From aa82c7c42002ece84d5cde5b79f613e3fc70bf00 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Tue, 7 May 2024 09:52:52 -1000 Subject: [PATCH 1/5] Handle 404 errors when we have a bad PR --- .../markPullRequestsAsDeployed.ts | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/.github/actions/javascript/markPullRequestsAsDeployed/markPullRequestsAsDeployed.ts b/.github/actions/javascript/markPullRequestsAsDeployed/markPullRequestsAsDeployed.ts index a312bae7e7df..e2fb46dba250 100644 --- a/.github/actions/javascript/markPullRequestsAsDeployed/markPullRequestsAsDeployed.ts +++ b/.github/actions/javascript/markPullRequestsAsDeployed/markPullRequestsAsDeployed.ts @@ -4,6 +4,7 @@ import {context} from '@actions/github'; import * as ActionUtils from '@github/libs/ActionUtils'; import CONST from '@github/libs/CONST'; import GithubUtils from '@github/libs/GithubUtils'; +import {RequestError} from '@octokit/types'; type PlatformResult = 'success' | 'cancelled' | 'skipped' | 'failure'; @@ -113,16 +114,24 @@ async function run() { * 1. For regular staging deploys, the person who merged the PR. * 2. For CPs, the person who committed the cherry-picked commit (not necessarily the author of the commit). */ - const {data: pr} = await GithubUtils.octokit.pulls.get({ - owner: CONST.GITHUB_OWNER, - repo: CONST.APP_REPO, - pull_number: prNumber, - }); - const deployer = isCP ? commit.committer.name : pr.merged_by?.login; - - const title = pr.title; - const deployMessage = deployer ? getDeployMessage(deployer, isCP ? 'Cherry-picked' : 'Deployed', title) : ''; - await commentPR(prNumber, deployMessage); + try { + const {data: pr} = await GithubUtils.octokit.pulls.get({ + owner: CONST.GITHUB_OWNER, + repo: CONST.APP_REPO, + pull_number: prNumber, + }); + const deployer = isCP ? commit.committer.name : pr.merged_by?.login; + + const title = pr.title; + const deployMessage = deployer ? getDeployMessage(deployer, isCP ? 'Cherry-picked' : 'Deployed', title) : ''; + await commentPR(prNumber, deployMessage); + } catch (error) { + if ((error as RequestError).status === 404) { + console.log(`404 when accessing PR #${prNumber}. Ignoring.`); + } else { + throw error; + } + } } } From a5fce64340e8ce7eed69afa81bd153bfd8843627 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Tue, 7 May 2024 09:56:51 -1000 Subject: [PATCH 2/5] Improve log --- .../markPullRequestsAsDeployed/markPullRequestsAsDeployed.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/javascript/markPullRequestsAsDeployed/markPullRequestsAsDeployed.ts b/.github/actions/javascript/markPullRequestsAsDeployed/markPullRequestsAsDeployed.ts index e2fb46dba250..b43c1bf8a9a5 100644 --- a/.github/actions/javascript/markPullRequestsAsDeployed/markPullRequestsAsDeployed.ts +++ b/.github/actions/javascript/markPullRequestsAsDeployed/markPullRequestsAsDeployed.ts @@ -127,7 +127,7 @@ async function run() { await commentPR(prNumber, deployMessage); } catch (error) { if ((error as RequestError).status === 404) { - console.log(`404 when accessing PR #${prNumber}. Ignoring.`); + console.log(`Unable to comment on PR #${prNumber}. GitHub responded with 404.`); } else { throw error; } From c2d9fd54256cb3f60fce5e0c0aaea3a92f20b2f2 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Tue, 7 May 2024 13:41:09 -1000 Subject: [PATCH 3/5] Fix lint and build the actions --- .../markPullRequestsAsDeployed/index.js | 28 +++++++++++++------ .../markPullRequestsAsDeployed.ts | 2 +- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/.github/actions/javascript/markPullRequestsAsDeployed/index.js b/.github/actions/javascript/markPullRequestsAsDeployed/index.js index 804d3ea610f3..b3db51d62da6 100644 --- a/.github/actions/javascript/markPullRequestsAsDeployed/index.js +++ b/.github/actions/javascript/markPullRequestsAsDeployed/index.js @@ -11598,15 +11598,25 @@ async function run() { * 1. For regular staging deploys, the person who merged the PR. * 2. For CPs, the person who committed the cherry-picked commit (not necessarily the author of the commit). */ - const { data: pr } = await GithubUtils_1.default.octokit.pulls.get({ - owner: CONST_1.default.GITHUB_OWNER, - repo: CONST_1.default.APP_REPO, - pull_number: prNumber, - }); - const deployer = isCP ? commit.committer.name : pr.merged_by?.login; - const title = pr.title; - const deployMessage = deployer ? getDeployMessage(deployer, isCP ? 'Cherry-picked' : 'Deployed', title) : ''; - await commentPR(prNumber, deployMessage); + try { + const { data: pr } = await GithubUtils_1.default.octokit.pulls.get({ + owner: CONST_1.default.GITHUB_OWNER, + repo: CONST_1.default.APP_REPO, + pull_number: prNumber, + }); + const deployer = isCP ? commit.committer.name : pr.merged_by?.login; + const title = pr.title; + const deployMessage = deployer ? getDeployMessage(deployer, isCP ? 'Cherry-picked' : 'Deployed', title) : ''; + await commentPR(prNumber, deployMessage); + } + catch (error) { + if (error.status === 404) { + console.log(`Unable to comment on PR #${prNumber}. GitHub responded with 404.`); + } + else { + throw error; + } + } } } if (require.main === require.cache[eval('__filename')]) { diff --git a/.github/actions/javascript/markPullRequestsAsDeployed/markPullRequestsAsDeployed.ts b/.github/actions/javascript/markPullRequestsAsDeployed/markPullRequestsAsDeployed.ts index b43c1bf8a9a5..6ad801140af2 100644 --- a/.github/actions/javascript/markPullRequestsAsDeployed/markPullRequestsAsDeployed.ts +++ b/.github/actions/javascript/markPullRequestsAsDeployed/markPullRequestsAsDeployed.ts @@ -4,7 +4,7 @@ import {context} from '@actions/github'; import * as ActionUtils from '@github/libs/ActionUtils'; import CONST from '@github/libs/CONST'; import GithubUtils from '@github/libs/GithubUtils'; -import {RequestError} from '@octokit/types'; +import {type as RequestError} from '@octokit/types'; type PlatformResult = 'success' | 'cancelled' | 'skipped' | 'failure'; From 1adc82e6076ff09c7f58b132fa191e9603b19f32 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Tue, 7 May 2024 13:54:41 -1000 Subject: [PATCH 4/5] fix TS --- .../markPullRequestsAsDeployed/markPullRequestsAsDeployed.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/javascript/markPullRequestsAsDeployed/markPullRequestsAsDeployed.ts b/.github/actions/javascript/markPullRequestsAsDeployed/markPullRequestsAsDeployed.ts index 6ad801140af2..4f45d7563a9e 100644 --- a/.github/actions/javascript/markPullRequestsAsDeployed/markPullRequestsAsDeployed.ts +++ b/.github/actions/javascript/markPullRequestsAsDeployed/markPullRequestsAsDeployed.ts @@ -4,7 +4,7 @@ import {context} from '@actions/github'; import * as ActionUtils from '@github/libs/ActionUtils'; import CONST from '@github/libs/CONST'; import GithubUtils from '@github/libs/GithubUtils'; -import {type as RequestError} from '@octokit/types'; +import type {RequestError} from '@octokit/types'; type PlatformResult = 'success' | 'cancelled' | 'skipped' | 'failure'; From f556e7b5233d3685be7752418adc513a03568cce Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Tue, 7 May 2024 14:03:56 -1000 Subject: [PATCH 5/5] Prettier --- .../markPullRequestsAsDeployed/markPullRequestsAsDeployed.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/javascript/markPullRequestsAsDeployed/markPullRequestsAsDeployed.ts b/.github/actions/javascript/markPullRequestsAsDeployed/markPullRequestsAsDeployed.ts index 4f45d7563a9e..53018cbb035e 100644 --- a/.github/actions/javascript/markPullRequestsAsDeployed/markPullRequestsAsDeployed.ts +++ b/.github/actions/javascript/markPullRequestsAsDeployed/markPullRequestsAsDeployed.ts @@ -1,10 +1,10 @@ /* eslint-disable @typescript-eslint/naming-convention, import/no-import-module-exports */ import * as core from '@actions/core'; import {context} from '@actions/github'; +import type {RequestError} from '@octokit/types'; import * as ActionUtils from '@github/libs/ActionUtils'; import CONST from '@github/libs/CONST'; import GithubUtils from '@github/libs/GithubUtils'; -import type {RequestError} from '@octokit/types'; type PlatformResult = 'success' | 'cancelled' | 'skipped' | 'failure';