-
Notifications
You must be signed in to change notification settings - Fork 510
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ implement more of the Azure DevOps client
Includes: - `GetBranch` - `GetSuccessfulWorkflowRuns` - `ListCheckRunsForRef` - `ListStatuses` - `ListWebhooks` - `SearchCommits` Also, includes comments about methods which can never be implemented: - `GetOrgRepoClient` - Org repository, AKA the `<org>/.github` repository, is a GitHub-specific feature - `ListLicenses` - Azure DevOps doesn't have a license detection feature. Thankfully, the License check falls back to file-based detection. Still need to implement: - `ListReleases` - Needs a little more investigation to line up the Azure DevOps implementation with what Scorecard expects Signed-off-by: Jamie Magee <[email protected]>
- Loading branch information
1 parent
2409124
commit 7292b2a
Showing
22 changed files
with
1,587 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// Copyright 2024 OpenSSF Scorecard Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package azuredevopsrepo | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
|
||
"github.com/microsoft/azure-devops-go-api/azuredevops/v7/build" | ||
|
||
"github.com/ossf/scorecard/v5/clients" | ||
) | ||
|
||
type buildsHandler struct { | ||
ctx context.Context | ||
once *sync.Once | ||
repourl *Repo | ||
buildClient build.Client | ||
getBuildDefinitions fnListBuildDefinitions | ||
getBuilds fnGetBuilds | ||
} | ||
|
||
type ( | ||
fnListBuildDefinitions func( | ||
ctx context.Context, | ||
args build.GetDefinitionsArgs, | ||
) (*build.GetDefinitionsResponseValue, error) | ||
fnGetBuilds func( | ||
ctx context.Context, | ||
args build.GetBuildsArgs, | ||
) (*build.GetBuildsResponseValue, error) | ||
) | ||
|
||
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 | ||
} | ||
|
||
func (b *buildsHandler) listSuccessfulBuilds(filename string) ([]clients.WorkflowRun, error) { | ||
buildDefinitions := make([]build.BuildDefinitionReference, 0) | ||
|
||
includeAllProperties := true | ||
repositoryType := "TfsGit" | ||
continuationToken := "" | ||
for { | ||
args := build.GetDefinitionsArgs{ | ||
Project: &b.repourl.project, | ||
RepositoryId: &b.repourl.id, | ||
RepositoryType: &repositoryType, | ||
IncludeAllProperties: &includeAllProperties, | ||
YamlFilename: &filename, | ||
ContinuationToken: &continuationToken, | ||
} | ||
|
||
response, err := b.getBuildDefinitions(b.ctx, args) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
buildDefinitions = append(buildDefinitions, response.Value...) | ||
|
||
if response.ContinuationToken == "" { | ||
break | ||
} | ||
continuationToken = response.ContinuationToken | ||
} | ||
|
||
buildIds := make([]int, 0) | ||
for i := range buildDefinitions { | ||
buildIds = append(buildIds, *buildDefinitions[i].Id) | ||
} | ||
|
||
workflowRuns := make([]clients.WorkflowRun, 0) | ||
args := build.GetBuildsArgs{ | ||
Project: &b.repourl.project, | ||
Definitions: &buildIds, | ||
ResultFilter: &build.BuildResultValues.Succeeded, | ||
} | ||
builds, err := b.getBuilds(b.ctx, args) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for i := range builds.Value { | ||
currentBuild := builds.Value[i] | ||
workflowRuns = append(workflowRuns, clients.WorkflowRun{ | ||
URL: *currentBuild.Url, | ||
HeadSHA: currentBuild.SourceVersion, | ||
}) | ||
} | ||
|
||
return workflowRuns, nil | ||
} |
Oops, something went wrong.