Skip to content

Commit

Permalink
fix: set default branch from api to compare with instead of hardcoded…
Browse files Browse the repository at this point in the history
… string (#136)

* ci: added codecov config to ignore generated graphql files

---------

Signed-off-by: Ryan Hoofard <[email protected]>
Co-authored-by: rhoofard <[email protected]>
  • Loading branch information
rhoofard and rhoofard authored Oct 3, 2023
1 parent 8829315 commit c51a790
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ignore:
- "**/generated*.go"

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ query getBranchNames($fullPath: ID!) {
# repo with just over 100,000 branches which is an extreme edge case which we believe is not
# worth supporting.
branchNames(searchPattern: "*", offset: 0, limit: 100000)
rootRef
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ type gitlabProject struct {
}

type projectData struct {
ProjectPath string
Branches []string
ProjectPath string
DefaultBranch string
Branches []string
}

// Returns a struct with the project path and an array of branch names via the given channel.
Expand All @@ -84,7 +85,7 @@ func (gls *gitlabScraper) getBranches(
return
}

ch <- projectData{ProjectPath: projectPath, Branches: branches.Project.Repository.BranchNames}
ch <- projectData{ProjectPath: projectPath, DefaultBranch: branches.Project.Repository.RootRef, Branches: branches.Project.Repository.BranchNames}
}

func (gls *gitlabScraper) getMergeRequests(
Expand Down Expand Up @@ -219,11 +220,11 @@ func (gls *gitlabScraper) scrape(ctx context.Context) (pmetric.Metrics, error) {
gls.logger.Sugar().Debugf("%s branch count: %v", proj.ProjectPath, int64(len(proj.Branches)))

for _, branch := range proj.Branches {
if branch == "main" {
if branch == proj.DefaultBranch {
continue
}

diff, _, err := restClient.Repositories.Compare(proj.ProjectPath, &gitlab.CompareOptions{From: gitlab.String("main"), To: gitlab.String(branch)})
diff, _, err := restClient.Repositories.Compare(proj.ProjectPath, &gitlab.CompareOptions{From: &proj.DefaultBranch, To: gitlab.String(branch)})
if err != nil {
gls.logger.Sugar().Errorf("error: %v", err)
}
Expand Down

0 comments on commit c51a790

Please sign in to comment.