Skip to content

Commit b7168b6

Browse files
Galen Ricegilbertsoft
Galen Rice
authored andcommitted
[FEATURE] Skip merge commits in pull requests
Merge commits can be identified by having two parent commits, so we add to the GraphQL query selecting PR commits to also return `parents.totalCount`. This shows any standard commit having 1 parent, and merge commits having 2. We can then `.filter()` out those instances before mapping commit messages.
1 parent 4c06ad2 commit b7168b6

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/input-helper.ts

+18-6
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,10 @@ async function getCommitMessagesFromPullRequest(
241241
edges {
242242
node {
243243
commit {
244-
message
244+
message,
245+
parents(last: 1) {
246+
totalCount
247+
}
245248
}
246249
}
247250
}
@@ -267,6 +270,9 @@ async function getCommitMessagesFromPullRequest(
267270
node: {
268271
commit: {
269272
message: string
273+
parents: {
274+
totalCount: number
275+
}
270276
}
271277
}
272278
}
@@ -289,11 +295,17 @@ async function getCommitMessagesFromPullRequest(
289295
let messages: string[] = []
290296

291297
if (repository.pullRequest) {
292-
messages = repository.pullRequest.commits.edges.map(function (
293-
edge: CommitEdgeItem
294-
): string {
295-
return edge.node.commit.message
296-
})
298+
messages = repository.pullRequest.commits.edges
299+
.filter(function (edge: CommitEdgeItem): boolean {
300+
if (edge.node.commit.parents.totalCount > 1) {
301+
// Skip merge commits (which have more than 1 parent commit)
302+
return false
303+
}
304+
return true
305+
})
306+
.map(function (edge: CommitEdgeItem): string {
307+
return edge.node.commit.message
308+
})
297309
}
298310

299311
return messages

0 commit comments

Comments
 (0)