import type { SourceControlProviderInfo } from "@t3tools/contracts"; export interface ChangeRequestPresentation { readonly icon: "github" | "gitlab" | "azure-devops" | "change-request"; readonly providerName: string; readonly shortName: string; readonly longName: string; readonly pluralLongName: string; readonly providerLongName: string; readonly checkoutCommandExample: string; readonly urlExample: string;} const GITHUB_CHANGE_REQUEST_PRESENTATION: ChangeRequestPresentation = { icon: "github", providerName: "GitHub", shortName: "PR", longName: "pull request", pluralLongName: "pull requests", providerLongName: "GitHub pull request", checkoutCommandExample: "gh pr checkout 123", urlExample: "https://github.com/owner/repo/pull/42",}; const GITLAB_CHANGE_REQUEST_PRESENTATION: ChangeRequestPresentation = { icon: "gitlab", providerName: "GitLab", shortName: "MR", longName: "merge request", pluralLongName: "merge requests", providerLongName: "GitLab merge request", checkoutCommandExample: "glab mr checkout 123", urlExample: "https://gitlab.com/group/project/-/merge_requests/42",}; const AZURE_DEVOPS_CHANGE_REQUEST_PRESENTATION: ChangeRequestPresentation = { icon: "azure-devops", providerName: "Azure DevOps", shortName: "PR", longName: "pull request", pluralLongName: "pull requests", providerLongName: "Azure DevOps pull request", checkoutCommandExample: "az repos pr checkout --id 123", urlExample: "https://dev.azure.com/org/project/_git/repo/pullrequest/42",}; const GENERIC_CHANGE_REQUEST_PRESENTATION: ChangeRequestPresentation = { icon: "change-request", providerName: "source control", shortName: "change request", longName: "change request", pluralLongName: "change requests", providerLongName: "change request", checkoutCommandExample: "123", urlExample: "#42",}; export function resolveChangeRequestPresentation( provider: SourceControlProviderInfo | null | undefined,): ChangeRequestPresentation { switch (provider?.kind) { case "github": case undefined: return GITHUB_CHANGE_REQUEST_PRESENTATION; case "gitlab": return GITLAB_CHANGE_REQUEST_PRESENTATION; case "azure-devops": return AZURE_DEVOPS_CHANGE_REQUEST_PRESENTATION; case "unknown": return GENERIC_CHANGE_REQUEST_PRESENTATION; }} export function formatChangeRequestAction( verb: "View" | "Create", presentation: ChangeRequestPresentation,): string { return `${verb} ${presentation.shortName}`;} export function formatCreateChangeRequestPhrase(presentation: ChangeRequestPresentation): string { return `create ${presentation.shortName}`;}
import type { SourceControlProviderInfo } from "@t3tools/contracts";
export interface ChangeRequestPresentation {
readonly icon: "github" | "gitlab" | "azure-devops" | "change-request";
readonly providerName: string;
readonly shortName: string;
readonly longName: string;
readonly pluralLongName: string;
readonly providerLongName: string;
readonly checkoutCommandExample: string;
readonly urlExample: string;
}
const GITHUB_CHANGE_REQUEST_PRESENTATION: ChangeRequestPresentation = {
icon: "github",
providerName: "GitHub",
shortName: "PR",
longName: "pull request",
pluralLongName: "pull requests",
providerLongName: "GitHub pull request",
checkoutCommandExample: "gh pr checkout 123",
urlExample: "https://github.com/owner/repo/pull/42",
};
const GITLAB_CHANGE_REQUEST_PRESENTATION: ChangeRequestPresentation = {
icon: "gitlab",
providerName: "GitLab",
shortName: "MR",
longName: "merge request",
pluralLongName: "merge requests",
providerLongName: "GitLab merge request",
checkoutCommandExample: "glab mr checkout 123",
urlExample: "https://gitlab.com/group/project/-/merge_requests/42",
};
const AZURE_DEVOPS_CHANGE_REQUEST_PRESENTATION: ChangeRequestPresentation = {
icon: "azure-devops",
providerName: "Azure DevOps",
shortName: "PR",
longName: "pull request",
pluralLongName: "pull requests",
providerLongName: "Azure DevOps pull request",
checkoutCommandExample: "az repos pr checkout --id 123",
urlExample: "https://dev.azure.com/org/project/_git/repo/pullrequest/42",
};
const GENERIC_CHANGE_REQUEST_PRESENTATION: ChangeRequestPresentation = {
icon: "change-request",
providerName: "source control",
shortName: "change request",
longName: "change request",
pluralLongName: "change requests",
providerLongName: "change request",
checkoutCommandExample: "123",
urlExample: "#42",
};
export function resolveChangeRequestPresentation(
provider: SourceControlProviderInfo | null | undefined,
): ChangeRequestPresentation {
switch (provider?.kind) {
case "github":
case undefined:
return GITHUB_CHANGE_REQUEST_PRESENTATION;
case "gitlab":
return GITLAB_CHANGE_REQUEST_PRESENTATION;
case "azure-devops":
return AZURE_DEVOPS_CHANGE_REQUEST_PRESENTATION;
case "unknown":
return GENERIC_CHANGE_REQUEST_PRESENTATION;
}
}
export function formatChangeRequestAction(
verb: "View" | "Create",
presentation: ChangeRequestPresentation,
): string {
return `${verb} ${presentation.shortName}`;
}
export function formatCreateChangeRequestPhrase(presentation: ChangeRequestPresentation): string {
return `create ${presentation.shortName}`;
}