diff --git a/clients/azuredevopsrepo/branches.go b/clients/azuredevopsrepo/branches.go index b5b1be34265..900831b70cb 100644 --- a/clients/azuredevopsrepo/branches.go +++ b/clients/azuredevopsrepo/branches.go @@ -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, diff --git a/clients/azuredevopsrepo/builds.go b/clients/azuredevopsrepo/builds.go index 875301e67c5..17832c68ad2 100644 --- a/clients/azuredevopsrepo/builds.go +++ b/clients/azuredevopsrepo/builds.go @@ -16,7 +16,6 @@ package azuredevopsrepo import ( "context" - "sync" "github.com/microsoft/azure-devops-go-api/azuredevops/v7/build" @@ -25,7 +24,6 @@ import ( type buildsHandler struct { ctx context.Context - once *sync.Once repourl *Repo buildClient build.Client getBuildDefinitions fnListBuildDefinitions @@ -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 @@ -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, @@ -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{ diff --git a/clients/azuredevopsrepo/commits.go b/clients/azuredevopsrepo/commits.go index 844bbb11292..df741bf1a2a 100644 --- a/clients/azuredevopsrepo/commits.go +++ b/clients/azuredevopsrepo/commits.go @@ -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, @@ -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) } diff --git a/clients/azuredevopsrepo/commits_test.go b/clients/azuredevopsrepo/commits_test.go index 2257ac29c73..c70578e27d6 100644 --- a/clients/azuredevopsrepo/commits_test.go +++ b/clients/azuredevopsrepo/commits_test.go @@ -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{ @@ -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{ diff --git a/clients/azuredevopsrepo/const.go b/clients/azuredevopsrepo/const.go index 18306627256..13743aba0d4 100644 --- a/clients/azuredevopsrepo/const.go +++ b/clients/azuredevopsrepo/const.go @@ -15,5 +15,5 @@ package azuredevopsrepo const ( - HeadCommit = "HEAD" + headCommit = "HEAD" ) diff --git a/clients/azuredevopsrepo/search_commits.go b/clients/azuredevopsrepo/search_commits.go index 5974d8196f5..42f017567be 100644 --- a/clients/azuredevopsrepo/search_commits.go +++ b/clients/azuredevopsrepo/search_commits.go @@ -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, diff --git a/clients/azuredevopsrepo/zip.go b/clients/azuredevopsrepo/zip.go index b0238cecbe6..1476d4e14e6 100644 --- a/clients/azuredevopsrepo/zip.go +++ b/clients/azuredevopsrepo/zip.go @@ -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 {