Skip to content

Commit f5b091b

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

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)