mirror of
https://github.com/stablyai/orca.git
synced 2026-11-02 18:17:36 +00:00
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>
75 lines
2.3 KiB
TypeScript
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]
|
|
}
|
|
}
|