Skip to content

feat(INFRA-2531): check for bitrise success comments in imported commits #15349

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/scripts/bitrise/bitrise-results-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,4 @@ async function main(): Promise<void> {
main().catch((error: Error): void => {
console.error(error);
process.exit(1);
});
});
53 changes: 45 additions & 8 deletions .github/scripts/bitrise/bitrise-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ export async function removeLabel(label: string) {
}
}

export function isMergeFromMainBranch(commitMessage: string): boolean {
const mergeFromMainCommitMessagePrefix = `Merge branch 'main' into`;
return commitMessage.startsWith(mergeFromMainCommitMessagePrefix);
}

export async function getLatestAssociatedBitriseComment(commitHashes: string[]): Promise<GithubComment | undefined> {

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

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

// Iterate through each commit hash to find the first matching Bitrise comment
// Return the first matching comment as our commits are sorted by newest to oldest
for (let i = 0; i < commitHashes.length; i++) {
const foundComment = comments.find(comment => comment.commitSha === commitHashes[i]);
if (foundComment) {
return foundComment;
// Check if the latest commit has a Bitrise comment
if (commitHashes.length > 0) {
const latestCommit = commitHashes[0];
const latestCommitComment = comments.find(comment => comment.commitSha === latestCommit);

if (latestCommitComment) {
console.log(`Found Bitrise comment for latest commit: ${latestCommit}`);
return latestCommitComment;
}

// If we're here, the latest commit doesn't have a Bitrise comment
// Get commit messages to check if they're merge commits
const { owner, repo, number: pullRequestNumber } = context.issue;
const { data: commits } = await getOctokitInstance().rest.pulls.listCommits({
owner,
repo,
pull_number: pullRequestNumber
});

// Create a map of commit SHA to commit message
const commitMessages = new Map<string, string>();
commits.forEach(commit => {
commitMessages.set(commit.sha, commit.commit.message);
});

// Check older commits, but only consider those that are merge commits from main
for (let i = 1; i < commitHashes.length; i++) {
const commitHash = commitHashes[i];
const commitMessage = commitMessages.get(commitHash) || '';

// Only consider this commit if it's a merge from main
if (isMergeFromMainBranch(commitMessage)) {
const foundComment = comments.find(comment => comment.commitSha === commitHash);
if (foundComment) {
console.log(`Found Bitrise comment for merge commit: ${commitHash}`);
return foundComment;
}
}
}
}

return undefined
return undefined;
}

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

// Default case if no conditions met
return [false, "Unexpected scenario or no relevant labels found."];
}
}
Loading