diff --git a/.github/actions/createOrUpdateStagingDeploy/index.js b/.github/actions/createOrUpdateStagingDeploy/index.js index 0c9c04620081..a73d9abeec88 100644 --- a/.github/actions/createOrUpdateStagingDeploy/index.js +++ b/.github/actions/createOrUpdateStagingDeploy/index.js @@ -195,14 +195,33 @@ const {execSync} = __nccwpck_require__(3129); * @returns {Array} */ function getPullRequestsMergedBetween(fromRef, toRef) { - const command = `git log --format="%s" ${fromRef}...${toRef}`; + const command = `git log --format="{[%B]}" ${fromRef}...${toRef}`; console.log('Getting pull requests merged between the following refs:', fromRef, toRef); console.log('Running command: ', command); const localGitLogs = execSync(command).toString(); - return _.map( - [...localGitLogs.matchAll(/Merge pull request #(\d{1,6}) from (?!Expensify\/(?:master|main|version-))/g)], + + // Parse the git log into an array of commit messages between the two refs + const commitMessages = _.map( + [...localGitLogs.matchAll(/{\[([\s\S]*?)\]}/gm)], match => match[1], ); + console.log(`A list of commits made between ${fromRef} and ${toRef}:\n${commitMessages}`); + + // We need to find which commit messages correspond to merge commits and get PR numbers. + // Additionally, we omit merge commits made while cherry picking using negative lookahead in the regexp. + const pullRequestIDs = _.reduce(commitMessages, (mergedPRs, commitMessage) => { + const mergeCommits = [ + ...commitMessage.matchAll(/Merge pull request #(\d{1,6}) from (?!(?:Expensify\/(?:master|main|version-))|(?:([\s\S]*?)\(cherry picked from commit .*\)\s*))/gm), + ]; + + // Get the PR number of the first match (there should not be multiple matches in one commit message) + if (_.size(mergeCommits)) { + mergedPRs.push(mergeCommits[0][1]); + } + return mergedPRs; + }, []); + console.log(`A list of pull requests merged between ${fromRef} and ${toRef}:\n${pullRequestIDs}`); + return pullRequestIDs; } module.exports = { diff --git a/.github/actions/getDeployPullRequestList/index.js b/.github/actions/getDeployPullRequestList/index.js index 6eca50094531..fa25492fcfc2 100644 --- a/.github/actions/getDeployPullRequestList/index.js +++ b/.github/actions/getDeployPullRequestList/index.js @@ -117,14 +117,33 @@ const {execSync} = __nccwpck_require__(3129); * @returns {Array} */ function getPullRequestsMergedBetween(fromRef, toRef) { - const command = `git log --format="%s" ${fromRef}...${toRef}`; + const command = `git log --format="{[%B]}" ${fromRef}...${toRef}`; console.log('Getting pull requests merged between the following refs:', fromRef, toRef); console.log('Running command: ', command); const localGitLogs = execSync(command).toString(); - return _.map( - [...localGitLogs.matchAll(/Merge pull request #(\d{1,6}) from (?!Expensify\/(?:master|main|version-))/g)], + + // Parse the git log into an array of commit messages between the two refs + const commitMessages = _.map( + [...localGitLogs.matchAll(/{\[([\s\S]*?)\]}/gm)], match => match[1], ); + console.log(`A list of commits made between ${fromRef} and ${toRef}:\n${commitMessages}`); + + // We need to find which commit messages correspond to merge commits and get PR numbers. + // Additionally, we omit merge commits made while cherry picking using negative lookahead in the regexp. + const pullRequestIDs = _.reduce(commitMessages, (mergedPRs, commitMessage) => { + const mergeCommits = [ + ...commitMessage.matchAll(/Merge pull request #(\d{1,6}) from (?!(?:Expensify\/(?:master|main|version-))|(?:([\s\S]*?)\(cherry picked from commit .*\)\s*))/gm), + ]; + + // Get the PR number of the first match (there should not be multiple matches in one commit message) + if (_.size(mergeCommits)) { + mergedPRs.push(mergeCommits[0][1]); + } + return mergedPRs; + }, []); + console.log(`A list of pull requests merged between ${fromRef} and ${toRef}:\n${pullRequestIDs}`); + return pullRequestIDs; } module.exports = { diff --git a/.github/libs/GitUtils.js b/.github/libs/GitUtils.js index 5f86983ac6c3..194401ed9238 100644 --- a/.github/libs/GitUtils.js +++ b/.github/libs/GitUtils.js @@ -9,14 +9,33 @@ const {execSync} = require('child_process'); * @returns {Array} */ function getPullRequestsMergedBetween(fromRef, toRef) { - const command = `git log --format="%s" ${fromRef}...${toRef}`; + const command = `git log --format="{[%B]}" ${fromRef}...${toRef}`; console.log('Getting pull requests merged between the following refs:', fromRef, toRef); console.log('Running command: ', command); const localGitLogs = execSync(command).toString(); - return _.map( - [...localGitLogs.matchAll(/Merge pull request #(\d{1,6}) from (?!Expensify\/(?:master|main|version-))/g)], + + // Parse the git log into an array of commit messages between the two refs + const commitMessages = _.map( + [...localGitLogs.matchAll(/{\[([\s\S]*?)\]}/gm)], match => match[1], ); + console.log(`A list of commits made between ${fromRef} and ${toRef}:\n${commitMessages}`); + + // We need to find which commit messages correspond to merge commits and get PR numbers. + // Additionally, we omit merge commits made while cherry picking using negative lookahead in the regexp. + const pullRequestIDs = _.reduce(commitMessages, (mergedPRs, commitMessage) => { + const mergeCommits = [ + ...commitMessage.matchAll(/Merge pull request #(\d{1,6}) from (?!(?:Expensify\/(?:master|main|version-))|(?:([\s\S]*?)\(cherry picked from commit .*\)\s*))/gm), + ]; + + // Get the PR number of the first match (there should not be multiple matches in one commit message) + if (_.size(mergeCommits)) { + mergedPRs.push(mergeCommits[0][1]); + } + return mergedPRs; + }, []); + console.log(`A list of pull requests merged between ${fromRef} and ${toRef}:\n${pullRequestIDs}`); + return pullRequestIDs; } module.exports = { diff --git a/tests/unit/GitUtilsTest.js b/tests/unit/GitUtilsTest.js index 623c6c25e24d..f10e02839cc0 100644 --- a/tests/unit/GitUtilsTest.js +++ b/tests/unit/GitUtilsTest.js @@ -6,43 +6,96 @@ const {execSync} = childProcess; const data = [ { - gitLog: `Start adding StagingDeployCash logic - Setting up bones - Merge pull request #337 from Expensify/francoisUpdateQbdSyncManager - Merge pull request #336 from Expensify/andrew-pr-cla - Update QBD Sync Manager version - Only run CLA on PR comments or events - Merge pull request #331 from Expensify/marcaaron-killMoment - Merge pull request #330 from Expensify/andrew-cla-update - Merge pull request #333 from Expensify/Rory-AddOnOffSwitchTooltip - Setup OnOffSwitch component with tooltips - Merge pull request #332 from Expensify/alex-mechler-patch-1 - Return to old hash-based deploy instrcutions - Remove DEFAULT_START_DATE & DEFAULT_END_DATE altogether`, + gitLog: `{[Start adding StagingDeployCash logic + ]} + {[Setting up bones + ]} + {[Merge pull request #337 from Expensify/francoisUpdateQbdSyncManager + ]} + {[Merge pull request #336 from Expensify/andrew-pr-cla + ]} + {[Update QBD Sync Manager version + ]} + {[Only run CLA on PR comments or events + ]} + {[Merge pull request #331 from Expensify/marcaaron-killMoment + ]} + {[Merge pull request #330 from Expensify/andrew-cla-update + ]} + {[Merge pull request #333 from Expensify/Rory-AddOnOffSwitchTooltip + ]} + {[Setup OnOffSwitch component with tooltips + ]} + {[Merge pull request #332 from Expensify/alex-mechler-patch-1 + ]} + {[Return to old hash-based deploy instrcutions + ]} + {[Remove DEFAULT_START_DATE & DEFAULT_END_DATE altogether + ]}`, result: ['337', '336', '331', '330', '333', '332'], }, { - gitLog: `Merge pull request #1521 from parasharrajat/parasharrajat/pdf-render - Merge pull request #1563 from Expensify/version-bump-e6498075e301df3e9c8d7866ea391a23c19ed9b0 - Update version to 1.0.1-470 - Merge pull request #1557 from aliabbasmalik8/IS-1500-compose-field-alignment-issue - Merge pull request #1562 from Expensify/version-bump-b9c85aa97dfb656b01a83871b4bbaed5e287c8b7 - Update version to 1.0.1-469 - Merge pull request #1515 from anthony-hull/typos - [IS-1500] Updated textalignInput utility - Merge pull request #1560 from Expensify/version-bump-b742a55d18e761cd7adb0849a29cfb48b3a04f99 - Update version to 1.0.1-468 - Merge pull request #1555 from SameeraMadushan/sameera-IsAppInstalledLogic - Merge pull request #1 from Expensify/master - Merge pull request #2 from Expensify/main - fix: set pdf width on large screens - [IS-1500] Fixed compose field alignment issue`, - result: ['1521', '1557', '1515', '1555'], + gitLog: `{[Merge pull request #1521 from parasharrajat/parasharrajat/pdf-render + ]} + {[Merge pull request #1563 from Expensify/version-bump-e6498075e301df3e9c8d7866ea391a23c19ed9b0 + ]} + {[Update version to 1.0.1-470 + ]} + {[Merge pull request #1557 from aliabbasmalik8/IS-1500-compose-field-alignment-issue + ]} + {[Merge pull request #1562 from Expensify/version-bump-b9c85aa97dfb656b01a83871b4bbaed5e287c8b7 + ]} + {[Update version to 1.0.1-469 + ]} + {[Merge pull request #1515 from anthony-hull/typos + ]} + {[[IS-1500] Updated textalignInput utility + ]} + {[Merge pull request #1560 from Expensify/version-bump-b742a55d18e761cd7adb0849a29cfb48b3a04f99 + ]} + {[Update version to 1.0.1-468 + ]} + {[Merge pull request #1555 from SameeraMadushan/sameera-IsAppInstalledLogic + ]} + {[Merge pull request #1 from Expensify/master + ]} + {[Merge pull request #2 from Expensify/main + ]} + {[fix: set pdf width on large screens + ]} + {[[IS-1500] Fixed compose field alignment issue + ]} + {[Merge pull request #5812 from akshayasalvi/tooltip-workspace-name … + 42b5016 + Added tooltip for workspace name + + (cherry picked from commit a77d468) + ]} + {[Merge pull request #5813 from Expensify/master … + 42b5016 + Added tooltip for workspace name + + (cherry picked from commit a77d468) + ]} + {[Merge pull request #1111 from akshayasalvi/tooltip-workspace-name … + 42b5016 + Added tooltip for workspace name + + (something else than cherry pick commit a77d468) + ]} + {[Merge pull request #9 from Expensify/main + ]} + {[fix: set pdf width on large screens + ]}`, + result: ['1521', '1557', '1515', '1555', '1111'], }, { - gitLog: `Return to old hash-based deploy instrcutions - Remove DEFAULT_START_DATE & DEFAULT_END_DATE altogether - refactor`, + gitLog: `{[Return to old hash-based deploy instrcutions + ]} + {[Remove DEFAULT_START_DATE & DEFAULT_END_DATE altogether + ]} + {[refactor + ]}`, result: [], }, ];