Skip to content

Commit

Permalink
fix commitshandler commitSHA tests
Browse files Browse the repository at this point in the history
Signed-off-by: Raghav Kaul <[email protected]>
  • Loading branch information
raghavkaul committed May 23, 2023
1 parent 8a09974 commit 1e08b55
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
3 changes: 2 additions & 1 deletion clients/gitlabrepo/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,12 @@ func (client *Client) ListCommits() ([]clients.Commit, error) {
return []clients.Commit{}, err
}

before := commitsRaw[0].CommittedDate
// Get merge request details from GraphQL
// GitLab REST API doesn't provide a way to link Merge Requests and Commits that
// are within them without making a REST call for each commit (~30 by default)
// Making 1 GraphQL query to combine the results of 2 REST calls, we avoid this
mrDetails, err := client.graphql.getMergeRequestsDetail()
mrDetails, err := client.graphql.getMergeRequestsDetail(before)
if err != nil {
return []clients.Commit{}, err
}
Expand Down
7 changes: 4 additions & 3 deletions clients/gitlabrepo/graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type graphqlData struct {
Project struct {
MergeRequests struct {
Nodes []graphqlMergeRequestNode `graphql:"nodes"`
} `graphql:"mergeRequests(sort: MERGED_AT_DESC, state: merged)"`
} `graphql:"mergeRequests(sort: MERGED_AT_DESC, state: merged, mergedBefore: $mergedBefore)"`
} `graphql:"project(fullPath: $fullPath)"`
QueryComplexity struct {
Limit int `graphql:"limit"`
Expand Down Expand Up @@ -127,11 +127,12 @@ func (g *GitlabGID) UnmarshalJSON(data []byte) error {
return nil
}

func (handler *graphqlHandler) getMergeRequestsDetail() (graphqlData, error) {
func (handler *graphqlHandler) getMergeRequestsDetail(before *time.Time) (graphqlData, error) {
data := graphqlData{}
path := fmt.Sprintf("%s/%s", handler.repourl.owner, handler.repourl.project)
params := map[string]interface{}{
"fullPath": path,
"fullPath": path,
"mergedBefore": before,
}
err := handler.graphClient.Query(context.Background(), &data, params)
if err != nil {
Expand Down
7 changes: 5 additions & 2 deletions clients/gitlabrepo/graphql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"os"
"testing"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -46,7 +47,8 @@ var _ = Describe("E2E TEST: gitlabrepo.graphqlHandler", func() {

path := fmt.Sprintf("%s/%s", graphqlhandler.repourl.owner, graphqlhandler.repourl.project)
params := map[string]interface{}{
"fullPath": path,
"fullPath": path,
"mergedBefore": time.Now(),
}
err = graphqlhandler.graphClient.Query(context.Background(), &data, params)
Expect(err).Should(BeNil())
Expand All @@ -65,7 +67,8 @@ var _ = Describe("E2E TEST: gitlabrepo.graphqlHandler", func() {

path := fmt.Sprintf("%s/%s", graphqlhandler.repourl.owner, graphqlhandler.repourl.project)
params := map[string]interface{}{
"fullPath": path,
"fullPath": path,
"mergedBefore": time.Now(),
}
err = graphqlhandler.graphClient.Query(context.Background(), &data, params)
Expect(err).Should(BeNil())
Expand Down

0 comments on commit 1e08b55

Please sign in to comment.