Skip to content

Commit 1ab7328

Browse files
committed
fix(github-actions): handle when no target label is provided for mergeability check (#2715)
Properly return an error meessage when no target label is present. PR Close #2715
1 parent f172f3f commit 1ab7328

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

.github/local-actions/branch-manager/lib/main.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
} from '../../../../github-actions/utils.js';
1212
import {MergeConflictsFatalError} from '../../../../ng-dev/pr/merge/failures.js';
1313
import {createPullRequestValidationConfig} from '../../../../ng-dev/pr/common/validation/validation-config.js';
14+
import {InvalidTargetLabelError} from '../../../../ng-dev/pr/common/targeting/target-label.js';
1415

1516
interface CommmitStatus {
1617
state: 'pending' | 'error' | 'failure' | 'success';
@@ -155,19 +156,22 @@ async function main() {
155156

156157
await setMergeabilityStatusOnPullRequest(statusInfo);
157158
} catch (e: Error | unknown) {
159+
let state: CommmitStatus['state'] = 'error';
158160
let description: string;
159161
const {runId, repo, serverUrl} = actionContext;
160162
const targetUrl = `${serverUrl}/${repo.owner}/${repo.repo}/actions/runs/${runId}`;
161-
if (e instanceof Error) {
163+
164+
if (e instanceof InvalidTargetLabelError) {
165+
// For this action, an invalid target label represents that we aren't ready to check the
166+
// mergeability yet, rather than an actual failure.
167+
state = 'pending';
168+
description = e.failureMessage;
169+
} else if (e instanceof Error) {
162170
description = e.message;
163171
} else {
164172
description = 'Internal Error, see link for action log';
165173
}
166-
await setMergeabilityStatusOnPullRequest({
167-
state: 'error',
168-
description,
169-
targetUrl,
170-
});
174+
await setMergeabilityStatusOnPullRequest({state, description, targetUrl});
171175
// Re-throw the error so that the action run is set as failing.
172176
throw e;
173177
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69642,19 +69642,19 @@ async function main() {
6964269642
})();
6964369643
await setMergeabilityStatusOnPullRequest(statusInfo);
6964469644
} catch (e) {
69645+
let state = "error";
6964569646
let description;
6964669647
const { runId, repo: repo2, serverUrl } = import_github5.context;
6964769648
const targetUrl = `${serverUrl}/${repo2.owner}/${repo2.repo}/actions/runs/${runId}`;
69648-
if (e instanceof Error) {
69649+
if (e instanceof InvalidTargetLabelError) {
69650+
state = "pending";
69651+
description = e.failureMessage;
69652+
} else if (e instanceof Error) {
6964969653
description = e.message;
6965069654
} else {
6965169655
description = "Internal Error, see link for action log";
6965269656
}
69653-
await setMergeabilityStatusOnPullRequest({
69654-
state: "error",
69655-
description,
69656-
targetUrl
69657-
});
69657+
await setMergeabilityStatusOnPullRequest({ state, description, targetUrl });
6965869658
throw e;
6965969659
}
6966069660
}

github-actions/branch-manager/lib/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ async function createWorkflowForPullRequest(inputs: WorkflowInputs) {
111111
repo: inputs.repo,
112112
owner: inputs.owner,
113113
state: 'pending',
114-
description: 'Running mergibility check',
114+
description: 'Mergibility check requested',
115115
sha: inputs.sha,
116116
context: 'mergeability',
117117
});

github-actions/branch-manager/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48159,7 +48159,7 @@ async function createWorkflowForPullRequest(inputs) {
4815948159
repo: inputs.repo,
4816048160
owner: inputs.owner,
4816148161
state: "pending",
48162-
description: "Running mergibility check",
48162+
description: "Mergibility check requested",
4816348163
sha: inputs.sha,
4816448164
context: "mergeability"
4816548165
});

0 commit comments

Comments
 (0)