Skip to content

Commit

Permalink
don't print pr comment if there's no detectable issue number
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianGonz97 committed Aug 30, 2024
1 parent f492a7d commit 6570451
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 43 deletions.
49 changes: 28 additions & 21 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24322,13 +24322,15 @@ async function main() {
if (branch === void 0) {
throw new Error("Unable to determine branch name");
}
await createPRComment({
status: "building",
previewUrl: "",
sha,
issueNumber,
runId
});
if (issueNumber !== void 0) {
await createPRComment({
status: "building",
previewUrl: "",
sha,
issueNumber,
runId
});
}
const project = await getPagesProject();
const productionEnvironment = branch === project.production_branch && !isPR && !isWorkflowRun;
let githubDeployment;
Expand Down Expand Up @@ -24360,13 +24362,15 @@ async function main() {
if (!productionEnvironment && deployment.aliases && deployment.aliases.length > 0) {
alias = deployment.aliases[0];
}
await createPRComment({
status: "success",
previewUrl: `[Visit Preview](${alias})`,
sha,
issueNumber,
runId
});
if (issueNumber !== void 0) {
await createPRComment({
status: "success",
previewUrl: `[Visit Preview](${alias})`,
sha,
issueNumber,
runId
});
}
(0, import_core3.setOutput)("id", deployment.id);
(0, import_core3.setOutput)("url", deployment.url);
(0, import_core3.setOutput)("environment", deployment.environment);
Expand All @@ -24378,13 +24382,16 @@ async function main() {
await main();
} catch (error) {
(0, import_core3.setFailed)(error.message);
await createPRComment({
status: "fail",
previewUrl: "",
sha: pr?.head.sha ?? import_github5.context.sha,
issueNumber: pr?.number ?? import_github5.context.issue.number,
runId: import_github5.context.payload.workflow_run.id ?? import_github5.context.runId
});
const issueNumber = pr?.number ?? import_github5.context.issue.number;
if (issueNumber !== void 0) {
await createPRComment({
status: "fail",
previewUrl: "",
sha: pr?.head.sha ?? import_github5.context.sha,
issueNumber: pr?.number ?? import_github5.context.issue.number,
runId: import_github5.context.payload.workflow_run.id ?? import_github5.context.runId
});
}
}
})();
/*! Bundled license information:
Expand Down
51 changes: 29 additions & 22 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async function main() {
pullRequests.find((p) => p.title === workflowRun?.display_title) ??
(context.payload.pull_request as PullRequest);

const issueNumber = pr?.number ?? context.issue.number;
const issueNumber = pr?.number ?? (context.issue.number as number | undefined);
const runId = workflowRun?.id ?? context.runId;
const sha = workflowRun?.head_sha ?? pr?.head.sha ?? context.sha;

Expand All @@ -57,13 +57,15 @@ async function main() {
throw new Error('Unable to determine branch name');
}

await createPRComment({
status: 'building',
previewUrl: '',
sha,
issueNumber,
runId,
});
if (issueNumber !== undefined) {
await createPRComment({
status: 'building',
previewUrl: '',
sha,
issueNumber,
runId,
});
}

const project = await getPagesProject();

Expand Down Expand Up @@ -105,13 +107,15 @@ async function main() {
alias = deployment.aliases[0]!; // we can assert that idx 0 exists
}

await createPRComment({
status: 'success',
previewUrl: `[Visit Preview](${alias})`,
sha,
issueNumber,
runId,
});
if (issueNumber !== undefined) {
await createPRComment({
status: 'success',
previewUrl: `[Visit Preview](${alias})`,
sha,
issueNumber,
runId,
});
}

setOutput('id', deployment.id);
setOutput('url', deployment.url);
Expand All @@ -128,12 +132,15 @@ async function main() {
// @ts-expect-error always print the message
setFailed(error.message);

await createPRComment({
status: 'fail',
previewUrl: '',
sha: pr?.head.sha ?? context.sha,
issueNumber: pr?.number ?? context.issue.number,
runId: context.payload.workflow_run.id ?? context.runId,
});
const issueNumber = pr?.number ?? (context.issue.number as number | undefined);
if (issueNumber !== undefined) {
await createPRComment({
status: 'fail',
previewUrl: '',
sha: pr?.head.sha ?? context.sha,
issueNumber: pr?.number ?? context.issue.number,
runId: context.payload.workflow_run.id ?? context.runId,
});
}
}
})();

0 comments on commit 6570451

Please sign in to comment.