Skip to content

Commit

Permalink
Merge pull request #41809 from Expensify/marcaaron-fixgetValidMergedPRs
Browse files Browse the repository at this point in the history
Handle 404 errors when we have a bad PR referenced in the PR list
  • Loading branch information
roryabraham authored Jun 21, 2024
2 parents 6294e7d + cc2c898 commit b021195
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
28 changes: 19 additions & 9 deletions .github/actions/javascript/markPullRequestsAsDeployed/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')]) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* 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';
Expand Down Expand Up @@ -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(`Unable to comment on PR #${prNumber}. GitHub responded with 404.`);
} else {
throw error;
}
}
}
}

Expand Down

0 comments on commit b021195

Please sign in to comment.