diff --git a/Dockerfile b/Dockerfile index fc00995a..ff124c4c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,10 @@ -FROM golang:1.14 as builder +FROM golang:1.26.4 AS builder ADD . /go/src/github.com/telia-oss/github-pr-resource WORKDIR /go/src/github.com/telia-oss/github-pr-resource RUN curl -sL https://taskfile.dev/install.sh | sh RUN ./bin/task build -FROM alpine:3.11 as resource +FROM alpine:3.24 AS resource COPY --from=builder /go/src/github.com/telia-oss/github-pr-resource/build /opt/resource RUN apk add --update --no-cache \ git \ diff --git a/README.md b/README.md index d46077ff..e8e8a9ec 100644 --- a/README.md +++ b/README.md @@ -121,6 +121,7 @@ empty commit to the PR*. | `context` | No | `unit-test` | A context to use for the status, which is prefixed by `base_context`. Defaults to `status`. | | `comment` | No | `hello world!` | A comment to add to the pull request. | | `comment_file` | No | `my-output/comment.txt` | Path to file containing a comment to add to the pull request (e.g. output of `terraform plan`). | +| `label` | No | `ready-to-merge` | A label to add to the pull request. | | `target_url` | No | `$ATC_EXTERNAL_URL/builds/$BUILD_ID` | The target URL for the status, where users are sent when clicking details (defaults to the Concourse build page). | | `description` | No | `Concourse CI build failed` | The description status on the specified pull request. | | `description_file` | No | `my-output/description.txt` | Path to file containing the description status to add to the pull request | @@ -197,7 +198,7 @@ Ref the above, here are some examples of running `check` against large repositor For the other two operations the costing is a bit easier: - `get`: Fixed cost of 1. Fetches the pull request at the given commit. -- `put`: Uses the V3 API and has a min cost of 1, +1 for each of `status`, `comment` and `comment_file` etc. +- `put`: Uses the V3 API and has a min cost of 1, +1 for each of `status`, `comment`, `comment_file`, `label` etc. ## Migrating @@ -241,7 +242,6 @@ If you are coming from [jtarchie/github-pullrequest-resource][original-resource] - `git.*` (with the exception of `git_depth`, see above) - `put`: - `merge.*` - - `label` Note that if you are migrating from the original resource on a Concourse version prior to `v5.0.0`, you might see an error `failed to unmarshal request: json: unknown field "ref"`. The solution is to rename the resource diff --git a/Taskfile.yml b/Taskfile.yml index f01ebc28..4090183e 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -1,4 +1,4 @@ -version: '2' +version: '3' vars: BUILD_DIR: build @@ -6,8 +6,10 @@ vars: tasks: default: + desc: List available tasks + silent: true cmds: - - task: test + - task --list-all generate: desc: Generate test fakes @@ -51,6 +53,7 @@ tasks: vars: {BINARY: out} go-build: + desc: Build one resource binary. Requires BINARY. cmds: - go build -o {{.BUILD_DIR}}/{{.BINARY}}{{exeExt}} -ldflags="-s -w" -v cmd/{{.BINARY}}/main.go env: diff --git a/e2e/e2e_test.go b/e2e/e2e_test.go index 523838c2..660410a2 100644 --- a/e2e/e2e_test.go +++ b/e2e/e2e_test.go @@ -1,3 +1,4 @@ +//go:build e2e // +build e2e package e2e_test diff --git a/fakes/fake_git.go b/fakes/fake_git.go index 2a395475..817b6461 100644 --- a/fakes/fake_git.go +++ b/fakes/fake_git.go @@ -122,15 +122,16 @@ func (fake *FakeGit) Checkout(arg1 string, arg2 string, arg3 bool) error { arg2 string arg3 bool }{arg1, arg2, arg3}) + stub := fake.CheckoutStub + fakeReturns := fake.checkoutReturns fake.recordInvocation("Checkout", []interface{}{arg1, arg2, arg3}) fake.checkoutMutex.Unlock() - if fake.CheckoutStub != nil { - return fake.CheckoutStub(arg1, arg2, arg3) + if stub != nil { + return stub(arg1, arg2, arg3) } if specificReturn { return ret.result1 } - fakeReturns := fake.checkoutReturns return fakeReturns.result1 } @@ -185,15 +186,16 @@ func (fake *FakeGit) Fetch(arg1 string, arg2 int, arg3 int, arg4 bool) error { arg3 int arg4 bool }{arg1, arg2, arg3, arg4}) + stub := fake.FetchStub + fakeReturns := fake.fetchReturns fake.recordInvocation("Fetch", []interface{}{arg1, arg2, arg3, arg4}) fake.fetchMutex.Unlock() - if fake.FetchStub != nil { - return fake.FetchStub(arg1, arg2, arg3, arg4) + if stub != nil { + return stub(arg1, arg2, arg3, arg4) } if specificReturn { return ret.result1 } - fakeReturns := fake.fetchReturns return fakeReturns.result1 } @@ -245,15 +247,16 @@ func (fake *FakeGit) GitCryptUnlock(arg1 string) error { fake.gitCryptUnlockArgsForCall = append(fake.gitCryptUnlockArgsForCall, struct { arg1 string }{arg1}) + stub := fake.GitCryptUnlockStub + fakeReturns := fake.gitCryptUnlockReturns fake.recordInvocation("GitCryptUnlock", []interface{}{arg1}) fake.gitCryptUnlockMutex.Unlock() - if fake.GitCryptUnlockStub != nil { - return fake.GitCryptUnlockStub(arg1) + if stub != nil { + return stub(arg1) } if specificReturn { return ret.result1 } - fakeReturns := fake.gitCryptUnlockReturns return fakeReturns.result1 } @@ -305,15 +308,16 @@ func (fake *FakeGit) Init(arg1 string) error { fake.initArgsForCall = append(fake.initArgsForCall, struct { arg1 string }{arg1}) + stub := fake.InitStub + fakeReturns := fake.initReturns fake.recordInvocation("Init", []interface{}{arg1}) fake.initMutex.Unlock() - if fake.InitStub != nil { - return fake.InitStub(arg1) + if stub != nil { + return stub(arg1) } if specificReturn { return ret.result1 } - fakeReturns := fake.initReturns return fakeReturns.result1 } @@ -366,15 +370,16 @@ func (fake *FakeGit) Merge(arg1 string, arg2 bool) error { arg1 string arg2 bool }{arg1, arg2}) + stub := fake.MergeStub + fakeReturns := fake.mergeReturns fake.recordInvocation("Merge", []interface{}{arg1, arg2}) fake.mergeMutex.Unlock() - if fake.MergeStub != nil { - return fake.MergeStub(arg1, arg2) + if stub != nil { + return stub(arg1, arg2) } if specificReturn { return ret.result1 } - fakeReturns := fake.mergeReturns return fakeReturns.result1 } @@ -430,15 +435,16 @@ func (fake *FakeGit) Pull(arg1 string, arg2 string, arg3 int, arg4 bool, arg5 bo arg4 bool arg5 bool }{arg1, arg2, arg3, arg4, arg5}) + stub := fake.PullStub + fakeReturns := fake.pullReturns fake.recordInvocation("Pull", []interface{}{arg1, arg2, arg3, arg4, arg5}) fake.pullMutex.Unlock() - if fake.PullStub != nil { - return fake.PullStub(arg1, arg2, arg3, arg4, arg5) + if stub != nil { + return stub(arg1, arg2, arg3, arg4, arg5) } if specificReturn { return ret.result1 } - fakeReturns := fake.pullReturns return fakeReturns.result1 } @@ -492,15 +498,16 @@ func (fake *FakeGit) Rebase(arg1 string, arg2 string, arg3 bool) error { arg2 string arg3 bool }{arg1, arg2, arg3}) + stub := fake.RebaseStub + fakeReturns := fake.rebaseReturns fake.recordInvocation("Rebase", []interface{}{arg1, arg2, arg3}) fake.rebaseMutex.Unlock() - if fake.RebaseStub != nil { - return fake.RebaseStub(arg1, arg2, arg3) + if stub != nil { + return stub(arg1, arg2, arg3) } if specificReturn { return ret.result1 } - fakeReturns := fake.rebaseReturns return fakeReturns.result1 } @@ -552,15 +559,16 @@ func (fake *FakeGit) RevParse(arg1 string) (string, error) { fake.revParseArgsForCall = append(fake.revParseArgsForCall, struct { arg1 string }{arg1}) + stub := fake.RevParseStub + fakeReturns := fake.revParseReturns fake.recordInvocation("RevParse", []interface{}{arg1}) fake.revParseMutex.Unlock() - if fake.RevParseStub != nil { - return fake.RevParseStub(arg1) + if stub != nil { + return stub(arg1) } if specificReturn { return ret.result1, ret.result2 } - fakeReturns := fake.revParseReturns return fakeReturns.result1, fakeReturns.result2 } @@ -612,22 +620,6 @@ func (fake *FakeGit) RevParseReturnsOnCall(i int, result1 string, result2 error) func (fake *FakeGit) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() - fake.checkoutMutex.RLock() - defer fake.checkoutMutex.RUnlock() - fake.fetchMutex.RLock() - defer fake.fetchMutex.RUnlock() - fake.gitCryptUnlockMutex.RLock() - defer fake.gitCryptUnlockMutex.RUnlock() - fake.initMutex.RLock() - defer fake.initMutex.RUnlock() - fake.mergeMutex.RLock() - defer fake.mergeMutex.RUnlock() - fake.pullMutex.RLock() - defer fake.pullMutex.RUnlock() - fake.rebaseMutex.RLock() - defer fake.rebaseMutex.RUnlock() - fake.revParseMutex.RLock() - defer fake.revParseMutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value diff --git a/fakes/fake_github.go b/fakes/fake_github.go index 1847478f..c4fd153b 100644 --- a/fakes/fake_github.go +++ b/fakes/fake_github.go @@ -9,6 +9,18 @@ import ( ) type FakeGithub struct { + AddLabelStub func(string, string) error + addLabelMutex sync.RWMutex + addLabelArgsForCall []struct { + arg1 string + arg2 string + } + addLabelReturns struct { + result1 error + } + addLabelReturnsOnCall map[int]struct { + result1 error + } DeletePreviousCommentsStub func(string) error deletePreviousCommentsMutex sync.RWMutex deletePreviousCommentsArgsForCall []struct { @@ -106,21 +118,84 @@ type FakeGithub struct { invocationsMutex sync.RWMutex } +func (fake *FakeGithub) AddLabel(arg1 string, arg2 string) error { + fake.addLabelMutex.Lock() + ret, specificReturn := fake.addLabelReturnsOnCall[len(fake.addLabelArgsForCall)] + fake.addLabelArgsForCall = append(fake.addLabelArgsForCall, struct { + arg1 string + arg2 string + }{arg1, arg2}) + stub := fake.AddLabelStub + fakeReturns := fake.addLabelReturns + fake.recordInvocation("AddLabel", []interface{}{arg1, arg2}) + fake.addLabelMutex.Unlock() + if stub != nil { + return stub(arg1, arg2) + } + if specificReturn { + return ret.result1 + } + return fakeReturns.result1 +} + +func (fake *FakeGithub) AddLabelCallCount() int { + fake.addLabelMutex.RLock() + defer fake.addLabelMutex.RUnlock() + return len(fake.addLabelArgsForCall) +} + +func (fake *FakeGithub) AddLabelCalls(stub func(string, string) error) { + fake.addLabelMutex.Lock() + defer fake.addLabelMutex.Unlock() + fake.AddLabelStub = stub +} + +func (fake *FakeGithub) AddLabelArgsForCall(i int) (string, string) { + fake.addLabelMutex.RLock() + defer fake.addLabelMutex.RUnlock() + argsForCall := fake.addLabelArgsForCall[i] + return argsForCall.arg1, argsForCall.arg2 +} + +func (fake *FakeGithub) AddLabelReturns(result1 error) { + fake.addLabelMutex.Lock() + defer fake.addLabelMutex.Unlock() + fake.AddLabelStub = nil + fake.addLabelReturns = struct { + result1 error + }{result1} +} + +func (fake *FakeGithub) AddLabelReturnsOnCall(i int, result1 error) { + fake.addLabelMutex.Lock() + defer fake.addLabelMutex.Unlock() + fake.AddLabelStub = nil + if fake.addLabelReturnsOnCall == nil { + fake.addLabelReturnsOnCall = make(map[int]struct { + result1 error + }) + } + fake.addLabelReturnsOnCall[i] = struct { + result1 error + }{result1} +} + func (fake *FakeGithub) DeletePreviousComments(arg1 string) error { fake.deletePreviousCommentsMutex.Lock() ret, specificReturn := fake.deletePreviousCommentsReturnsOnCall[len(fake.deletePreviousCommentsArgsForCall)] fake.deletePreviousCommentsArgsForCall = append(fake.deletePreviousCommentsArgsForCall, struct { arg1 string }{arg1}) + stub := fake.DeletePreviousCommentsStub + fakeReturns := fake.deletePreviousCommentsReturns fake.recordInvocation("DeletePreviousComments", []interface{}{arg1}) fake.deletePreviousCommentsMutex.Unlock() - if fake.DeletePreviousCommentsStub != nil { - return fake.DeletePreviousCommentsStub(arg1) + if stub != nil { + return stub(arg1) } if specificReturn { return ret.result1 } - fakeReturns := fake.deletePreviousCommentsReturns return fakeReturns.result1 } @@ -173,15 +248,16 @@ func (fake *FakeGithub) GetChangedFiles(arg1 string, arg2 string) ([]resource.Ch arg1 string arg2 string }{arg1, arg2}) + stub := fake.GetChangedFilesStub + fakeReturns := fake.getChangedFilesReturns fake.recordInvocation("GetChangedFiles", []interface{}{arg1, arg2}) fake.getChangedFilesMutex.Unlock() - if fake.GetChangedFilesStub != nil { - return fake.GetChangedFilesStub(arg1, arg2) + if stub != nil { + return stub(arg1, arg2) } if specificReturn { return ret.result1, ret.result2 } - fakeReturns := fake.getChangedFilesReturns return fakeReturns.result1, fakeReturns.result2 } @@ -237,15 +313,16 @@ func (fake *FakeGithub) GetPullRequest(arg1 string, arg2 string) (*resource.Pull arg1 string arg2 string }{arg1, arg2}) + stub := fake.GetPullRequestStub + fakeReturns := fake.getPullRequestReturns fake.recordInvocation("GetPullRequest", []interface{}{arg1, arg2}) fake.getPullRequestMutex.Unlock() - if fake.GetPullRequestStub != nil { - return fake.GetPullRequestStub(arg1, arg2) + if stub != nil { + return stub(arg1, arg2) } if specificReturn { return ret.result1, ret.result2 } - fakeReturns := fake.getPullRequestReturns return fakeReturns.result1, fakeReturns.result2 } @@ -300,15 +377,16 @@ func (fake *FakeGithub) ListModifiedFiles(arg1 int) ([]string, error) { fake.listModifiedFilesArgsForCall = append(fake.listModifiedFilesArgsForCall, struct { arg1 int }{arg1}) + stub := fake.ListModifiedFilesStub + fakeReturns := fake.listModifiedFilesReturns fake.recordInvocation("ListModifiedFiles", []interface{}{arg1}) fake.listModifiedFilesMutex.Unlock() - if fake.ListModifiedFilesStub != nil { - return fake.ListModifiedFilesStub(arg1) + if stub != nil { + return stub(arg1) } if specificReturn { return ret.result1, ret.result2 } - fakeReturns := fake.listModifiedFilesReturns return fakeReturns.result1, fakeReturns.result2 } @@ -368,15 +446,16 @@ func (fake *FakeGithub) ListPullRequests(arg1 []githubv4.PullRequestState) ([]*r fake.listPullRequestsArgsForCall = append(fake.listPullRequestsArgsForCall, struct { arg1 []githubv4.PullRequestState }{arg1Copy}) + stub := fake.ListPullRequestsStub + fakeReturns := fake.listPullRequestsReturns fake.recordInvocation("ListPullRequests", []interface{}{arg1Copy}) fake.listPullRequestsMutex.Unlock() - if fake.ListPullRequestsStub != nil { - return fake.ListPullRequestsStub(arg1) + if stub != nil { + return stub(arg1) } if specificReturn { return ret.result1, ret.result2 } - fakeReturns := fake.listPullRequestsReturns return fakeReturns.result1, fakeReturns.result2 } @@ -432,15 +511,16 @@ func (fake *FakeGithub) PostComment(arg1 string, arg2 string) error { arg1 string arg2 string }{arg1, arg2}) + stub := fake.PostCommentStub + fakeReturns := fake.postCommentReturns fake.recordInvocation("PostComment", []interface{}{arg1, arg2}) fake.postCommentMutex.Unlock() - if fake.PostCommentStub != nil { - return fake.PostCommentStub(arg1, arg2) + if stub != nil { + return stub(arg1, arg2) } if specificReturn { return ret.result1 } - fakeReturns := fake.postCommentReturns return fakeReturns.result1 } @@ -497,15 +577,16 @@ func (fake *FakeGithub) UpdateCommitStatus(arg1 string, arg2 string, arg3 string arg5 string arg6 string }{arg1, arg2, arg3, arg4, arg5, arg6}) + stub := fake.UpdateCommitStatusStub + fakeReturns := fake.updateCommitStatusReturns fake.recordInvocation("UpdateCommitStatus", []interface{}{arg1, arg2, arg3, arg4, arg5, arg6}) fake.updateCommitStatusMutex.Unlock() - if fake.UpdateCommitStatusStub != nil { - return fake.UpdateCommitStatusStub(arg1, arg2, arg3, arg4, arg5, arg6) + if stub != nil { + return stub(arg1, arg2, arg3, arg4, arg5, arg6) } if specificReturn { return ret.result1 } - fakeReturns := fake.updateCommitStatusReturns return fakeReturns.result1 } @@ -554,20 +635,6 @@ func (fake *FakeGithub) UpdateCommitStatusReturnsOnCall(i int, result1 error) { func (fake *FakeGithub) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() - fake.deletePreviousCommentsMutex.RLock() - defer fake.deletePreviousCommentsMutex.RUnlock() - fake.getChangedFilesMutex.RLock() - defer fake.getChangedFilesMutex.RUnlock() - fake.getPullRequestMutex.RLock() - defer fake.getPullRequestMutex.RUnlock() - fake.listModifiedFilesMutex.RLock() - defer fake.listModifiedFilesMutex.RUnlock() - fake.listPullRequestsMutex.RLock() - defer fake.listPullRequestsMutex.RUnlock() - fake.postCommentMutex.RLock() - defer fake.postCommentMutex.RUnlock() - fake.updateCommitStatusMutex.RLock() - defer fake.updateCommitStatusMutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value diff --git a/git.go b/git.go index 53f339d4..4068159d 100644 --- a/git.go +++ b/git.go @@ -14,6 +14,7 @@ import ( ) // Git interface for testing purposes. +// //go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -o fakes/fake_git.go . Git type Git interface { Init(string) error diff --git a/github.go b/github.go index ab10cbdc..6cfb0720 100644 --- a/github.go +++ b/github.go @@ -18,6 +18,7 @@ import ( ) // Github for testing purposes. +// //go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -o fakes/fake_github.go . Github type Github interface { ListPullRequests([]githubv4.PullRequestState) ([]*PullRequest, error) @@ -27,6 +28,7 @@ type Github interface { GetChangedFiles(string, string) ([]ChangedFileObject, error) UpdateCommitStatus(string, string, string, string, string, string) error DeletePreviousComments(string) error + AddLabel(string, string) error } // GithubClient for handling requests to the Github V3 and V4 APIs. @@ -219,6 +221,23 @@ func (m *GithubClient) PostComment(prNumber, comment string) error { return err } +// AddLabel to a pull request or issue. +func (m *GithubClient) AddLabel(prNumber, label string) error { + pr, err := strconv.Atoi(prNumber) + if err != nil { + return fmt.Errorf("failed to convert pull request number to int: %s", err) + } + + _, _, err = m.V3.Issues.AddLabelsToIssue( + context.TODO(), + m.Owner, + m.Repository, + pr, + []string{label}, + ) + return err +} + // GetChangedFiles ... func (m *GithubClient) GetChangedFiles(prNumber string, commitRef string) ([]ChangedFileObject, error) { pr, err := strconv.Atoi(prNumber) diff --git a/go.mod b/go.mod index ef1f5ca4..517beea9 100644 --- a/go.mod +++ b/go.mod @@ -1,17 +1,27 @@ module github.com/telia-oss/github-pr-resource require ( - github.com/golang/protobuf v1.4.0 // indirect github.com/google/go-github/v28 v28.1.1 - github.com/maxbrunsfeld/counterfeiter/v6 v6.2.3 + github.com/maxbrunsfeld/counterfeiter/v6 v6.12.2 github.com/shurcooL/githubv4 v0.0.0-20200414012201-bbc966b061dd - github.com/shurcooL/graphql v0.0.0-20181231061246-d48a9a75455f // indirect github.com/stretchr/testify v1.3.0 - golang.org/x/crypto v0.0.0-20200423211502-4bdfaf469ed5 // indirect - golang.org/x/net v0.0.0-20200421231249-e086a090c8fd // indirect golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d - golang.org/x/tools v0.0.0-20200423205358-59e73619c742 // indirect +) + +require ( + github.com/davecgh/go-spew v1.1.0 // indirect + github.com/golang/protobuf v1.4.0 // indirect + github.com/google/go-querystring v1.0.0 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/shurcooL/graphql v0.0.0-20181231061246-d48a9a75455f // indirect + golang.org/x/crypto v0.49.0 // indirect + golang.org/x/mod v0.34.0 // indirect + golang.org/x/net v0.52.0 // indirect + golang.org/x/sync v0.20.0 // indirect + golang.org/x/text v0.35.0 // indirect + golang.org/x/tools v0.43.0 // indirect google.golang.org/appengine v1.6.6 // indirect + google.golang.org/protobuf v1.21.0 // indirect ) -go 1.14 +go 1.26 diff --git a/go.sum b/go.sum index 82ec24e7..76b55742 100644 --- a/go.sum +++ b/go.sum @@ -1,9 +1,6 @@ cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= -github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= @@ -14,33 +11,19 @@ github.com/golang/protobuf v1.4.0 h1:oOuy+ugB+P/kBdUnG5QaMXSIyJ1q38wWSojYCb3z5VQ github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= +github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/go-github/v28 v28.1.1 h1:kORf5ekX5qwXO2mGzXXOjMe/g6ap8ahVe0sBEulhSxo= github.com/google/go-github/v28 v28.1.1/go.mod h1:bsqJWQX05omyWVmc00nEUql9mhQyv38lDZ8kPZcQVoM= github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= -github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= -github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= -github.com/joefitzgerald/rainbow-reporter v0.1.0 h1:AuMG652zjdzI0YCCnXAqATtRBpGXMcAnrajcaTrSeuo= -github.com/joefitzgerald/rainbow-reporter v0.1.0/go.mod h1:481CNgqmVHQZzdIbN52CupLJyoVwB10FQ/IQlF1pdL8= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/maxbrunsfeld/counterfeiter/v6 v6.2.3 h1:z1lXirM9f9WTcdmzSZahKh/t+LCqPiiwK2/DB1kLlI4= -github.com/maxbrunsfeld/counterfeiter/v6 v6.2.3/go.mod h1:1ftk08SazyElaaNvmqAfZWGwJzshjCfBXDLoQtPAMNk= -github.com/onsi/ginkgo v1.6.0 h1:Ix8l273rp3QzYgXSR+c8d1fTG7UPgYkOSELPhiY/YGw= -github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.8.0 h1:VkHVNpR4iVnU8XQR6DBm8BqYjN7CRzw+xKUbVVbbW9w= -github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/gomega v1.9.0 h1:R1uwffexN6Pr340GtYRIdZmAiN4J+iw6WG4wog1DUXg= -github.com/onsi/gomega v1.9.0/go.mod h1:Ho0h+IUsWyvy1OpqCwxlQ/21gkhVunqlU8fDGcoTdcA= +github.com/maxbrunsfeld/counterfeiter/v6 v6.12.2 h1:V23nK2R2B63g2GhygF9zVGpnigmhvoZoH8d0hrZwMGY= +github.com/maxbrunsfeld/counterfeiter/v6 v6.12.2/go.mod h1:Mr897yU9FmyKaQDPtRlVKibrjz40XXyOHUfyZBPSyZU= +github.com/onsi/gomega v1.39.1 h1:1IJLAad4zjPn2PsnhH70V4DKRFlrCzGBNrNaru+Vf28= +github.com/onsi/gomega v1.39.1/go.mod h1:hL6yVALoTOxeWudERyfppUcZXjMwIMLnuSfruD2lcfg= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/sclevine/spec v1.2.0 h1:1Jwdf9jSfDl9NVmt8ndHqbTZ7XCCPbh1jI3hkDBHVYA= -github.com/sclevine/spec v1.2.0/go.mod h1:W4J29eT/Kzv7/b9IWLB055Z+qvVC9vt0Arko24q7p+U= github.com/sclevine/spec v1.4.0 h1:z/Q9idDcay5m5irkZ28M7PtQM4aOISzOpj4bUPkDee8= github.com/sclevine/spec v1.4.0/go.mod h1:LvpgJaFyvQzRvc1kaDs0bulYwzC70PbiYjC4QnFHkOM= github.com/shurcooL/githubv4 v0.0.0-20200414012201-bbc966b061dd h1:EwtC+kDj8s9OKiaStPZtTv3neldOyr98AXIxvmn3Gss= @@ -50,56 +33,34 @@ github.com/shurcooL/graphql v0.0.0-20181231061246-d48a9a75455f/go.mod h1:AuYgA5K github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M= +go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc= +go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20200423211502-4bdfaf469ed5 h1:Q7tZBpemrlsc2I7IyODzhtallWRSm4Q0d09pL6XbQtU= -golang.org/x/crypto v0.0.0-20200423211502-4bdfaf469ed5/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee h1:WG0RUwxtNT4qqaXX3DPA8zHFNm/D9xaBpxzHt1WcA/E= -golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= -golang.org/x/mod v0.2.0 h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ= -golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/crypto v0.49.0 h1:+Ng2ULVvLHnJ/ZFEq4KdcDd/cfjrrjjNSXNzxg0Y4U4= +golang.org/x/crypto v0.49.0/go.mod h1:ErX4dUh2UM+CFYiXZRTcMpEcN8b/1gxEuv3nODoYtCA= +golang.org/x/mod v0.34.0 h1:xIHgNUUnW6sYkcM5Jleh05DvLOtwc6RitGHbDk4akRI= +golang.org/x/mod v0.34.0/go.mod h1:ykgH52iCZe79kzLLMhyCUzhMci+nQj+0XkbXpNYtVjY= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200421231249-e086a090c8fd h1:QPwSajcTUrFriMF1nJ3XzgoqakqQEsnZf9LdXdi2nkI= -golang.org/x/net v0.0.0-20200421231249-e086a090c8fd/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.52.0 h1:He/TN1l0e4mmR3QqHMT2Xab3Aj3L9qjbhRm78/6jrW0= +golang.org/x/net v0.52.0/go.mod h1:R1MAz7uMZxVMualyPXb+VaqGSa3LIaUqk0eEt3w36Sw= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d h1:TzXSXBo42m9gQenoE3b9BGiEpg5IG2JkU5FkPIawgtw= golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4= +golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb h1:fgwFCsaw9buMuxNd6+DQfAuSFqbNiQZpcgJQAgJsK6k= -golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884= -golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.35.0 h1:JOVx6vVDFokkpaq1AEptVzLTpDe9KGpj5tR4/X+ybL8= +golang.org/x/text v0.35.0/go.mod h1:khi/HExzZJ2pGnjenulevKNX1W67CUy0AsXcNubPGCA= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20200301222351-066e0c02454c h1:FD7jysxM+EJqg5UYYy3XYDsAiUickFsn4UiaanJkf8c= -golang.org/x/tools v0.0.0-20200301222351-066e0c02454c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200423205358-59e73619c742 h1:9OGWpORUXvk8AsaBJlpzzDx7Srv/rSK6rvjcsJq4rJo= -golang.org/x/tools v0.0.0-20200423205358-59e73619c742/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/tools v0.43.0 h1:12BdW9CeB3Z+J/I/wj34VMl8X+fEXBxVR90JeMX5E7s= +golang.org/x/tools v0.43.0/go.mod h1:uHkMso649BX2cZK6+RpuIPXS3ho2hZo4FVwfoy1vIk0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= @@ -111,13 +72,3 @@ google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQ google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= google.golang.org/protobuf v1.21.0 h1:qdOKuR/EIArgaWNjetjgTzgVTAZ+S/WXVrq9HW9zimw= google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= -gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= -gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I= -gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/out.go b/out.go index cd6245c9..c27568a2 100644 --- a/out.go +++ b/out.go @@ -85,6 +85,14 @@ func Put(request PutRequest, manager Github, inputDir string) (*PutResponse, err } } + // Set label if specified + if p := request.Params; p.Label != "" { + err = manager.AddLabel(version.PR, p.Label) + if err != nil { + return nil, fmt.Errorf("failed to add label: %s", err) + } + } + return &PutResponse{ Version: version, Metadata: metadata, @@ -114,6 +122,7 @@ type PutParameters struct { Status string `json:"status"` CommentFile string `json:"comment_file"` Comment string `json:"comment"` + Label string `json:"label"` DeletePreviousComments bool `json:"delete_previous_comments"` } diff --git a/out_test.go b/out_test.go index 4d430c7b..0829b3ba 100644 --- a/out_test.go +++ b/out_test.go @@ -144,6 +144,23 @@ func TestPut(t *testing.T) { pullRequest: createTestPR(1, "master", false, false, 0, nil, false, githubv4.PullRequestStateOpen), }, + { + description: "we can add a label to the pull request", + source: resource.Source{ + Repository: "itsdalmo/test-repository", + AccessToken: "oauthtoken", + }, + version: resource.Version{ + PR: "pr1", + Commit: "commit1", + CommittedDate: time.Time{}, + }, + parameters: resource.PutParameters{ + Label: "ready", + }, + pullRequest: createTestPR(1, "master", false, false, 0, nil, false, githubv4.PullRequestStateOpen), + }, + { description: "we can delete previous comments made on the pull request", source: resource.Source{ @@ -208,6 +225,14 @@ func TestPut(t *testing.T) { } } + if tc.parameters.Label != "" { + if assert.Equal(t, 1, github.AddLabelCallCount()) { + pr, label := github.AddLabelArgsForCall(0) + assert.Equal(t, tc.version.PR, pr) + assert.Equal(t, tc.parameters.Label, label) + } + } + if tc.parameters.DeletePreviousComments { if assert.Equal(t, 1, github.DeletePreviousCommentsCallCount()) { pr := github.DeletePreviousCommentsArgsForCall(0) diff --git a/scripts/install_git_crypt.sh b/scripts/install_git_crypt.sh index c56eafc4..504d1b36 100755 --- a/scripts/install_git_crypt.sh +++ b/scripts/install_git_crypt.sh @@ -3,21 +3,7 @@ set -eu _main() { - apk --update add --virtual=.build-deps curl make g++ openssl-dev - apk add --no-cache libgcc libstdc++ openssl - local tmpdir - tmpdir="$(mktemp -d git_crypt_install.XXXXXX)" - - cd "$tmpdir" - curl -Lo git-crypt-0.6.0.tar.gz https://www.agwa.name/projects/git-crypt/downloads/git-crypt-0.6.0.tar.gz - tar -zxf git-crypt-0.6.0.tar.gz - cd git-crypt-0.6.0 - make - make install - cd .. - rm -rf "$tmpdir" - - apk del .build-deps + apk add --no-cache git-crypt rm -rf /var/cache/apk/* } diff --git a/tools/tools.go b/tools/tools.go index 722d1d89..bcb0ddbf 100644 --- a/tools/tools.go +++ b/tools/tools.go @@ -1,3 +1,4 @@ +//go:build tools // +build tools package tools