Skip to content

Commit f3941d5

Browse files
committed
feat(INFRA-2531): check for bitrise success comments in imported commits
1 parent b22bfcc commit f3941d5

File tree

2 files changed

+51
-9
lines changed

2 files changed

+51
-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: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,16 @@ export async function removeLabel(label: string) {
133133
}
134134
}
135135

136+
/**
137+
* Determines if a commit message indicates a merge from the main branch
138+
* @param commitMessage The commit message to check
139+
* @returns True if the commit is a merge from main branch
140+
*/
141+
export function isMergeFromMainBranch(commitMessage: string): boolean {
142+
const mergeFromMainCommitMessagePrefix = `Merge branch 'main' into`;
143+
return commitMessage.startsWith(mergeFromMainCommitMessagePrefix);
144+
}
145+
136146
export async function getLatestAssociatedBitriseComment(commitHashes: string[]): Promise<GithubComment | undefined> {
137147

138148
// Get all Bitrise comments
@@ -145,16 +155,48 @@ export async function getLatestAssociatedBitriseComment(commitHashes: string[]):
145155

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

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;
158+
// Check if the latest commit has a Bitrise comment
159+
if (commitHashes.length > 0) {
160+
const latestCommit = commitHashes[0];
161+
const latestCommitComment = comments.find(comment => comment.commitSha === latestCommit);
162+
163+
if (latestCommitComment) {
164+
console.log(`Found Bitrise comment for latest commit: ${latestCommit}`);
165+
return latestCommitComment;
166+
}
167+
168+
// If we're here, the latest commit doesn't have a Bitrise comment
169+
// Get commit messages to check if they're merge commits
170+
const { owner, repo, number: pullRequestNumber } = context.issue;
171+
const { data: commits } = await getOctokitInstance().rest.pulls.listCommits({
172+
owner,
173+
repo,
174+
pull_number: pullRequestNumber
175+
});
176+
177+
// Create a map of commit SHA to commit message
178+
const commitMessages = new Map<string, string>();
179+
commits.forEach(commit => {
180+
commitMessages.set(commit.sha, commit.commit.message);
181+
});
182+
183+
// Check older commits, but only consider those that are merge commits from main
184+
for (let i = 1; i < commitHashes.length; i++) {
185+
const commitHash = commitHashes[i];
186+
const commitMessage = commitMessages.get(commitHash) || '';
187+
188+
// Only consider this commit if it's a merge from main
189+
if (isMergeFromMainBranch(commitMessage)) {
190+
const foundComment = comments.find(comment => comment.commitSha === commitHash);
191+
if (foundComment) {
192+
console.log(`Found Bitrise comment for merge commit: ${commitHash}`);
193+
return foundComment;
194+
}
195+
}
154196
}
155197
}
156198

157-
return undefined
199+
return undefined;
158200
}
159201

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

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

0 commit comments

Comments
 (0)