diff --git a/go.mod b/go.mod index c1f19c2df2..8f79be520e 100644 --- a/go.mod +++ b/go.mod @@ -32,7 +32,7 @@ require ( github.com/imdario/mergo v0.3.5 // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/magiconair/properties v1.7.3 // indirect - github.com/mcdafydd/go-azuredevops v0.11.0 + github.com/mcdafydd/go-azuredevops v0.11.1 github.com/microcosm-cc/bluemonday v1.0.1 github.com/mitchellh/colorstring v0.0.0-20150917214807-8631ce90f286 github.com/mitchellh/go-homedir v1.0.0 diff --git a/go.sum b/go.sum index e3fc2748ee..d84f77c0f4 100644 --- a/go.sum +++ b/go.sum @@ -203,6 +203,8 @@ github.com/mcdafydd/go-azuredevops v0.10.2 h1:cVAxfGqSUK7i4ZRc7s+EpeWSOrDgkBM4Sz github.com/mcdafydd/go-azuredevops v0.10.2/go.mod h1:/NYbgJ/1+9+SmG5CjETCoWm+FlLNcRwdiw1/AGW9zm0= github.com/mcdafydd/go-azuredevops v0.11.0 h1:DHUctw4lNpPfExpwAxDsdat+n4IitH3vYLAxSGs9y0E= github.com/mcdafydd/go-azuredevops v0.11.0/go.mod h1:B4UDyn7WEj1/97f45j3VnzEfkWKe05+/dCcAPdOET4A= +github.com/mcdafydd/go-azuredevops v0.11.1 h1:NO4wlkyFpdxqZZzNzn5m3fJc4box0jnkC8LBhAaPXeA= +github.com/mcdafydd/go-azuredevops v0.11.1/go.mod h1:B4UDyn7WEj1/97f45j3VnzEfkWKe05+/dCcAPdOET4A= github.com/microcosm-cc/bluemonday v1.0.1 h1:SIYunPjnlXcW+gVfvm0IlSeR5U3WZUOLfVmqg85Go44= github.com/microcosm-cc/bluemonday v1.0.1/go.mod h1:hsXNsILzKxV+sX77C5b8FSuKF00vh2OMYv+xgHpAMF4= github.com/mitchellh/colorstring v0.0.0-20150917214807-8631ce90f286 h1:KHyL+3mQOF9sPfs26lsefckcFNDcIZtiACQiECzIUkw= diff --git a/server/events/vcs/azuredevops_client.go b/server/events/vcs/azuredevops_client.go index 5613518f91..c60f6029c4 100644 --- a/server/events/vcs/azuredevops_client.go +++ b/server/events/vcs/azuredevops_client.go @@ -6,7 +6,6 @@ import ( "net/http" "net/url" "path/filepath" - "strconv" "strings" "time" @@ -177,7 +176,7 @@ func (g *AzureDevopsClient) PullIsMergeable(repo models.Repo, pull models.PullRe } projectID := *adPull.Repository.Project.ID - artifactID := g.Client.PolicyEvaluations.GetPullRequestArtifactID(projectID, strconv.Itoa(pull.Num)) + artifactID := g.Client.PolicyEvaluations.GetPullRequestArtifactID(projectID, pull.Num) policyEvaluations, _, err := g.Client.PolicyEvaluations.List(g.ctx, owner, project, artifactID, &azuredevops.PolicyEvaluationsListOptions{}) if err != nil { return false, fmt.Errorf("list policy evaluations: %w", err) @@ -195,7 +194,7 @@ func (g *AzureDevopsClient) PullIsMergeable(repo models.Repo, pull models.PullRe continue } - if *policyEvaluation.Configuration.IsBlocking && *policyEvaluation.Status != "approved" { + if *policyEvaluation.Configuration.IsBlocking && *policyEvaluation.Status != azuredevops.PolicyEvaluationApproved { return false, nil } } diff --git a/vendor/github.com/mcdafydd/go-azuredevops/azuredevops/policy_evaluations.go b/vendor/github.com/mcdafydd/go-azuredevops/azuredevops/policy_evaluations.go index e2c54cca20..34f12cc5ed 100644 --- a/vendor/github.com/mcdafydd/go-azuredevops/azuredevops/policy_evaluations.go +++ b/vendor/github.com/mcdafydd/go-azuredevops/azuredevops/policy_evaluations.go @@ -55,10 +55,30 @@ type PolicyTypeRef struct { Url *string `json:"url,omitempty"` } +const ( + // PolicyEvaluationApproved represents that the policy has been fulfilled for this pull request. + PolicyEvaluationApproved = "approved" + + // PolicyEvaluationBroken represents that the policy encountered an unexpected error. + PolicyEvaluationBroken = "broken" + + // PolicyEvaluationNotApplicable represents that the policy does not apply to this pull request. + PolicyEvaluationNotApplicable = "notApplicable" + + // PolicyEvaluationQueued represents that the policy is either queued to run, or is waiting for some event before progressing. + PolicyEvaluationQueued = "queued" + + // PolicyEvaluationRejected represents that the policy has rejected this pull request. + PolicyEvaluationRejected = "rejected" + + // PolicyEvaluationRunning represents that the policy is currently running. + PolicyEvaluationRunning = "running" +) + // GetPullRequestArtifactID gets the Artifact ID of a pull request. // ex: vstfs:///CodeReview/CodeReviewId/{projectId}/{pullRequestId} -func (s *PolicyEvaluationsService) GetPullRequestArtifactID(projectID string, pullRequestID string) string { - return fmt.Sprintf("vstfs:///CodeReview/CodeReviewId/%s/%s", projectID, pullRequestID) +func (s *PolicyEvaluationsService) GetPullRequestArtifactID(projectID string, pullRequestID int) string { + return fmt.Sprintf("vstfs:///CodeReview/CodeReviewId/%s/%d", projectID, pullRequestID) } // List retrieves a list of all the policy evaluation statuses for a specific pull request. diff --git a/vendor/github.com/petergtz/pegomock/.gitignore b/vendor/github.com/petergtz/pegomock/.gitignore index a8b83fdd09..153ff9570f 100644 --- a/vendor/github.com/petergtz/pegomock/.gitignore +++ b/vendor/github.com/petergtz/pegomock/.gitignore @@ -1,5 +1,4 @@ mock_display_test.go -matchers debug.test .vscode *.coverprofile diff --git a/vendor/github.com/petergtz/pegomock/README.md b/vendor/github.com/petergtz/pegomock/README.md index bc2566f38e..56e30dcb04 100644 --- a/vendor/github.com/petergtz/pegomock/README.md +++ b/vendor/github.com/petergtz/pegomock/README.md @@ -13,6 +13,8 @@ go get github.com/petergtz/pegomock/... This will download the package and install an executable `pegomock` in your `$GOPATH/bin`. +See also section[Tracking the pegomock tool in your project](#tracking-the-pegomock-tool-in-your-project) for a per-project control of the tool version. + Getting Started =============== @@ -403,6 +405,46 @@ Install it via: go install github.com/petergtz/pegomock/pegomock ``` +Tracking the pegomock tool in your project +------------------------------------------ + +Go modules allow to pin not only a package but also a tool (that is, an executable). The steps are: + +1. Use a file named `tools.go` with contents similar to this: +```go +// +build tools + +// This file will never be compiled (see the build constraint above); it is +// used to record dependencies on build tools with the Go modules machinery. +// See https://github.com/go-modules-by-example/index/blob/master/010_tools/README.md + +package tools + +import ( + _ "github.com/petergtz/pegomock/pegomock" +) +``` +2. Set `$GOBIN` to a `bin` directory relative to your repo (this defines where tool dependencies will be installed). +2. Install the tool with `go install`: +```console +$ cd /path/to/myproject +$ export GOBIN=$PWD/bin +$ go install github.com/petergtz/pegomock/pegomock +``` +3. Use that `$GOBIN` when invoking `pegomock` for that project: +```console +$ $GOBIN/pegomock ... +``` +or +```console +$ export PATH=$GOBIN:$PATH +$ pegomock ... +``` + +See [Tools as dependencies] for details. + +[Tools as dependencies]: https://github.com/go-modules-by-example/index/blob/master/010_tools/README.md + Generating Mocks ---------------- diff --git a/vendor/modules.txt b/vendor/modules.txt index 21cbc82f64..65d0ed9c07 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -149,7 +149,7 @@ github.com/magiconair/properties github.com/mattn/go-colorable # github.com/mattn/go-isatty v0.0.4 github.com/mattn/go-isatty -# github.com/mcdafydd/go-azuredevops v0.11.0 +# github.com/mcdafydd/go-azuredevops v0.11.1 github.com/mcdafydd/go-azuredevops/azuredevops # github.com/microcosm-cc/bluemonday v1.0.1 github.com/microcosm-cc/bluemonday