MCPcopy Create free account
hub / github.com/angular/dev-infra / getCombinedChecksAndStatusesForRef

Function getCombinedChecksAndStatusesForRef

ng-dev/utils/git/github-macros.ts:56–107  ·  view source on GitHub ↗

* Retrieve a combined listing of the results for a refs statuses and checks.

(
  github: AuthenticatedGithubClient,
  params: RestEndpointMethodTypes['checks']['listForRef']['parameters'] &
    RestEndpointMethodTypes['repos']['getCombinedStatusForRef']['parameters'],
)

Source from the content-addressed store, hash-verified

54/** Shared base object for a derived Check or Status result. */
55interface CheckOrStatusResult {
56 type: string;
57 name: string;
58 result: string;
59 url: string;
60}
61
62/** A derived Check result */
63interface CheckResult extends CheckOrStatusResult {
64 type: 'check';
65 check: RestEndpointMethodTypes['checks']['listForRef']['response']['data']['check_runs'][number];
66}
67
68/** A derived Status result */
69interface StatusResult extends CheckOrStatusResult {
70 type: 'status';
71 description: string;
72 status: RestEndpointMethodTypes['repos']['getCombinedStatusForRef']['response']['data']['statuses'][number];
73}
74
75/** The overall results of a combined Checks and Statuses check. */
76export interface CombinedChecksAndStatusesResult {
77 result: 'pending' | 'passing' | 'failing' | null;
78 results: (CheckResult | StatusResult)[];
79}
80
81/**
82 * Retrieve a combined listing of the results for a refs statuses and checks.
83 */
84async function getCombinedChecksAndStatusesForRef(
85 github: AuthenticatedGithubClient,
86 params: RestEndpointMethodTypes['checks']['listForRef']['parameters'] &
87 RestEndpointMethodTypes['repos']['getCombinedStatusForRef']['parameters'],
88): Promise<CombinedChecksAndStatusesResult> {
89 const {data: checkResults} = await github.checks.listForRef(params);
90 const {data: statusResults} = await github.repos.getCombinedStatusForRef(params);
91
92 const results = [
93 ...checkResults.check_runs.map((result): CheckResult => ({
94 type: 'check',
95 name: result.name,
96 result: result.status === 'completed' ? result.conclusion! : result.status,
97 url: result.details_url ?? '',
98 check: result,
99 })),
100 ...statusResults.statuses.map((result): StatusResult => ({
101 type: 'status',
102 name: result.context,
103 result: result.state,
104 description: result.description ?? '',
105 url: result.target_url ?? '',
106 status: result,
107 })),
108 ];
109
110 // TODO: Refactor away from a reducer.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected