Skip to content

Commit 7a51c1d

Browse files
committed
fix: ensure 'evaluate all' works correctly with git sha
1 parent df3eb37 commit 7a51c1d

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

pkg/scm/gitlab/client_merge_request.go

+13-4
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,19 @@ func (client *MergeRequestClient) List(ctx context.Context, options *scm.ListMer
8787
return nil, err
8888
}
8989

90-
hits := []scm.ListMergeRequest{}
91-
for _, x := range result.Project.MergeRequests.Nodes {
92-
hits = append(hits, scm.ListMergeRequest{ID: x.ID})
90+
results := []scm.ListMergeRequest{}
91+
92+
for _, mergeRequest := range result.Project.MergeRequests.Nodes {
93+
// If there are no DiffHeadSha; there are no commits on the MR; so don't process it
94+
if mergeRequest.DiffHeadSha == nil {
95+
continue
96+
}
97+
98+
results = append(results, scm.ListMergeRequest{
99+
ID: mergeRequest.ID,
100+
SHA: *mergeRequest.DiffHeadSha,
101+
})
93102
}
94103

95-
return hits, nil
104+
return results, nil
96105
}

schema/gitlab.schema.graphqls

+6-5
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type Context {
3838
CurrentUser: ContextUser!
3939

4040
"Information about the event that triggered the evaluation. Empty when not using webhook server."
41-
WebhookEvent: Any @generated
41+
WebhookEvent: Any @generated @expr(key: "webhook_event")
4242
}
4343

4444
enum MergeRequestState {
@@ -98,7 +98,8 @@ type ListMergeRequestsProjectMergeRequestNodes {
9898
}
9999

100100
type ListMergeRequestsProjectMergeRequest {
101-
ID: String! @graphql(key: "iid") @internal
101+
ID: String! @graphql(key: "iid") @internal
102+
DiffHeadSha: String @graphql(key: "diffHeadSha") @internal
102103
}
103104

104105
# https://docs.gitlab.com/ee/api/graphql/reference/#project
@@ -135,9 +136,9 @@ type ContextProject {
135136
"Labels available on this project"
136137
Labels: [ContextLabel!] @generated
137138

138-
ResponseLabels: ContextLabelNode @internal @graphql(key: "labels(first: 200)")
139-
MergeRequest: ContextMergeRequest @internal @graphql(key: "mergeRequest(iid: $mr_id)")
140-
ResponseGroup: ContextGroup @internal @graphql(key: "group")
139+
ResponseLabels: ContextLabelNode @internal @graphql(key: "labels(first: 200)")
140+
MergeRequest: ContextMergeRequest @internal @graphql(key: "mergeRequest(iid: $mr_id)")
141+
ResponseGroup: ContextGroup @internal @graphql(key: "group")
141142
}
142143

143144
# https://docs.gitlab.com/ee/api/graphql/reference/#group

0 commit comments

Comments
 (0)