Skip to content

Commit 8248bc1

Browse files
authoredApr 4, 2021
Protects against null head_repository (#14)
1 parent a81b3c4 commit 8248bc1

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed
 

‎dist/index.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -1505,7 +1505,9 @@ function getCommonGroupIdFromTriggeringRunInfo(triggeringRunInfo, sourceWorkflow
15051505
* @returns the unique string id for the group
15061506
*/
15071507
function getCommonGroupIdFromRunItem(runItem) {
1508-
return `:${retrieveWorkflowIdFromUrl(runItem.workflow_url)}:${runItem.head_repository.full_name}:${runItem.head_branch}:${runItem.event}`;
1508+
return `:${retrieveWorkflowIdFromUrl(runItem.workflow_url)}:${runItem.head_repository !== null
1509+
? runItem.head_repository.full_name
1510+
: 'UNKNOWN_REPO'}:${runItem.head_branch}:${runItem.event}`;
15091511
}
15101512
/**
15111513
* Creates query parameters selecting all runs that share the same source group as we have. This can
@@ -1755,6 +1757,10 @@ function getWorkflowRuns(repositoryInfo, statusValues, cancelMode, createListRun
17551757
* @return true if we determine that the run Id should be cancelled
17561758
*/
17571759
function checkCandidateForCancellingDuplicate(runItem, cancelFutureDuplicates, triggeringRunInfo, sourceWorkflowId, mapOfWorkflowRunCandidates) {
1760+
if (runItem.head_repository === null) {
1761+
core.warning(`\nThe run number: ${runItem.run_number} is weird. It's 'head_repository' is null.\n`);
1762+
return;
1763+
}
17581764
const runHeadRepo = runItem.head_repository.full_name;
17591765
if (triggeringRunInfo.headRepo !== undefined &&
17601766
runHeadRepo !== triggeringRunInfo.headRepo) {
@@ -2010,6 +2016,10 @@ function findPullRequest(repositoryInfo, headRepo, headBranch, headSha) {
20102016
*/
20112017
function findPullRequestForRunItem(repositoryInfo, runItem) {
20122018
return __awaiter(this, void 0, void 0, function* () {
2019+
if (runItem.head_repository === null) {
2020+
core.warning(`\nThe run number: ${runItem.run_number} is weird. It's 'head_repository' is null.\n`);
2021+
return undefined;
2022+
}
20132023
const pullRequest = yield findPullRequest(repositoryInfo, runItem.head_repository.owner.login, runItem.head_branch, runItem.head_sha);
20142024
if (pullRequest) {
20152025
return pullRequest.number;
@@ -2205,6 +2215,19 @@ function getTriggeringRunInfo(repositoryInfo, runId) {
22052215
run_id: runId
22062216
});
22072217
const sourceRun = reply.data;
2218+
if (sourceRun.head_repository === null) {
2219+
core.warning(`\nThe run number: ${sourceRun.run_number} is weird. It's 'head_repository' is null.\n`);
2220+
return {
2221+
workflowId: retrieveWorkflowIdFromUrl(reply.data.workflow_url),
2222+
runId,
2223+
headRepo: 'UNKNOWN_REPO',
2224+
headBranch: reply.data.head_branch,
2225+
headSha: reply.data.head_sha,
2226+
mergeCommitSha: null,
2227+
pullRequest: null,
2228+
eventName: reply.data.event
2229+
};
2230+
}
22082231
core.info(`Source workflow: Head repo: ${sourceRun.head_repository.full_name}, ` +
22092232
`Head branch: ${sourceRun.head_branch} ` +
22102233
`Event: ${sourceRun.event}, Head sha: ${sourceRun.head_sha}, url: ${sourceRun.url}`);

‎src/main.ts

+30-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ function getCommonGroupIdFromRunItem(
7676
runItem: rest.ActionsListWorkflowRunsResponseWorkflowRunsItem
7777
): string {
7878
return `:${retrieveWorkflowIdFromUrl(runItem.workflow_url)}:${
79-
runItem.head_repository.full_name
79+
runItem.head_repository !== null
80+
? runItem.head_repository.full_name
81+
: 'UNKNOWN_REPO'
8082
}:${runItem.head_branch}:${runItem.event}`
8183
}
8284

@@ -373,6 +375,12 @@ function checkCandidateForCancellingDuplicate(
373375
rest.ActionsListWorkflowRunsResponseWorkflowRunsItem[]
374376
>
375377
): void {
378+
if (runItem.head_repository === null) {
379+
core.warning(
380+
`\nThe run number: ${runItem.run_number} is weird. It's 'head_repository' is null.\n`
381+
)
382+
return
383+
}
376384
const runHeadRepo = runItem.head_repository.full_name
377385
if (
378386
triggeringRunInfo.headRepo !== undefined &&
@@ -793,6 +801,12 @@ async function findPullRequestForRunItem(
793801
repositoryInfo: RepositoryInfo,
794802
runItem: rest.ActionsListWorkflowRunsResponseWorkflowRunsItem
795803
): Promise<number | undefined> {
804+
if (runItem.head_repository === null) {
805+
core.warning(
806+
`\nThe run number: ${runItem.run_number} is weird. It's 'head_repository' is null.\n`
807+
)
808+
return undefined
809+
}
796810
const pullRequest = await findPullRequest(
797811
repositoryInfo,
798812
runItem.head_repository.owner.login,
@@ -1118,6 +1132,21 @@ async function getTriggeringRunInfo(
11181132
run_id: runId
11191133
})
11201134
const sourceRun = reply.data
1135+
if (sourceRun.head_repository === null) {
1136+
core.warning(
1137+
`\nThe run number: ${sourceRun.run_number} is weird. It's 'head_repository' is null.\n`
1138+
)
1139+
return {
1140+
workflowId: retrieveWorkflowIdFromUrl(reply.data.workflow_url),
1141+
runId,
1142+
headRepo: 'UNKNOWN_REPO',
1143+
headBranch: reply.data.head_branch,
1144+
headSha: reply.data.head_sha,
1145+
mergeCommitSha: null,
1146+
pullRequest: null,
1147+
eventName: reply.data.event
1148+
}
1149+
}
11211150
core.info(
11221151
`Source workflow: Head repo: ${sourceRun.head_repository.full_name}, ` +
11231152
`Head branch: ${sourceRun.head_branch} ` +

0 commit comments

Comments
 (0)
Please sign in to comment.