Skip to content

Commit

Permalink
pull request possible to be undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
wilson-ang committed Jul 27, 2023
1 parent e4f2df4 commit 3c4ea02
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions action.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,15 @@ async function action() {
PULL_REQUEST = github.context.payload.pull_request,
REGEX_STRING = `${TRIGGER_PHRASE}(?:\s*)https:\\/\\/app.asana.com\\/(\\d+)\\/(?<project>\\d+)\\/(?<task>\\d+)`,
REGEX = new RegExp(REGEX_STRING, "g");
console.log("pull_request", PULL_REQUEST);

const client = await buildClient(ASANA_PAT);
if (client === null) {
throw new Error("client authorization failed");
}

console.info("looking in body", PULL_REQUEST.body, "regex", REGEX_STRING);
console.info("looking in body", PULL_REQUEST?.body, "regex", REGEX_STRING);
let foundAsanaTasks = [];
while ((parseAsanaURL = REGEX.exec(PULL_REQUEST.body)) !== null) {
while ((parseAsanaURL = REGEX.exec(PULL_REQUEST?.body)) !== null) {
const taskId = parseAsanaURL.groups.task;
if (!taskId) {
core.error(
Expand All @@ -199,14 +198,14 @@ async function action() {
const statusState =
!linkRequired || foundAsanaTasks.length > 0 ? "success" : "error";
core.info(
`setting ${statusState} for ${github.context.payload.pull_request.head.sha}`
`setting ${statusState} for ${github.context.payload.pull_request?.head.sha}`
);
octokit.repos.createStatus({
...github.context.repo,
context: "asana-link-presence",
state: statusState,
description: "asana link not found",
sha: github.context.payload.pull_request.head.sha,
sha: github.context.payload.pull_request?.head.sha,
});
break;
}
Expand Down

0 comments on commit 3c4ea02

Please sign in to comment.