Skip to content

Commit 8cd78c4

Browse files
committed
fix(ng-dev): filter out duplicate CheckRun results
When requesting the CheckRun and StatusContext objects for a pull request commit, it is possible that Github will return multiple CheckRuns with the same context name but different results as they are additive rather than replacing the value. We now sort this original list by timestamp and then filter out the duplicates to only consider the final status result.
1 parent c855fff commit 8cd78c4

File tree

2 files changed

+44
-26
lines changed

2 files changed

+44
-26
lines changed

.github/local-actions/branch-manager/main.js

Lines changed: 16 additions & 9 deletions
Large diffs are not rendered by default.

ng-dev/pr/common/fetch-pull-request.ts

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,13 @@ export const PR_SCHEMA = {
6565
status: graphqlTypes.custom<CheckStatusState>(),
6666
conclusion: graphqlTypes.custom<CheckConclusionState | null>(),
6767
name: graphqlTypes.string,
68+
completedAt: graphqlTypes.string,
6869
},
6970
StatusContext: {
7071
__typename: graphqlTypes.constant('StatusContext'),
7172
state: graphqlTypes.custom<StatusState>(),
7273
context: graphqlTypes.string,
74+
createdAt: graphqlTypes.string,
7375
},
7476
}),
7577
],
@@ -232,26 +234,35 @@ export function getStatusesForPullRequest(
232234
};
233235
}
234236

235-
const statuses = statusCheckRollup.contexts.nodes.map((context) => {
236-
switch (context.__typename) {
237-
case 'CheckRun':
238-
return {
239-
type: 'check' as const,
240-
name: context.name,
241-
status: normalizeGithubCheckState(context.conclusion, context.status),
242-
};
243-
case 'StatusContext':
244-
return {
245-
type: 'status' as const,
246-
name: context.context,
247-
status: normalizeGithubStatusState(context.state),
248-
};
249-
}
250-
});
237+
/** A map of all of the statuses indexed by their names. */
238+
const statusMap = new Map<string, PullRequestStatusInfo['statuses'][number]>();
239+
240+
statusCheckRollup.contexts.nodes
241+
.sort((a, b) => {
242+
const aTimestamp = Date.parse(a.completedAt || a.createdAt || '0');
243+
const bTimestamp = Date.parse(b.completedAt || b.createdAt || '0');
244+
return aTimestamp - bTimestamp;
245+
})
246+
.forEach((context) => {
247+
switch (context.__typename) {
248+
case 'CheckRun':
249+
statusMap.set(context.name, {
250+
type: 'check' as const,
251+
name: context.name,
252+
status: normalizeGithubCheckState(context.conclusion, context.status),
253+
});
254+
case 'StatusContext':
255+
statusMap.set(context.context!, {
256+
type: 'status' as const,
257+
name: context.context!,
258+
status: normalizeGithubStatusState(context.state!),
259+
});
260+
}
261+
});
251262

252263
return {
253264
combinedStatus: normalizeGithubStatusState(statusCheckRollup.state),
254-
statuses,
265+
statuses: Array.from(statusMap.values()),
255266
};
256267
}
257268

0 commit comments

Comments
 (0)