Skip to content

Commit 3e06e0e

Browse files
authored
Merge pull request #31507 from Expensify/Rory-ImproveGitUtilsLogs
[No QA] Improve GitUtils logging
2 parents 7c3b07a + 97c1cb0 commit 3e06e0e

File tree

4 files changed

+43
-37
lines changed

4 files changed

+43
-37
lines changed

.github/actions/javascript/createOrUpdateStagingDeploy/index.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,16 @@ function fetchTag(tag) {
198198
let needsRepack = false;
199199
while (shouldRetry) {
200200
try {
201+
let command = '';
201202
if (needsRepack) {
202203
// We have seen some scenarios where this fixes the git fetch.
203204
// Why? Who knows... https://github.com/Expensify/App/pull/31459
204-
execSync('git repack -d');
205+
command = 'git repack -d';
206+
console.log(`Running command: ${command}`);
207+
execSync(command);
205208
}
206209

207-
let command = `git fetch origin tag ${tag} --no-tags`;
210+
command = `git fetch origin tag ${tag} --no-tags`;
208211

209212
// Exclude commits reachable from the previous patch version (i.e: previous checklist),
210213
// so that we don't have to fetch the full history
@@ -315,16 +318,15 @@ function getValidMergedPRs(commits) {
315318
* @param {String} toTag
316319
* @returns {Promise<Array<Number>>} – Pull request numbers
317320
*/
318-
function getPullRequestsMergedBetween(fromTag, toTag) {
321+
async function getPullRequestsMergedBetween(fromTag, toTag) {
319322
console.log(`Looking for commits made between ${fromTag} and ${toTag}...`);
320-
return getCommitHistoryAsJSON(fromTag, toTag).then((commitList) => {
321-
console.log(`Commits made between ${fromTag} and ${toTag}:`, commitList);
323+
const commitList = await getCommitHistoryAsJSON(fromTag, toTag);
324+
console.log(`Commits made between ${fromTag} and ${toTag}:`, commitList);
322325

323-
// Find which commit messages correspond to merged PR's
324-
const pullRequestNumbers = getValidMergedPRs(commitList);
325-
console.log(`List of pull requests merged between ${fromTag} and ${toTag}`, pullRequestNumbers);
326-
return _.map(pullRequestNumbers, (prNum) => Number.parseInt(prNum, 10));
327-
});
326+
// Find which commit messages correspond to merged PR's
327+
const pullRequestNumbers = getValidMergedPRs(commitList).sort((a, b) => a - b);
328+
console.log(`List of pull requests merged between ${fromTag} and ${toTag}`, pullRequestNumbers);
329+
return pullRequestNumbers;
328330
}
329331

330332
module.exports = {

.github/actions/javascript/getDeployPullRequestList/index.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,16 @@ function fetchTag(tag) {
140140
let needsRepack = false;
141141
while (shouldRetry) {
142142
try {
143+
let command = '';
143144
if (needsRepack) {
144145
// We have seen some scenarios where this fixes the git fetch.
145146
// Why? Who knows... https://github.com/Expensify/App/pull/31459
146-
execSync('git repack -d');
147+
command = 'git repack -d';
148+
console.log(`Running command: ${command}`);
149+
execSync(command);
147150
}
148151

149-
let command = `git fetch origin tag ${tag} --no-tags`;
152+
command = `git fetch origin tag ${tag} --no-tags`;
150153

151154
// Exclude commits reachable from the previous patch version (i.e: previous checklist),
152155
// so that we don't have to fetch the full history
@@ -257,16 +260,15 @@ function getValidMergedPRs(commits) {
257260
* @param {String} toTag
258261
* @returns {Promise<Array<Number>>} – Pull request numbers
259262
*/
260-
function getPullRequestsMergedBetween(fromTag, toTag) {
263+
async function getPullRequestsMergedBetween(fromTag, toTag) {
261264
console.log(`Looking for commits made between ${fromTag} and ${toTag}...`);
262-
return getCommitHistoryAsJSON(fromTag, toTag).then((commitList) => {
263-
console.log(`Commits made between ${fromTag} and ${toTag}:`, commitList);
265+
const commitList = await getCommitHistoryAsJSON(fromTag, toTag);
266+
console.log(`Commits made between ${fromTag} and ${toTag}:`, commitList);
264267

265-
// Find which commit messages correspond to merged PR's
266-
const pullRequestNumbers = getValidMergedPRs(commitList);
267-
console.log(`List of pull requests merged between ${fromTag} and ${toTag}`, pullRequestNumbers);
268-
return _.map(pullRequestNumbers, (prNum) => Number.parseInt(prNum, 10));
269-
});
268+
// Find which commit messages correspond to merged PR's
269+
const pullRequestNumbers = getValidMergedPRs(commitList).sort((a, b) => a - b);
270+
console.log(`List of pull requests merged between ${fromTag} and ${toTag}`, pullRequestNumbers);
271+
return pullRequestNumbers;
270272
}
271273

272274
module.exports = {

.github/libs/GitUtils.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@ function fetchTag(tag) {
1313
let needsRepack = false;
1414
while (shouldRetry) {
1515
try {
16+
let command = '';
1617
if (needsRepack) {
1718
// We have seen some scenarios where this fixes the git fetch.
1819
// Why? Who knows... https://github.com/Expensify/App/pull/31459
19-
execSync('git repack -d');
20+
command = 'git repack -d';
21+
console.log(`Running command: ${command}`);
22+
execSync(command);
2023
}
2124

22-
let command = `git fetch origin tag ${tag} --no-tags`;
25+
command = `git fetch origin tag ${tag} --no-tags`;
2326

2427
// Exclude commits reachable from the previous patch version (i.e: previous checklist),
2528
// so that we don't have to fetch the full history
@@ -130,16 +133,15 @@ function getValidMergedPRs(commits) {
130133
* @param {String} toTag
131134
* @returns {Promise<Array<Number>>} – Pull request numbers
132135
*/
133-
function getPullRequestsMergedBetween(fromTag, toTag) {
136+
async function getPullRequestsMergedBetween(fromTag, toTag) {
134137
console.log(`Looking for commits made between ${fromTag} and ${toTag}...`);
135-
return getCommitHistoryAsJSON(fromTag, toTag).then((commitList) => {
136-
console.log(`Commits made between ${fromTag} and ${toTag}:`, commitList);
138+
const commitList = await getCommitHistoryAsJSON(fromTag, toTag);
139+
console.log(`Commits made between ${fromTag} and ${toTag}:`, commitList);
137140

138-
// Find which commit messages correspond to merged PR's
139-
const pullRequestNumbers = getValidMergedPRs(commitList);
140-
console.log(`List of pull requests merged between ${fromTag} and ${toTag}`, pullRequestNumbers);
141-
return _.map(pullRequestNumbers, (prNum) => Number.parseInt(prNum, 10));
142-
});
141+
// Find which commit messages correspond to merged PR's
142+
const pullRequestNumbers = getValidMergedPRs(commitList).sort((a, b) => a - b);
143+
console.log(`List of pull requests merged between ${fromTag} and ${toTag}`, pullRequestNumbers);
144+
return pullRequestNumbers;
143145
}
144146

145147
module.exports = {

tests/unit/CIGitLogicTest.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ cherry_pick_pr 3
238238
tag_staging
239239

240240
# Verify output for checklist
241-
assert_prs_merged_between '1.0.0-0' '1.0.0-2' "[ 3, 1 ]"
241+
assert_prs_merged_between '1.0.0-0' '1.0.0-2' "[ 1, 3 ]"
242242

243243
# Verify output for deploy comment
244244
assert_prs_merged_between '1.0.0-1' '1.0.0-2' "[ 3 ]"
@@ -252,7 +252,7 @@ title "Scenario #4A: Run the production deploy"
252252
update_production_from_staging
253253

254254
# Verify output for release body and production deploy comments
255-
assert_prs_merged_between '1.0.0-0' '1.0.0-2' "[ 3, 1 ]"
255+
assert_prs_merged_between '1.0.0-0' '1.0.0-2' "[ 1, 3 ]"
256256

257257
success "Scenario #4A completed successfully!"
258258

@@ -284,7 +284,7 @@ update_staging_from_main
284284
tag_staging
285285

286286
# Verify output for checklist
287-
assert_prs_merged_between '1.0.0-2' '1.0.1-1' "[ 5, 2 ]"
287+
assert_prs_merged_between '1.0.0-2' '1.0.1-1' "[ 2, 5 ]"
288288

289289
# Verify output for deploy comment
290290
assert_prs_merged_between '1.0.1-0' '1.0.1-1' "[ 5 ]"
@@ -307,7 +307,7 @@ update_staging_from_main
307307
tag_staging
308308

309309
# Verify output for checklist
310-
assert_prs_merged_between '1.0.0-2' '1.0.1-2' "[ 6, 5, 2 ]"
310+
assert_prs_merged_between '1.0.0-2' '1.0.1-2' "[ 2, 5, 6 ]"
311311

312312
# Verify output for deploy comment
313313
assert_prs_merged_between '1.0.1-1' '1.0.1-2' "[ 6 ]"
@@ -329,7 +329,7 @@ update_staging_from_main
329329
tag_staging
330330

331331
# Verify output for checklist
332-
assert_prs_merged_between '1.0.0-2' '1.0.1-3' "[ 7, 6, 5, 2 ]"
332+
assert_prs_merged_between '1.0.0-2' '1.0.1-3' "[ 2, 5, 6, 7 ]"
333333

334334
# Verify output for deploy comment
335335
assert_prs_merged_between '1.0.1-2' '1.0.1-3' "[ 7 ]"
@@ -389,10 +389,10 @@ update_staging_from_main
389389
tag_staging
390390

391391
# Verify production release list
392-
assert_prs_merged_between '1.0.0-2' '1.0.1-4' "[ 9, 7, 6, 5, 2 ]"
392+
assert_prs_merged_between '1.0.0-2' '1.0.1-4' "[ 2, 5, 6, 7, 9 ]"
393393

394394
# Verify PR list for the new checklist
395-
assert_prs_merged_between '1.0.1-4' '1.0.2-0' "[ 10, 8 ]"
395+
assert_prs_merged_between '1.0.1-4' '1.0.2-0' "[ 8, 10 ]"
396396

397397
### Cleanup
398398
title "Cleaning up..."

0 commit comments

Comments
 (0)