Skip to content

Commit

Permalink
Merge pull request #3815 from Expensify/Rory-FixStagingDeployCashPagi…
Browse files Browse the repository at this point in the history
…nation

Fix bugs in createOrUpdateStagingDeploy
  • Loading branch information
roryabraham authored Jul 7, 2021
2 parents 9a84fbe + 338788f commit f5c9b21
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 170 deletions.
17 changes: 2 additions & 15 deletions .github/actions/checkDeployBlockers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,26 +288,13 @@ class GithubUtils {
deployBlockers = [],
resolvedDeployBlockers = [],
) {
return this.octokit.paginate(this.octokit.pulls.list, {
owner: GITHUB_OWNER,
repo: EXPENSIFY_CASH_REPO,
state: 'all',
sort: 'created',
direction: 'desc',
per_page: 100,
}, ({data}, done) => {
// PRList is reverse-chronologically ordered
const oldestMergedPR = _.last(PRList);
if (_.find(data, pr => pr.html_url === oldestMergedPR)) {
done();
}
return data;
})
return this.fetchAllPullRequests(_.map(PRList, this.getPullRequestNumberFromURL))
.then((data) => {
const automatedPRs = _.pluck(
_.filter(data, GithubUtils.isAutomatedPullRequest),
'html_url',
);
console.log('Filtering out the following automated pull requests:', automatedPRs);
const sortedPRList = _.chain(PRList)
.difference(automatedPRs)
.unique()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const GitUtils = require('../../libs/GitUtils');

const run = function () {
const newVersion = core.getInput('NPM_VERSION');
console.log('New version found from action input:', newVersion);

let shouldCreateNewStagingDeployCash = false;
let currentStagingDeployCashIssueNumber = null;
Expand All @@ -26,8 +27,7 @@ const run = function () {
labels: GithubUtils.DEPLOY_BLOCKER_CASH_LABEL,
}),
])
.then((results) => {
const [stagingDeployResponse, deployBlockerResponse] = results;
.then(([stagingDeployResponse, deployBlockerResponse]) => {
if (!stagingDeployResponse || !stagingDeployResponse.data || _.isEmpty(stagingDeployResponse.data)) {
console.error('Failed fetching StagingDeployCash issues from Github!', stagingDeployResponse);
throw new Error('Failed fetching StagingDeployCash issues from Github');
Expand Down Expand Up @@ -58,15 +58,14 @@ const run = function () {

console.log('Found tag of previous StagingDeployCash:', previousStagingDeployCashData.tag);

// Find the list of PRs merged between the last StagingDeployCash and the new version
const mergedPRs = GitUtils.getPullRequestsMergedBetween(previousStagingDeployCashData.tag, newVersion);
console.log(
'The following PRs have been merged between the previous StagingDeployCash and new version:',
mergedPRs,
);

if (shouldCreateNewStagingDeployCash) {
// We're in the create flow, not update
// Find the list of PRs merged between the last StagingDeployCash and the new version
const mergedPRs = GitUtils.getPullRequestsMergedBetween(previousStagingDeployCashData.tag, newVersion);
console.log(
'The following PRs have been merged between the previous StagingDeployCash and new version:',
mergedPRs,
);

// TODO: if there are open DeployBlockers and we are opening a new checklist,
// then we should close / remove the DeployBlockerCash label from those
return GithubUtils.generateStagingDeployCashBody(
Expand All @@ -89,6 +88,13 @@ const run = function () {
// If we aren't sent a tag, then use the existing tag
const tag = newVersion || currentStagingDeployCashData.tag;

// Find the list of PRs merged between the last StagingDeployCash and the new version
const mergedPRs = GitUtils.getPullRequestsMergedBetween(previousStagingDeployCashData.tag, tag);
console.log(
'The following PRs have been merged between the previous StagingDeployCash and new version:',
mergedPRs,
);

// Generate the PR list, preserving the previous state of `isVerified` for existing PRs
const PRList = _.sortBy(
_.unique(
Expand Down
43 changes: 18 additions & 25 deletions .github/actions/createOrUpdateStagingDeploy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const GitUtils = __nccwpck_require__(669);

const run = function () {
const newVersion = core.getInput('NPM_VERSION');
console.log('New version found from action input:', newVersion);

let shouldCreateNewStagingDeployCash = false;
let currentStagingDeployCashIssueNumber = null;
Expand All @@ -36,8 +37,7 @@ const run = function () {
labels: GithubUtils.DEPLOY_BLOCKER_CASH_LABEL,
}),
])
.then((results) => {
const [stagingDeployResponse, deployBlockerResponse] = results;
.then(([stagingDeployResponse, deployBlockerResponse]) => {
if (!stagingDeployResponse || !stagingDeployResponse.data || _.isEmpty(stagingDeployResponse.data)) {
console.error('Failed fetching StagingDeployCash issues from Github!', stagingDeployResponse);
throw new Error('Failed fetching StagingDeployCash issues from Github');
Expand Down Expand Up @@ -68,15 +68,14 @@ const run = function () {

console.log('Found tag of previous StagingDeployCash:', previousStagingDeployCashData.tag);

// Find the list of PRs merged between the last StagingDeployCash and the new version
const mergedPRs = GitUtils.getPullRequestsMergedBetween(previousStagingDeployCashData.tag, newVersion);
console.log(
'The following PRs have been merged between the previous StagingDeployCash and new version:',
mergedPRs,
);

if (shouldCreateNewStagingDeployCash) {
// We're in the create flow, not update
// Find the list of PRs merged between the last StagingDeployCash and the new version
const mergedPRs = GitUtils.getPullRequestsMergedBetween(previousStagingDeployCashData.tag, newVersion);
console.log(
'The following PRs have been merged between the previous StagingDeployCash and new version:',
mergedPRs,
);

// TODO: if there are open DeployBlockers and we are opening a new checklist,
// then we should close / remove the DeployBlockerCash label from those
return GithubUtils.generateStagingDeployCashBody(
Expand All @@ -99,6 +98,13 @@ const run = function () {
// If we aren't sent a tag, then use the existing tag
const tag = newVersion || currentStagingDeployCashData.tag;

// Find the list of PRs merged between the last StagingDeployCash and the new version
const mergedPRs = GitUtils.getPullRequestsMergedBetween(previousStagingDeployCashData.tag, tag);
console.log(
'The following PRs have been merged between the previous StagingDeployCash and new version:',
mergedPRs,
);

// Generate the PR list, preserving the previous state of `isVerified` for existing PRs
const PRList = _.sortBy(
_.unique(
Expand Down Expand Up @@ -410,26 +416,13 @@ class GithubUtils {
deployBlockers = [],
resolvedDeployBlockers = [],
) {
return this.octokit.paginate(this.octokit.pulls.list, {
owner: GITHUB_OWNER,
repo: EXPENSIFY_CASH_REPO,
state: 'all',
sort: 'created',
direction: 'desc',
per_page: 100,
}, ({data}, done) => {
// PRList is reverse-chronologically ordered
const oldestMergedPR = _.last(PRList);
if (_.find(data, pr => pr.html_url === oldestMergedPR)) {
done();
}
return data;
})
return this.fetchAllPullRequests(_.map(PRList, this.getPullRequestNumberFromURL))
.then((data) => {
const automatedPRs = _.pluck(
_.filter(data, GithubUtils.isAutomatedPullRequest),
'html_url',
);
console.log('Filtering out the following automated pull requests:', automatedPRs);
const sortedPRList = _.chain(PRList)
.difference(automatedPRs)
.unique()
Expand Down
17 changes: 2 additions & 15 deletions .github/actions/getMergeCommitForPullRequest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,26 +316,13 @@ class GithubUtils {
deployBlockers = [],
resolvedDeployBlockers = [],
) {
return this.octokit.paginate(this.octokit.pulls.list, {
owner: GITHUB_OWNER,
repo: EXPENSIFY_CASH_REPO,
state: 'all',
sort: 'created',
direction: 'desc',
per_page: 100,
}, ({data}, done) => {
// PRList is reverse-chronologically ordered
const oldestMergedPR = _.last(PRList);
if (_.find(data, pr => pr.html_url === oldestMergedPR)) {
done();
}
return data;
})
return this.fetchAllPullRequests(_.map(PRList, this.getPullRequestNumberFromURL))
.then((data) => {
const automatedPRs = _.pluck(
_.filter(data, GithubUtils.isAutomatedPullRequest),
'html_url',
);
console.log('Filtering out the following automated pull requests:', automatedPRs);
const sortedPRList = _.chain(PRList)
.difference(automatedPRs)
.unique()
Expand Down
17 changes: 2 additions & 15 deletions .github/actions/getReleaseBody/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,26 +259,13 @@ class GithubUtils {
deployBlockers = [],
resolvedDeployBlockers = [],
) {
return this.octokit.paginate(this.octokit.pulls.list, {
owner: GITHUB_OWNER,
repo: EXPENSIFY_CASH_REPO,
state: 'all',
sort: 'created',
direction: 'desc',
per_page: 100,
}, ({data}, done) => {
// PRList is reverse-chronologically ordered
const oldestMergedPR = _.last(PRList);
if (_.find(data, pr => pr.html_url === oldestMergedPR)) {
done();
}
return data;
})
return this.fetchAllPullRequests(_.map(PRList, this.getPullRequestNumberFromURL))
.then((data) => {
const automatedPRs = _.pluck(
_.filter(data, GithubUtils.isAutomatedPullRequest),
'html_url',
);
console.log('Filtering out the following automated pull requests:', automatedPRs);
const sortedPRList = _.chain(PRList)
.difference(automatedPRs)
.unique()
Expand Down
17 changes: 2 additions & 15 deletions .github/actions/isPullRequestMergeable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,26 +262,13 @@ class GithubUtils {
deployBlockers = [],
resolvedDeployBlockers = [],
) {
return this.octokit.paginate(this.octokit.pulls.list, {
owner: GITHUB_OWNER,
repo: EXPENSIFY_CASH_REPO,
state: 'all',
sort: 'created',
direction: 'desc',
per_page: 100,
}, ({data}, done) => {
// PRList is reverse-chronologically ordered
const oldestMergedPR = _.last(PRList);
if (_.find(data, pr => pr.html_url === oldestMergedPR)) {
done();
}
return data;
})
return this.fetchAllPullRequests(_.map(PRList, this.getPullRequestNumberFromURL))
.then((data) => {
const automatedPRs = _.pluck(
_.filter(data, GithubUtils.isAutomatedPullRequest),
'html_url',
);
console.log('Filtering out the following automated pull requests:', automatedPRs);
const sortedPRList = _.chain(PRList)
.difference(automatedPRs)
.unique()
Expand Down
17 changes: 2 additions & 15 deletions .github/actions/isStagingDeployLocked/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,26 +240,13 @@ class GithubUtils {
deployBlockers = [],
resolvedDeployBlockers = [],
) {
return this.octokit.paginate(this.octokit.pulls.list, {
owner: GITHUB_OWNER,
repo: EXPENSIFY_CASH_REPO,
state: 'all',
sort: 'created',
direction: 'desc',
per_page: 100,
}, ({data}, done) => {
// PRList is reverse-chronologically ordered
const oldestMergedPR = _.last(PRList);
if (_.find(data, pr => pr.html_url === oldestMergedPR)) {
done();
}
return data;
})
return this.fetchAllPullRequests(_.map(PRList, this.getPullRequestNumberFromURL))
.then((data) => {
const automatedPRs = _.pluck(
_.filter(data, GithubUtils.isAutomatedPullRequest),
'html_url',
);
console.log('Filtering out the following automated pull requests:', automatedPRs);
const sortedPRList = _.chain(PRList)
.difference(automatedPRs)
.unique()
Expand Down
17 changes: 2 additions & 15 deletions .github/actions/markPullRequestsAsDeployed/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,26 +392,13 @@ class GithubUtils {
deployBlockers = [],
resolvedDeployBlockers = [],
) {
return this.octokit.paginate(this.octokit.pulls.list, {
owner: GITHUB_OWNER,
repo: EXPENSIFY_CASH_REPO,
state: 'all',
sort: 'created',
direction: 'desc',
per_page: 100,
}, ({data}, done) => {
// PRList is reverse-chronologically ordered
const oldestMergedPR = _.last(PRList);
if (_.find(data, pr => pr.html_url === oldestMergedPR)) {
done();
}
return data;
})
return this.fetchAllPullRequests(_.map(PRList, this.getPullRequestNumberFromURL))
.then((data) => {
const automatedPRs = _.pluck(
_.filter(data, GithubUtils.isAutomatedPullRequest),
'html_url',
);
console.log('Filtering out the following automated pull requests:', automatedPRs);
const sortedPRList = _.chain(PRList)
.difference(automatedPRs)
.unique()
Expand Down
17 changes: 2 additions & 15 deletions .github/actions/reopenIssueWithComment/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,26 +251,13 @@ class GithubUtils {
deployBlockers = [],
resolvedDeployBlockers = [],
) {
return this.octokit.paginate(this.octokit.pulls.list, {
owner: GITHUB_OWNER,
repo: EXPENSIFY_CASH_REPO,
state: 'all',
sort: 'created',
direction: 'desc',
per_page: 100,
}, ({data}, done) => {
// PRList is reverse-chronologically ordered
const oldestMergedPR = _.last(PRList);
if (_.find(data, pr => pr.html_url === oldestMergedPR)) {
done();
}
return data;
})
return this.fetchAllPullRequests(_.map(PRList, this.getPullRequestNumberFromURL))
.then((data) => {
const automatedPRs = _.pluck(
_.filter(data, GithubUtils.isAutomatedPullRequest),
'html_url',
);
console.log('Filtering out the following automated pull requests:', automatedPRs);
const sortedPRList = _.chain(PRList)
.difference(automatedPRs)
.unique()
Expand Down
17 changes: 2 additions & 15 deletions .github/actions/triggerWorkflowAndWait/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,26 +402,13 @@ class GithubUtils {
deployBlockers = [],
resolvedDeployBlockers = [],
) {
return this.octokit.paginate(this.octokit.pulls.list, {
owner: GITHUB_OWNER,
repo: EXPENSIFY_CASH_REPO,
state: 'all',
sort: 'created',
direction: 'desc',
per_page: 100,
}, ({data}, done) => {
// PRList is reverse-chronologically ordered
const oldestMergedPR = _.last(PRList);
if (_.find(data, pr => pr.html_url === oldestMergedPR)) {
done();
}
return data;
})
return this.fetchAllPullRequests(_.map(PRList, this.getPullRequestNumberFromURL))
.then((data) => {
const automatedPRs = _.pluck(
_.filter(data, GithubUtils.isAutomatedPullRequest),
'html_url',
);
console.log('Filtering out the following automated pull requests:', automatedPRs);
const sortedPRList = _.chain(PRList)
.difference(automatedPRs)
.unique()
Expand Down
17 changes: 2 additions & 15 deletions .github/libs/GithubUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,26 +200,13 @@ class GithubUtils {
deployBlockers = [],
resolvedDeployBlockers = [],
) {
return this.octokit.paginate(this.octokit.pulls.list, {
owner: GITHUB_OWNER,
repo: EXPENSIFY_CASH_REPO,
state: 'all',
sort: 'created',
direction: 'desc',
per_page: 100,
}, ({data}, done) => {
// PRList is reverse-chronologically ordered
const oldestMergedPR = _.last(PRList);
if (_.find(data, pr => pr.html_url === oldestMergedPR)) {
done();
}
return data;
})
return this.fetchAllPullRequests(_.map(PRList, this.getPullRequestNumberFromURL))
.then((data) => {
const automatedPRs = _.pluck(
_.filter(data, GithubUtils.isAutomatedPullRequest),
'html_url',
);
console.log('Filtering out the following automated pull requests:', automatedPRs);
const sortedPRList = _.chain(PRList)
.difference(automatedPRs)
.unique()
Expand Down

0 comments on commit f5c9b21

Please sign in to comment.