Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieMagee committed Dec 18, 2024
1 parent 7292b2a commit d5da1e2
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 13 deletions.
5 changes: 4 additions & 1 deletion clients/azuredevopsrepo/branches.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ func (b *branchesHandler) getBranch(branchName string) (*clients.BranchRef, erro
}

refName := fmt.Sprintf("refs/heads/%s", *branch.Name)
repositoryID := uuid.MustParse(b.repourl.id)
repositoryID, err := uuid.Parse(b.repourl.id)
if err != nil {
return nil, fmt.Errorf("error parsing repository ID %s: %w", b.repourl.id, err)
}
args := git.GetPolicyConfigurationsArgs{
RepositoryId: &repositoryID,
RefName: &refName,
Expand Down
7 changes: 2 additions & 5 deletions clients/azuredevopsrepo/builds.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package azuredevopsrepo

import (
"context"
"sync"

"github.com/microsoft/azure-devops-go-api/azuredevops/v7/build"

Expand All @@ -25,7 +24,6 @@ import (

type buildsHandler struct {
ctx context.Context
once *sync.Once
repourl *Repo
buildClient build.Client
getBuildDefinitions fnListBuildDefinitions
Expand All @@ -45,7 +43,6 @@ type (

func (b *buildsHandler) init(ctx context.Context, repourl *Repo) {
b.ctx = ctx
b.once = new(sync.Once)
b.repourl = repourl
b.getBuildDefinitions = b.buildClient.GetDefinitions
b.getBuilds = b.buildClient.GetBuilds
Expand Down Expand Up @@ -80,12 +77,11 @@ func (b *buildsHandler) listSuccessfulBuilds(filename string) ([]clients.Workflo
continuationToken = response.ContinuationToken
}

buildIds := make([]int, 0)
buildIds := make([]int, 0, len(buildDefinitions))
for i := range buildDefinitions {
buildIds = append(buildIds, *buildDefinitions[i].Id)
}

workflowRuns := make([]clients.WorkflowRun, 0)
args := build.GetBuildsArgs{
Project: &b.repourl.project,
Definitions: &buildIds,
Expand All @@ -96,6 +92,7 @@ func (b *buildsHandler) listSuccessfulBuilds(filename string) ([]clients.Workflo
return nil, err
}

workflowRuns := make([]clients.WorkflowRun, 0, len(builds.Value))
for i := range builds.Value {
currentBuild := builds.Value[i]
workflowRuns = append(workflowRuns, clients.WorkflowRun{
Expand Down
4 changes: 2 additions & 2 deletions clients/azuredevopsrepo/commits.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ type (
func (c *commitsHandler) setup() error {
c.once.Do(func() {
var itemVersion git.GitVersionDescriptor
if c.repourl.commitSHA == HeadCommit {
if c.repourl.commitSHA == headCommit {
itemVersion = git.GitVersionDescriptor{
VersionType: &git.GitVersionTypeValues.Branch,
Version: &c.repourl.defaultBranch,
Expand Down Expand Up @@ -232,7 +232,7 @@ func (c *commitsHandler) getFirstCommitCreatedAt() (time.Time, error) {
}

func (c *commitsHandler) listStatuses(ref string) ([]clients.Status, error) {
matched, err := regexp.MatchString("^[0-9a-f]{5,40}$", ref)
matched, err := regexp.MatchString("^[0-9a-fA-F]{40}$", ref)
if err != nil {
return nil, fmt.Errorf("error matching ref: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions clients/azuredevopsrepo/commits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func Test_listStatuses(t *testing.T) {
wantErr: false,
},
{
name: "head - no statuses",
name: "HEAD - no statuses",
ref: "main",
getRefs: func(ctx context.Context, args git.GetRefsArgs) (*git.GetRefsResponseValue, error) {
return &git.GetRefsResponseValue{
Expand All @@ -83,7 +83,7 @@ func Test_listStatuses(t *testing.T) {
wantErr: false,
},
{
name: "head - single status",
name: "HEAD - single status",
ref: "main",
getRefs: func(ctx context.Context, args git.GetRefsArgs) (*git.GetRefsResponseValue, error) {
return &git.GetRefsResponseValue{
Expand Down
2 changes: 1 addition & 1 deletion clients/azuredevopsrepo/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
package azuredevopsrepo

const (
HeadCommit = "HEAD"
headCommit = "HEAD"
)
2 changes: 1 addition & 1 deletion clients/azuredevopsrepo/search_commits.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (s *searchCommitsHandler) searchCommits(searchOptions clients.SearchCommits
skip := 0

var itemVersion git.GitVersionDescriptor
if s.repourl.commitSHA == HeadCommit {
if s.repourl.commitSHA == headCommit {
itemVersion = git.GitVersionDescriptor{
VersionType: &git.GitVersionTypeValues.Branch,
Version: &s.repourl.defaultBranch,
Expand Down
2 changes: 1 addition & 1 deletion clients/azuredevopsrepo/zip.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (z *zipHandler) getZipfile() error {
queryParams.Add("resolveLfs", "true")
queryParams.Add("$format", "zip")

if z.repourl.commitSHA == HeadCommit {
if z.repourl.commitSHA == headCommit {
queryParams.Add("versionDescriptor.versionType", "branch")
queryParams.Add("versionDescriptor.version", z.repourl.defaultBranch)
} else {
Expand Down

0 comments on commit d5da1e2

Please sign in to comment.