Skip to content

Commit 7cca5bb

Browse files
authored
feat(INFRA-2531): check for bitrise success comments in imported commits (#15349)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> #15154 <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> ## **Related issues** Fixes: ## **Manual testing steps** 1. Go to this page... 2. 3. ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [ ] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
1 parent b287175 commit 7cca5bb

File tree

2 files changed

+46
-9
lines changed

2 files changed

+46
-9
lines changed

.github/scripts/bitrise/bitrise-results-check.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,4 @@ async function main(): Promise<void> {
8888
main().catch((error: Error): void => {
8989
console.error(error);
9090
process.exit(1);
91-
});
91+
});

.github/scripts/bitrise/bitrise-utils.ts

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ export async function removeLabel(label: string) {
133133
}
134134
}
135135

136+
export function isMergeFromMainBranch(commitMessage: string): boolean {
137+
const mergeFromMainCommitMessagePrefix = `Merge branch 'main' into`;
138+
return commitMessage.startsWith(mergeFromMainCommitMessagePrefix);
139+
}
140+
136141
export async function getLatestAssociatedBitriseComment(commitHashes: string[]): Promise<GithubComment | undefined> {
137142

138143
// Get all Bitrise comments
@@ -145,16 +150,48 @@ export async function getLatestAssociatedBitriseComment(commitHashes: string[]):
145150

146151
console.log(`Checking if recent commits have Bitrise comments: ${commitHashes}`);
147152

148-
// Iterate through each commit hash to find the first matching Bitrise comment
149-
// Return the first matching comment as our commits are sorted by newest to oldest
150-
for (let i = 0; i < commitHashes.length; i++) {
151-
const foundComment = comments.find(comment => comment.commitSha === commitHashes[i]);
152-
if (foundComment) {
153-
return foundComment;
153+
// Check if the latest commit has a Bitrise comment
154+
if (commitHashes.length > 0) {
155+
const latestCommit = commitHashes[0];
156+
const latestCommitComment = comments.find(comment => comment.commitSha === latestCommit);
157+
158+
if (latestCommitComment) {
159+
console.log(`Found Bitrise comment for latest commit: ${latestCommit}`);
160+
return latestCommitComment;
161+
}
162+
163+
// If we're here, the latest commit doesn't have a Bitrise comment
164+
// Get commit messages to check if they're merge commits
165+
const { owner, repo, number: pullRequestNumber } = context.issue;
166+
const { data: commits } = await getOctokitInstance().rest.pulls.listCommits({
167+
owner,
168+
repo,
169+
pull_number: pullRequestNumber
170+
});
171+
172+
// Create a map of commit SHA to commit message
173+
const commitMessages = new Map<string, string>();
174+
commits.forEach(commit => {
175+
commitMessages.set(commit.sha, commit.commit.message);
176+
});
177+
178+
// Check older commits, but only consider those that are merge commits from main
179+
for (let i = 1; i < commitHashes.length; i++) {
180+
const commitHash = commitHashes[i];
181+
const commitMessage = commitMessages.get(commitHash) || '';
182+
183+
// Only consider this commit if it's a merge from main
184+
if (isMergeFromMainBranch(commitMessage)) {
185+
const foundComment = comments.find(comment => comment.commitSha === commitHash);
186+
if (foundComment) {
187+
console.log(`Found Bitrise comment for merge commit: ${commitHash}`);
188+
return foundComment;
189+
}
190+
}
154191
}
155192
}
156193

157-
return undefined
194+
return undefined;
158195
}
159196

160197
export async function getBitriseTestStatus(bitriseComment: GithubComment): Promise<BitriseTestStatus> {
@@ -344,4 +381,4 @@ export function shouldRunBitriseE2E(flags : E2ERunFlags): [boolean, string] {
344381

345382
// Default case if no conditions met
346383
return [false, "Unexpected scenario or no relevant labels found."];
347-
}
384+
}

0 commit comments

Comments
 (0)