Files
orca/src/shared/github/pull-request-merge-methods.ts
T
YEONGUK LEEandNeil a3ba93c87b fix(i18n): localize PR merge/close confirmations and merge method labels (#28568)
PR close/reopen/merge confirmation titles were built from a fragment
template ("{{value0}} PR #{{value1}}?"), so locales could not reorder the
verb, and merge method labels came from English-only shared constants.

Add whole-sentence title keys per action and merge method plus translated
merge method labels in a renderer copy module, and route every PR surface
(item dialog, PR page, Tasks MergeCell, right-sidebar HostedReviewActions)
through it. Drop the English labels from the shared merge-method
presentation and remove the dead fragment keys from all locales.

Co-authored-by: Neil <4138956+nwparker@users.noreply.github.com>
2026-10-26 09:52:05 -07:00

75 lines
2.3 KiB
TypeScript

import type { GitHubPRMergeMethod, GitHubPRMergeMethodSettings } from './pull-request-types'
export const GITHUB_PR_MERGE_METHODS = ['squash', 'merge', 'rebase'] as const
export type GitHubPRMergeMethodPresentation = {
defaultMethod: GitHubPRMergeMethod
methods: GitHubPRMergeMethod[]
}
function allMethodsAllowed(): Record<GitHubPRMergeMethod, boolean> {
return {
squash: true,
merge: true,
rebase: true
}
}
export function mapGitHubDefaultMergeMethod(value: unknown): GitHubPRMergeMethod | null {
switch (typeof value === 'string' ? value.toUpperCase() : '') {
case 'MERGE':
return 'merge'
case 'SQUASH':
return 'squash'
case 'REBASE':
return 'rebase'
default:
return null
}
}
export function normalizeGitHubPRMergeMethodSettings(args: {
defaultMethod: unknown
mergeCommitAllowed: unknown
rebaseMergeAllowed: unknown
squashMergeAllowed: unknown
}): GitHubPRMergeMethodSettings | undefined {
const allowedMethods = {
squash: args.squashMergeAllowed === true,
merge: args.mergeCommitAllowed === true,
rebase: args.rebaseMergeAllowed === true
}
const defaultMethod = mapGitHubDefaultMergeMethod(args.defaultMethod)
const firstAllowedMethod = GITHUB_PR_MERGE_METHODS.find((method) => allowedMethods[method])
const resolvedDefault =
defaultMethod && allowedMethods[defaultMethod]
? defaultMethod
: (firstAllowedMethod ?? defaultMethod)
if (!resolvedDefault) {
return undefined
}
return {
defaultMethod: resolvedDefault,
allowedMethods
}
}
export function resolveGitHubPRMergeMethods(
settings?: GitHubPRMergeMethodSettings | null
): GitHubPRMergeMethodPresentation {
const allowedMethods = settings?.allowedMethods ?? allMethodsAllowed()
const firstAllowedMethod = GITHUB_PR_MERGE_METHODS.find((method) => allowedMethods[method])
const defaultMethod =
settings?.defaultMethod && allowedMethods[settings.defaultMethod]
? settings.defaultMethod
: (firstAllowedMethod ?? 'squash')
const orderedMethods = [
defaultMethod,
...GITHUB_PR_MERGE_METHODS.filter((method) => method !== defaultMethod)
].filter((method) => allowedMethods[method])
return {
defaultMethod,
methods: orderedMethods.length > 0 ? orderedMethods : [...GITHUB_PR_MERGE_METHODS]
}
}