Files
archived-orca/src/shared/github/project-content-field.ts
T
Brennan Benson 6acdb0535c fix(github-project): use content values for built-in grouping and sorting (#38818)
* fix(github-project): derive built-in field display and ordering from content

* fix(i18n): register linked PR summary overflow fallback

* fix: satisfy project projection static checks

* test(github-project): cover normalized phone metadata and update field contracts

* fix(github-project): narrow optional grouping values explicitly

* test(github-project): place fixture safety rationale at assertion start

* test(github-project): isolate Node and native regression boundaries
2026-11-05 21:09:14 -08:00

69 lines
2.4 KiB
TypeScript

import type { GitHubProjectRow } from './project-types'
type ProjectContent = Pick<
GitHubProjectRow['content'],
'repository' | 'linkedPullRequests' | 'subIssuesProgress'
> & { parentIssue?: GitHubProjectRow['content']['parentIssue'] }
export type ProjectContentField =
| { kind: 'parent'; parent: NonNullable<ProjectContent['parentIssue']> }
| { kind: 'repository'; repository: string }
| { kind: 'progress'; progress: NonNullable<ProjectContent['subIssuesProgress']> }
| { kind: 'linked'; linked: NonNullable<ProjectContent['linkedPullRequests']> }
// Undefined leaves unsupported fields on the field-value path; null is authoritative emptiness.
export function projectContentField(
content: ProjectContent,
dataType: string
): ProjectContentField | null | undefined {
switch (dataType) {
case 'PARENT_ISSUE':
return content.parentIssue ? { kind: 'parent', parent: content.parentIssue } : null
case 'REPOSITORY':
return content.repository ? { kind: 'repository', repository: content.repository } : null
case 'SUB_ISSUES_PROGRESS':
return content.subIssuesProgress && content.subIssuesProgress.total !== 0
? { kind: 'progress', progress: content.subIssuesProgress }
: null
case 'LINKED_PULL_REQUESTS':
return content.linkedPullRequests &&
(content.linkedPullRequests.pullRequests.length > 0 ||
content.linkedPullRequests.totalCount > 0)
? { kind: 'linked', linked: content.linkedPullRequests }
: null
default:
return undefined
}
}
export function projectContentFieldLabel(value: ProjectContentField): string {
switch (value.kind) {
case 'parent':
return `#${value.parent.number}`
case 'repository':
return value.repository
case 'progress':
return `${value.progress.completed}/${value.progress.total} (${value.progress.percentCompleted}%)`
case 'linked':
return value.linked.pullRequests.map((pr) => `#${pr.number}`).join(', ')
}
}
export function projectContentFieldSortValue(
value: ProjectContentField | null
): string | number | null {
if (!value) {
return null
}
switch (value.kind) {
case 'parent':
return value.parent.number
case 'repository':
return value.repository
case 'progress':
return value.progress.percentCompleted
case 'linked':
return value.linked.pullRequests[0]?.number ?? null
}
}