@@ -133,6 +133,16 @@ export async function removeLabel(label: string) {
133
133
}
134
134
}
135
135
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
+
136
146
export async function getLatestAssociatedBitriseComment ( commitHashes : string [ ] ) : Promise < GithubComment | undefined > {
137
147
138
148
// Get all Bitrise comments
@@ -145,16 +155,48 @@ export async function getLatestAssociatedBitriseComment(commitHashes: string[]):
145
155
146
156
console . log ( `Checking if recent commits have Bitrise comments: ${ commitHashes } ` ) ;
147
157
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
+ }
154
196
}
155
197
}
156
198
157
- return undefined
199
+ return undefined ;
158
200
}
159
201
160
202
export async function getBitriseTestStatus ( bitriseComment : GithubComment ) : Promise < BitriseTestStatus > {
@@ -344,4 +386,4 @@ export function shouldRunBitriseE2E(flags : E2ERunFlags): [boolean, string] {
344
386
345
387
// Default case if no conditions met
346
388
return [ false , "Unexpected scenario or no relevant labels found." ] ;
347
- }
389
+ }
0 commit comments