@@ -133,6 +133,11 @@ export async function removeLabel(label: string) {
133
133
}
134
134
}
135
135
136
+ export function isMergeFromMainBranch ( commitMessage : string ) : boolean {
137
+ const mergeFromMainCommitMessagePrefix = `Merge branch 'main' into` ;
138
+ return commitMessage . startsWith ( mergeFromMainCommitMessagePrefix ) ;
139
+ }
140
+
136
141
export async function getLatestAssociatedBitriseComment ( commitHashes : string [ ] ) : Promise < GithubComment | undefined > {
137
142
138
143
// Get all Bitrise comments
@@ -145,16 +150,48 @@ export async function getLatestAssociatedBitriseComment(commitHashes: string[]):
145
150
146
151
console . log ( `Checking if recent commits have Bitrise comments: ${ commitHashes } ` ) ;
147
152
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
+ }
154
191
}
155
192
}
156
193
157
- return undefined
194
+ return undefined ;
158
195
}
159
196
160
197
export async function getBitriseTestStatus ( bitriseComment : GithubComment ) : Promise < BitriseTestStatus > {
@@ -344,4 +381,4 @@ export function shouldRunBitriseE2E(flags : E2ERunFlags): [boolean, string] {
344
381
345
382
// Default case if no conditions met
346
383
return [ false , "Unexpected scenario or no relevant labels found." ] ;
347
- }
384
+ }
0 commit comments