From 617c6eacdbaf13033aee1c03589b5446d2b1625b Mon Sep 17 00:00:00 2001 From: Alexander Jung Date: Wed, 18 Nov 2020 16:01:21 +0100 Subject: [PATCH] Initial release Signed-off-by: Alexander Jung --- .editorconfig | 10 + .github/workflows/pipeline.yml | 114 +++++++++++ .gitignore | 6 + .goreleaser.yml | 34 ++++ Dockerfile | 68 +++++++ LICENSE | 30 +++ Makefile | 151 +++++++++++++++ README.md | 134 +++++++++++++ actions/actions.go | 233 +++++++++++++++++++++++ actions/check.go | 150 +++++++++++++++ actions/in.go | 215 +++++++++++++++++++++ actions/out.go | 252 +++++++++++++++++++++++++ api/github.go | 334 +++++++++++++++++++++++++++++++++ assets/check | 3 + assets/in | 3 + assets/out | 3 + cmd/root.go | 75 ++++++++ cmd/version.go | 53 ++++++ go.mod | 10 + go.sum | 295 +++++++++++++++++++++++++++++ main.go | 52 +++++ 21 files changed, 2225 insertions(+) create mode 100644 .editorconfig create mode 100644 .github/workflows/pipeline.yml create mode 100644 .gitignore create mode 100644 .goreleaser.yml create mode 100644 Dockerfile create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 README.md create mode 100644 actions/actions.go create mode 100644 actions/check.go create mode 100644 actions/in.go create mode 100644 actions/out.go create mode 100644 api/github.go create mode 100644 assets/check create mode 100644 assets/in create mode 100644 assets/out create mode 100644 cmd/root.go create mode 100644 cmd/version.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..de3addf --- /dev/null +++ b/.editorconfig @@ -0,0 +1,10 @@ +[*] +end_of_line = lf +insert_final_newline = true + +[*.go] +indent_style = space +indent_size = 2 + +[Makefile] +indent_style = tab diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml new file mode 100644 index 0000000..d808ab4 --- /dev/null +++ b/.github/workflows/pipeline.yml @@ -0,0 +1,114 @@ +name: 'resource-pipeline' +on: + push: + pull_request: + types: [ opened, reopened ] +jobs: + unit-test: + strategy: + matrix: + go-version: [1.14.x, 1.15.x] + platform: [ubuntu-latest] + runs-on: ${{ matrix.platform }} + steps: + + - uses: actions/setup-go@v1 + with: + go-version: ${{ matrix.go-version }} + + - uses: actions/checkout@v1 + + - name: Cache go dependencies + id: unit-cache-go-dependencies + uses: actions/cache@v1 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }} + restore-keys: ${{ runner.os }}-go-${{ matrix.go-version }}- + + - name: Install go dependencies + if: steps.unit-cache-go-dependencies.outputs.cache-hit != 'true' + run: go get ./... + + - name: Test + run: make ci-unit-test + + build-artifacts: + runs-on: ubuntu-latest + steps: + - uses: actions/setup-go@v1 + with: + go-version: '1.15.x' + + - uses: actions/checkout@v1 + + - name: Install tooling + run: | + make ci-install-go-tools + make ci-install-ci-tools + - name: Cache go dependencies + id: package-cache-go-dependencies + uses: actions/cache@v1 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-prod-${{ hashFiles('**/go.sum') }} + restore-keys: ${{ runner.os }}-go-prod- + + - name: Install dependencies + if: steps.package-cache-go-dependencies.outputs.cache-hit != 'true' + run: go get ./... + + - name: Linting, formatting, and other static code analyses + run: make ci-static-analysis + + - name: Build snapshot artifacts + run: make ci-build-snapshot-packages + + - run: docker images ndrjng/concourse-github-pr-comment-resource + + - name: Test production image + run: make ci-test-production-image + + release: + needs: [ unit-test, build-artifacts ] + runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/v') + steps: + + - uses: actions/setup-go@v1 + with: + go-version: '1.15.x' + + - uses: actions/checkout@v1 + + - name: Install tooling + run: make ci-install-ci-tools + + - name: Cache go dependencies + id: release-cache-go-dependencies + uses: actions/cache@v1 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-prod-${{ hashFiles('**/go.sum') }} + restore-keys: ${{ runner.os }}-go-prod- + + - name: Install dependencies + if: steps.release-cache-go-dependencies.outputs.cache-hit != 'true' + run: go get ./... + + - name: Docker login + run: make ci-docker-login + env: + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + + - name: Publish GitHub release + run: make ci-release + env: + GITHUB_TOKEN: ${{ secrets.RELEASE_GITHUB_TOKEN }} + + - name: Docker logout + run: make ci-docker-logout + + - name: Smoke test published image + run: make ci-test-production-image diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..813ec78 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +// CONCOURSE +.credentials.yml + +// GO +coverage.out +dist/ diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..29ff0d7 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,34 @@ +release: + prerelease: false + +builds: + - binary: dist/github-pr-comment + env: + - CGO_ENABLED=0 + goos: + - linux + goarch: + - amd64 + ldflags: -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.buildTime={{.Date}}`. + +dockers: + - binaries: + - github-pr-comment + dockerfile: Dockerfile + # todo: on 1.0 remove 'v' prefix + image_templates: + - "ndrjng/concourse-github-pr-resource-resource:latest" + - "ndrjng/concourse-github-pr-resource-resource:{{ .Tag }}" + - "ndrjng/concourse-github-pr-resource-resource:v{{ .Major }}" + - "ndrjng/concourse-github-pr-resource-resource:v{{ .Major }}.{{ .Minor }}" + extra_files: + - go.mod + - go.sum + - main.go + - cmd/ + - api/ + - actions/ + - assets/ + - Makefile + + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c15198c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,68 @@ +# SPDX-License-Identifier: BSD-3-Clause +# +# Authors: Alexander Jung +# +# Copyright (c) 2020, Alexander Jung. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +ARG GOLANG_VERSION=1.15 + +FROM golang:${GOLANG_VERSION} AS devenv + +ARG ORG=nderjung +ARG REPO=concourse-github-pr-comment-resource + +RUN set -xe; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + sudo; + +COPY . /go/src/github.com/${ORG}/${REPO} + +FROM devenv AS build + +ARG GOOS=linux +ARG GOARCH=amd64 +ARG ORG=nderjung +ARG REPO=concourse-github-pr-comment-resource + +WORKDIR /go/src/github.com/${ORG}/${REPO} + +RUN set -xe; \ + BUILDPATH=/github-pr-comment make build + +FROM concourse/buildroot:base AS run + +ARG BIN=github-pr-resource + +COPY --from=build /github-pr-comment /bin/github-pr-comment + +# Required by concrouse resource +COPY /assets/check /opt/resource/check +COPY /assets/in /opt/resource/in +COPY /assets/out /opt/resource/out + +RUN chmod +x /opt/resource/* diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..379a807 --- /dev/null +++ b/LICENSE @@ -0,0 +1,30 @@ +SPDX-License-Identifier: BSD-3-Clause + +Authors: Alexander Jung + +Copyright (c) 2020, Alexander Jung. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..89407c2 --- /dev/null +++ b/Makefile @@ -0,0 +1,151 @@ +# SPDX-License-Identifier: BSD-3-Clause +# +# Authors: Alexander Jung +# +# Copyright (c) 2020, Alexander Jung. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +# Application configuration +BIN ?= github-pr-comment +ORG ?= nderjung +REPO ?= concourse-github-pr-comment-resource +REGISTRY ?= docker.io +GOOS ?= linux +GOARCH ?= amd64 + +# Directories and paths +WORKDIR ?= $(CURDIR) +BUILDPATH ?= $(WORKDIR)/dist/$(BIN)$(DIST)_$(GOOS)_$(GOARCH) + +# Tools +DOCKER ?= docker +GO ?= go +GOFMT ?= gofmt +GOLANGCILINT ?= golangci-lint +GORELEASER ?= goreleaser +SUDO ?= sudo + +# Misc +Q ?= @ + +# Targets +.PHONY: all +all: build + +.PHONY: build +build: GOFLAGS ?= -linkshared +build: + $(GO) build $(GOFLAGS) -o $(BUILDPATH) + +# Build the docker container +docker: DOCKER_BUILD_EXTRA ?= +docker: DOCKER_TARGET ?= +docker: DOCKER_TAG ?= +ifeq ($(DOCKER_TARGET),) +docker: IMAGE_TAG ?= latest +docker: DOCKER_TARGET := run +else ifeq ($(DOCKER_TARGET),devenv) +docker: IMAGE_TAG ?= dev +endif +.PHONY: docker +docker: GOLANG_VERSION ?= 1.15 +docker: + $(Q)$(DOCKER) build \ + --tag ndrjng/$(REPO):$(IMAGE_TAG) \ + --file $(WORKDIR)/Dockerfile \ + --target $(DOCKER_TARGET) \ + --build-arg BIN=$(BIN) \ + --build-arg ORG=$(ORG) \ + --build-arg REPO=$(REPO) \ + --build-arg GOOS=$(GOOS) \ + --build-arg GOARCH=$(GOARCH) \ + --build-arg GOLANG_VERSION=$(GOLANG_VERSION) \ + $(DOCKER_BUILD_EXTRA) $(WORKDIR) + +# Create a development environment +.PHONY: devenv +devenv: DOCKER_RUN_EXTRA ?= +devenv: + $(Q)$(DOCKER) run -it --rm \ + --name $(BIN)-devenv \ + --workdir /go/src/github.com/$(ORG)/$(REPO) \ + --volume $(WORKDIR):/go/src/github.com/$(ORG)/$(REPO) \ + ndrjng/$(REPO):dev \ + $(DOCKER_RUN_EXTRA) bash + +# CI/CD targets +.PHONY: ci-unit-test +ci-unit-test: + $(GO) test -cover -v -race ./... + +.PHONY: ci-static-analysis +ci-static-analysis: + $(Q)$(GO) vet ./... + $(Q)$(GOFMT) -s -l . 2>&1 | grep -vE '^\.git/' | grep -vE '^\.cache/' + $(Q)$(GOLANGCILINT) run + +.PHONY: ci-install-go-tools +ci-install-go-tools: + $(Q)curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | $(SUDO) sh -s -- -b /usr/local/bin/ latest + +.PHONY: ci-install-ci-tools +ci-install-ci-tools: + $(Q)curl -sfL https://install.goreleaser.com/github.com/goreleaser/goreleaser.sh | $(SUDO) sh -s -- -b /usr/local/bin/ "v0.146.0" + +.PHONY: ci-docker-login +ci-docker-login: + $(Q)echo '${DOCKER_PASSWORD}' | docker login -u '${DOCKER_USERNAME}' --password-stdin '${REGISTRY}' + +.PHONY: ci-docker-logout +ci-docker-logout: + $(Q)$(DOCKER) logout '${REGISTRY}' + +.PHONY: ci-publish-release +ci-publish-release: + $(Q)$(GORELEASER) --rm-dist + +.PHONY: ci-build-snapshot-packages +ci-build-snapshot-packages: + $(Q)$(GORELEASER) \ + --snapshot \ + --skip-publish \ + --rm-dist + +.PHONY: ci-release +ci-release: + $(Q)$(GORELEASER) release --rm-dist + +.PHONY: ci-test-production-image +ci-test-production-image: + $(Q)$(DOCKER) run --rm -t \ + ${REGISTRY}/ndrjng/$(REPO):latest \ + /bin/$(BIN) --version + +.PHONY: ci-test-linux-run +ci-test-linux-run: + chmod +x $(BUILDPATH) + $(BUILDPATH) --version diff --git a/README.md b/README.md new file mode 100644 index 0000000..6a612da --- /dev/null +++ b/README.md @@ -0,0 +1,134 @@ +# concourse-github-pr-comment-resource + +![resource-pipeline](https://github.com/nderjung/concourse-github-pr-comment-resource/workflows/resource-pipeline/badge.svg) + +This Concourse resource monitors incoming comments on a Github Pull Request and +is able to monitor for comments matching regular expressions, match comment +author's association with the project, the pull request's state and any labels +it has been assigned. + +Inspired by [`telia-oss/github-pr-resource`](https://github.com/telia-oss/github-pr-resource) +with the aim of providing a resource which reacts solely on the newest comment +to a particular pull request of a repository. + +## Source configuration + +The following parameters are used for the resource's `source` configuration: + +| Parameter | Required | Example | Default | Description | +| -------------------- | -------- | ------------------------------------------- | ------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `repository` | Yes | `nderjung/limp` | | The repository to listen for PR comments on. | +| `access_token` | Yes | | | The [personal access token](https://github.com/settings/tokens/new) of the account used to access, monitor and post comments on the repository in question. | +| `github_endpoint` | No | | `https://api.github.com` | Endpoint used to connect to the Github v3 API. | +| `skip_ssl` | No | `true` | `false` | Whether to skip SSL verification of the Github API. | +| `author_association` | No | `["first_time_contributor", "first_timer"]` | `["all"]` | The comment author's relationship with the pull request's repository. Possible values include any of or any combination of `"collaborator"`, `"contributor"`, `"first_timer"`, `"first_time_contributor"`, `"member"`, `"owner"`, or `"all"`. | +| `only_mergeable` | No | `true` | `false` | Whether to react to (non-)mergeable pull requests. | +| `states` | No | `["closed"]` | `["open"]` | The state of the pull request to react on. | +| `ignore_states` | No | `["open"]` | `[]` | The state of the pull request to not react on. | +| `labels` | No | `["bug"]` | `[]` | The labels of the pull request to react on. | +| `ignore_labels` | No | `["lifecycle/stale"]` | `[]` | The labels of the pull request not to react on. | +| `comments` | No | `["^ping$"]` | `[]` | The regular expressions of the latest comment to react on. | +| `ignore_comments` | No | `["ing$"]` | `[]` | The regular expressions of the latest comment not to react on. | + +## Behaviour + +### `check` + +Produces new versions for all new comments to pull requests matching the +criteria set by the resource's `source` configuration. The version provided to +Concourse is Github's unique numerical ID for the comment. + +### `in` + +The following parameters may be used in the `get` step of the resource: + +| Parameter | Required | Default | Description | +| -------------- | -------- | ------------- | ---------------------------------------------- | +| `comment_file` | No | `comment.txt` | A unique path to save the body of the comment. | + +The `in` procedure of this resource retrieves the following metadata about the +pull request comment and saves the key as the filename to the `path` set by the +resource. + +| Key | Description | +| -------------------- | ------------------------------------------------------------------------- | +| `pr_id` | The ID of the pull request relative to the repository. | +| `comment_id` | The unique ID provided by Github for the comment. | +| `body` | The content of the comment. | +| `created_at` | The [timestamp](https://golang.org/pkg/time/#Time.String) of the comment. | +| `updated_at` | The timestamp of when the comment was last updated. | +| `author_association` | The association the author of the comment has with the repository. | +| `html_url` | The URL to the comment. | +| `user_login` | The username of the comment author on Github. | +| `user_id` | The unique ID of the comment author on Github. | +| `user_avatar_url` | The avatar URL for the comment author. | +| `user_html_url` | The URL to the comment author's profile on Github. | + +Additionally, the `in`/get step of this resource produces two additional JSON +formatted files which contain the information about the PR comment: + + * `version.json` which contains only contains the unique ID of the Github + comment to the PR; and, + * `metadata.json` which contains a serialized version of the table above. + +### `out` + +| Parameter | Required | Example | Default | Description | +| --------------------- | -------- | ----------------- | ------- | ------------------------------------------------------------------- | +| `path` | Yes | `pr-comment` | | The name given to the resource in a in/get step. | +| `state` | No | `closed` | | The state to set the PR. Options include `open` and `closed`. | +| `comment` | No | `pong` | | The string to use as a new comment on the PR. | +| `comment_file` | No | `pong.txt` | | The path to the file to read and post as a new comment on the PR. | +| `labels` | No | `[""]` | | The finite set of labels to replace on the PR. | +| `add_labels` | No | `["cicd/tested"]` | | Additional labels to add to the PR. | +| `remove_labels` | No | `["cicd/await"]` | | Labels to remove from the PR. | +| `delete_last_comment` | No | `true` | `false` | Whether or not to delete the last comment of the PR comment thread. | + + +Note that `comment` and `comment_file` will all expand all [Concourse environment variables](https://concourse-ci.org/implementing-resource-types.html#resource-metadata). + +#### Notes + + * The author of the comment will be that of the user whose access token is used + in the resource's `source` configuration. + +## Example + +The following represents a simple "ping-pong" setup, where Concourse is able to +use this resource to react to comments to a PR with the single term "ping" with +a comment "pong": + +```yaml +resource_types: + - name: github-pr-comment-resource + type: docker-image + source: + repository: ndrjng/concourse-github-pr-comment-resource + tag: latest + +resources: + - name: github-pr-comment-ping + type: github-pr-comment-resource + icon: magnify + source: + repository: nderjung/limp + access_token: ((github.access-token)) + comments: ["^ping$"] + +jobs: + - name: pong + serial: true + plan: + - get: github-pr-comment-ping + trigger: true + version: every + + - put: github-pr-comment-ping + params: + path: github-pr-comment-ping + comment: "pong" +``` + +## License + +BSD-3-Clause. See [`LICENSE`](LICENSE). diff --git a/actions/actions.go b/actions/actions.go new file mode 100644 index 0000000..28627e8 --- /dev/null +++ b/actions/actions.go @@ -0,0 +1,233 @@ +// SPDX-License-Identifier: BSD-3-Clause +// +// Authors: Alexander Jung +// +// Copyright (c) 2020, Alexander Jung. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +package actions + +import ( + "os" + "fmt" + "log" + "regexp" + "strings" + "reflect" + "encoding/json" + + "github.com/google/go-github/v32/github" +) + +// Source parameters provided by the resource. +type Source struct { + // Meta + SkipSSLVerification bool `json:"skip_ssl"` + GithubEndpoint string `json:"github_endpoint"` + + // The repository to interface with + Repository string `json:"repository"` + + // Access methods + AccessToken string `json:"access_token"` + Username string `json:"username"` + Password string `json:"password"` + + // Selection criteria + OnlyMergeable bool `json:"only_mergeable"` + States []string `json:"states"` + Labels []string `json:"labels"` + Comments []string `json:"comments"` + CommenterAssociation []string `json:"commenter_association"` + + IgnoreStates []string `json:"ignore_states"` + IgnoreLabels []string `json:"ignore_labels"` + IgnoreComments []string `json:"ignore_comments"` +} + +// Version communicated with Concourse. +type Version struct { + Ref string `json:"ref"` +} + +// Metadata has a key name and value +type MetadataField struct { + Name string `json:"name"` + Value string `json:"value"` +} + +// Metadata contains the serialized interface +type Metadata []*MetadataField + +// Add a MetadataField to the Metadata struct +func (m *Metadata) Add(name, value string) { + *m = append(*m, &MetadataField{ + Name: name, + Value: value, + }) +} + +// Get a MetadataField value from the Metadata struct +func (m *Metadata) Get(name string) (string, error) { + for _, i := range *m { + if name == i.Name { + return i.Value, nil + } + } + + return "", fmt.Errorf("metadata index does not exist: %s", name) +} + +func serializeMetadata(meta interface{}) Metadata { + var res Metadata + v := reflect.ValueOf(meta) + typeOfS := v.Type() + + for i := 0; i< v.NumField(); i++ { + res.Add( + typeOfS.Field(i).Tag.Get("json"), + fmt.Sprintf("%v", v.Field(i).Interface()), + ) + } + + return res +} + +// requestsState checks whether the source requests this particular state +func (source *Source) requestsState(state string) bool { + ret := false + + // if there are no set states, assume only "open" states + if len(source.States) == 0 { + ret = state == "open" + } else { + for _, s := range source.States { + if s == state { + ret = true + break + } + } + } + + // Ensure ignored states + for _, s := range source.IgnoreStates { + if s == state { + ret = false + break + } + } + + return ret +} + +// requestsLabels checks whether the source requests these set of labels +func (source *Source) requestsLabels(labels []*github.Label) bool { + ret := false + + // If no set labels, assume all + if len(source.Labels) == 0 { + ret = true + } else { + includeLoop: + for _, rl := range source.Labels { + for _, rr := range labels { + if rl == rr.GetName() { + ret = true + break includeLoop + } + } + } + } + + excludeLoop: + for _, rl := range source.IgnoreLabels { + for _, rr := range labels { + if rl == rr.GetName() { + ret = false + break excludeLoop + } + } + } + + return ret +} + +// requestsCommenterAssociation checks the comment author's association +func (source *Source) requestsCommenterAssociation(assoc string) bool { + // if no associations set, assume all + if len(source.CommenterAssociation) == 0 || ( + len(source.CommenterAssociation) == 1 && + source.CommenterAssociation[0] == "all") { + return true + } + + assoc = strings.ToLower(assoc) + for _, a := range source.CommenterAssociation { + if assoc == strings.ToLower(a) { + return true + } + } + + return false +} + +// requestsCommentRegex determines if the source requests this comment regex +func (source *Source) requestsCommentRegex(comment string) bool { + ret := false + + if len(source.Comments) == 0 { + ret = true + } else { + for _, c := range source.Comments { + matched, _ := regexp.Match(c, []byte(comment)) + if matched { + ret = true + } + } + } + + for _, c := range source.IgnoreComments { + matched, _ := regexp.Match(c, []byte(comment)) + if matched { + ret = false + } + } + + return ret +} + +var logger = log.New(os.Stderr, "resource:", log.Lshortfile) + +// doOutput ... +func doOutput(output interface{}, encoder *json.Encoder, logger *log.Logger) error { + _, err := json.MarshalIndent(output, "", " ") + if err != nil { + return err + } + + // encode output to stdout + return encoder.Encode(output) +} diff --git a/actions/check.go b/actions/check.go new file mode 100644 index 0000000..1ef8cec --- /dev/null +++ b/actions/check.go @@ -0,0 +1,150 @@ +// SPDX-License-Identifier: BSD-3-Clause +// +// Authors: Alexander Jung +// +// Copyright (c) 2020, Alexander Jung. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +package actions + +import ( + "os" + "strconv" + "encoding/json" + + "github.com/spf13/cobra" + "github.com/nderjung/concourse-github-pr-comment-resource/api" +) + +// CheckCmd ... +var CheckCmd = &cobra.Command{ + Use: "check", + Short: "Run the check step", + Run: doCheckCmd, + DisableFlagsInUseLine: true, +} + +// CheckRequest from the check stdin. +type CheckRequest struct { + Source Source `json:"source"` + Version Version `json:"version"` +} + +// CheckResponse represents the structure Concourse expects on stdout +type CheckResponse []Version + +func doCheckCmd(cmd *cobra.Command, args []string) { + decoder := json.NewDecoder(os.Stdin) + decoder.DisallowUnknownFields() + + // Concourse passes .json on stdin + var req CheckRequest + if err := decoder.Decode(&req); err != nil { + logger.Fatalf("Failed to decode to stdin: %s", err) + return + } + + // Perform the check with the given request + res, err := Check(req) + if err != nil { + logger.Fatalf("Failed to connect to Github: %s", err) + return + } + + var encoder = json.NewEncoder(os.Stdout) + + // Generate a compatible Concourse output + if err := doOutput(*res, encoder, logger); err != nil { + logger.Fatalf("Failed to encode to stdout: %s", err) + return + } +} + +func Check(req CheckRequest) (*CheckResponse, error) { + client, err := api.NewGithubClient( + req.Source.Repository, + req.Source.AccessToken, + req.Source.SkipSSLVerification, + req.Source.GithubEndpoint, + ) + if err != nil { + return nil, err + } + + var versions CheckResponse + + // Get all pull requests + pulls, err := client.ListPullRequests() + if err != nil { + return nil, err + } + + // Iterate over all pull requests + for _, pull := range pulls { + // Ignore if state not requested + if !req.Source.requestsState(*pull.State) { + continue + } + + // Ignore if labels not requested + if !req.Source.requestsLabels(pull.Labels) { + continue + } + + // Ignore if only mergeables requested + if req.Source.OnlyMergeable && !*pull.Mergeable { + continue + } + + // Ignore drafts + if *pull.Draft { + continue + } + + // Iterate through all the comments for this PR + comments, err := client.ListPullRequestComments(int(*pull.Number)) + if err != nil { + return nil, err + } + + for _, comment := range comments { + if !req.Source.requestsCommenterAssociation(*comment.AuthorAssociation) { + continue + } + + if !req.Source.requestsCommentRegex(*comment.Body) { + continue + } + + // Add the comment ID to the list of versions we want Concourse to see + versions = append(versions, Version{ + Ref: strconv.FormatInt(*comment.ID, 10), + }) + } + } + + return &versions, nil +} diff --git a/actions/in.go b/actions/in.go new file mode 100644 index 0000000..8bf9f47 --- /dev/null +++ b/actions/in.go @@ -0,0 +1,215 @@ +// SPDX-License-Identifier: BSD-3-Clause +// +// Authors: Alexander Jung +// +// Copyright (c) 2020, Alexander Jung. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +package actions + +import ( + "os" + "fmt" + "time" + "strconv" + "io/ioutil" + "encoding/json" + "path/filepath" + + "github.com/spf13/cobra" + "github.com/nderjung/concourse-github-pr-comment-resource/api" +) + +// InCmd +var InCmd = &cobra.Command{ + Use: "in [OPTIONS] PATH", + Short: "Run the input parsing step", + Run: doInCmd, + Args: cobra.ExactArgs(1), + DisableFlagsInUseLine: true, +} + +// InParams are the parameters for configuring the input +type InParams struct { + CommentFile string `json:"comment_file"` +} + +// InRequest from the check stdin. +type InRequest struct { + Source Source `json:"source"` + Version Version `json:"version"` + Params InParams `json:"params"` +} + +// InResponse represents the structure Concourse expects on stdout +type InResponse struct { + Version Version `json:"version"` + Metadata Metadata `json:"metadata"` +} + +type InMetadata struct { + PRID int `json:"pr_id"` + CommentID int64 `json:"comment_id"` + Body string `json:"body"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` + AuthorAssociation string `json:"author_association"` + HTMLURL string `json:"html_url"` + UserLogin string `json:"user_login"` + UserID int64 `json:"user_id"` + UserAvatarURL string `json:"user_avatar_url"` + UserHTMLURL string `json:"user_html_url"` +} + +func doInCmd(cmd *cobra.Command, args []string) { + decoder := json.NewDecoder(os.Stdin) + decoder.DisallowUnknownFields() + + // Concourse passes .json on stdin + var req InRequest + if err := decoder.Decode(&req); err != nil { + logger.Fatal(err) + return + } + + // Perform the in command with the given request + res, err := In(args[0], req) + if err != nil { + logger.Fatal(err) + return + } + + var encoder = json.NewEncoder(os.Stdout) + + // Generate a compatible Concourse output + if err := doOutput(res, encoder, logger); err != nil { + logger.Fatalf("Failed to encode to stdout: %s", err) + return + } +} + +func In(outputDir string, req InRequest) (*InResponse, error) { + client, err := api.NewGithubClient( + req.Source.Repository, + req.Source.AccessToken, + req.Source.SkipSSLVerification, + req.Source.GithubEndpoint, + ) + if err != nil { + return nil, err + } + + commentID, err := strconv.ParseInt(req.Version.Ref, 10, 64) + if err != nil { + return nil, err + } + comment, err := client.GetPullRequestComment(commentID) + if err != nil { + return nil, err + } + + // Write comment, version and metadata for reuse in PUT + path := filepath.Join(outputDir) + if err := os.MkdirAll(path, os.ModePerm); err != nil { + return nil, fmt.Errorf("failed to create output directory: %s", err) + } + + // Set the destination file to save the comment to + commentFile := "comment.txt" + if req.Params.CommentFile != "" { + commentFile = req.Params.CommentFile + } + + // Write the comment body to the specified path + f, err := os.Create(filepath.Join(path, commentFile)) + if err != nil { + return nil, fmt.Errorf("could not create comment file: %s", err) + } + + defer f.Close() + + err = f.Truncate(0) + if err != nil { + return nil, err + } + + _, err = f.WriteString(*comment.Body) + if err != nil { + return nil, err + } + + // Retrieve the PR number from the given URL + prNumber, err := api.ParseCommentHTMLURL(*comment.HTMLURL) + if err != nil { + return nil, err + } + + metadata := serializeMetadata(InMetadata{ + PRID: prNumber, + CommentID: *comment.ID, + Body: *comment.Body, + CreatedAt: *comment.CreatedAt, + UpdatedAt: *comment.UpdatedAt, + AuthorAssociation: *comment.AuthorAssociation, + HTMLURL: *comment.HTMLURL, + UserLogin: *comment.User.Login, + UserID: *comment.User.ID, + UserAvatarURL: *comment.User.AvatarURL, + UserHTMLURL: *comment.User.HTMLURL, + }) + + b, err := json.Marshal(req.Version) + if err != nil { + return nil, fmt.Errorf("failed to marshal version: %s", err) + } + + if err := ioutil.WriteFile(filepath.Join(path, "version.json"), b, 0644); err != nil { + return nil, fmt.Errorf("failed to write version: %s", err) + } + + b, err = json.Marshal(metadata) + if err != nil { + return nil, fmt.Errorf("failed to marshal metadata: %s", err) + } + + if err := ioutil.WriteFile(filepath.Join(path, "metadata.json"), b, 0644); err != nil { + return nil, fmt.Errorf("failed to write metadata: %s", err) + } + + // Save the individual metadata items to seperate files + for _, d := range metadata { + filename := d.Name + content := []byte(d.Value) + if err := ioutil.WriteFile(filepath.Join(path, filename), content, 0644); err != nil { + return nil, fmt.Errorf("failed to write metadata file %s: %s", filename, err) + } + } + + return &InResponse{ + Version: req.Version, + Metadata: metadata, + }, nil +} diff --git a/actions/out.go b/actions/out.go new file mode 100644 index 0000000..0d4ee5e --- /dev/null +++ b/actions/out.go @@ -0,0 +1,252 @@ +// SPDX-License-Identifier: BSD-3-Clause +// +// Authors: Alexander Jung +// +// Copyright (c) 2020, Alexander Jung. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +package actions + +import ( + "os" + "fmt" + "strconv" + "strings" + "io/ioutil" + "encoding/json" + "path/filepath" + + "github.com/spf13/cobra" + "github.com/nderjung/concourse-github-pr-comment-resource/api" +) + +// OutCmd +var OutCmd = &cobra.Command{ + Use: "out [OPTIONS] PATH", + Short: "Run the output processing step", + Run: doOutCmd, + Args: cobra.ExactArgs(1), + DisableFlagsInUseLine: true, +} + +type OutParams struct { + Path string `json:"path"` + State string `json:"state"` + Comment string `json:"comment"` + CommentFile string `json:"comment_file"` + Labels []string `json:"labels"` + AddLabels []string `json:"add_labels"` + RemoveLabels []string `json:"remove_labels"` + DeleteLastComment bool `json:"delete_last_comment"` +} + +func (p *OutParams) Validate() error { + if p.State == "" { + return nil + } + + // Make sure we are setting an allowed state + var allowedState bool + + state := strings.ToLower(p.State) + allowed := []string{"open", "closed"} + + for _, a := range allowed { + if state == a { + allowedState = true + } + } + + if !allowedState { + return fmt.Errorf("unknown state: %s", p.State) + } + + return nil +} + +// OutRequest from the check stdin. +type OutRequest struct { + Source Source `json:"source"` + Params OutParams `json:"params"` +} + +// OutResponse represents the structure Concourse expects on stdout +type OutResponse struct { + Version Version `json:"version"` + Metadata Metadata `json:"metadata"` +} + +func doOutCmd(cmd *cobra.Command, args []string) { + decoder := json.NewDecoder(os.Stdin) + decoder.DisallowUnknownFields() + + // Concourse passes .json on stdin + var req OutRequest + if err := decoder.Decode(&req); err != nil { + logger.Fatalf("Failed to decode to stdin: %s", err) + return + } + + // Perform the out command with the given request + res, err := Out(args[0], req) + if err != nil { + logger.Fatal(err) + return + } + + var encoder = json.NewEncoder(os.Stdout) + + // Generate a compatible Concourse output + if err := doOutput(res, encoder, logger); err != nil { + logger.Fatalf("Failed to encode to stdout: %s", err) + return + } +} + +func Out(inputDir string, req OutRequest) (*OutResponse, error) { + if err := req.Params.Validate(); err != nil { + return nil, fmt.Errorf("invalid parameters: %s", err) + } + + path := filepath.Join(inputDir, req.Params.Path) + + // Version available after a GET step. + var version Version + content, err := ioutil.ReadFile(filepath.Join(path, "version.json")) + if err != nil { + return nil, fmt.Errorf("failed to read version from path: %s", err) + } + if err := json.Unmarshal(content, &version); err != nil { + return nil, fmt.Errorf("failed to unmarshal version from file: %s", err) + } + + // Metadata available after a GET step. + var metadata Metadata + content, err = ioutil.ReadFile(filepath.Join(path, "metadata.json")) + if err != nil { + return nil, fmt.Errorf("failed to read metadata from path: %s", err) + } + if err := json.Unmarshal(content, &metadata); err != nil { + return nil, fmt.Errorf("failed to unmarshal metadata from file: %s", err) + } + + prNumber, err := metadata.Get("pr_id") + if err != nil { + return nil, err + } + + prID, err := strconv.Atoi(prNumber) + if err != nil { + return nil, err + } + + client, err := api.NewGithubClient( + req.Source.Repository, + req.Source.AccessToken, + req.Source.SkipSSLVerification, + req.Source.GithubEndpoint, + ) + if err != nil { + return nil, err + } + + // Update the state? + if req.Params.State != "" { + err = client.SetPullRequestState(prID, req.Params.State) + if err != nil { + return nil, err + } + } + + // Delete the last comment? + if req.Params.DeleteLastComment { + err = client.DeleteLastPullRequestComment(prID) + if err != nil { + return nil, err + } + } + + // Add, remove or replace tags? + if len(req.Params.Labels) > 0 { + err = client.ReplacePullRequestLabels(prID, req.Params.Labels) + if err != nil { + return nil, err + } + } else { + if len(req.Params.AddLabels) > 0 { + err = client.AddPullRequestLabels(prID, req.Params.AddLabels) + if err != nil { + return nil, err + } + } + if len(req.Params.RemoveLabels) > 0 { + err = client.RemovePullRequestLabels(prID, req.Params.RemoveLabels) + if err != nil { + return nil, err + } + } + } + + // Add a new comment? + var comment string + if len(req.Params.Comment) > 0 { + comment = req.Params.Comment + } else if len(req.Params.CommentFile) > 0 { + b, err := ioutil.ReadFile(filepath.Join(path, req.Params.CommentFile)) + if err != nil { + return nil, err + } + comment = string(b) + } + + if len(comment) > 0 { + err = client.CreatePullRequestComment(prID, safeExpandEnv(comment)) + if err != nil { + return nil, err + } + } + + return &OutResponse{ + Version: version, + Metadata: metadata, + }, nil +} + +func safeExpandEnv(s string) string { + return os.Expand(s, func(v string) string { + switch v { + case "BUILD_ID", + "BUILD_NAME", + "BUILD_JOB_NAME", + "BUILD_PIPELINE_NAME", + "BUILD_TEAM_NAME", + "ATC_EXTERNAL_URL": + return os.Getenv(v) + } + + return "$" + v + }) +} diff --git a/api/github.go b/api/github.go new file mode 100644 index 0000000..a7c60e2 --- /dev/null +++ b/api/github.go @@ -0,0 +1,334 @@ +// SPDX-License-Identifier: BSD-3-Clause +// +// Authors: Alexander Jung +// +// Copyright (c) 2020, Alexander Jung. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +package api + +import ( + "fmt" + "context" + "strconv" + "strings" + "net/url" + "net/http" + "crypto/tls" + + "golang.org/x/oauth2" + "github.com/google/go-github/v32/github" +) + +// GithubClient containing the necessary information to authenticate and perform +// actions against the REST API. +type GithubClient struct { + Owner string + Repository string + Client *github.Client +} + +// Github interface representing the desired functions for this resource. +type Github interface { + ListPullRequests() ([]*github.PullRequest, error) + GetPullRequest(prID int) (*github.PullRequest, error) + ListPullRequestComments(prID int) ([]*github.IssueComment, error) + GetPullRequestComment(commentID int64) (*github.IssueComment, error) + SetPullRequestState(prID int, state string) error + DeleteLastPullRequestComment(prID int) error + AddPullRequestLabels(prID int, labels []string) error + RemovePullRequestLabels(prID int, labels []string) error + ReplacePullRequestLabels(prID int, labels []string) error + CreatePullRequestComment(prID int, comment string) error +} + +// NewGitHubClient for creating a new instance of the client. +func NewGithubClient(repo string, accessToken string, skipSSL bool, githubEndpoint string) (*GithubClient, error) { + owner, repository, err := parseRepository(repo) + if err != nil { + return nil, err + } + + var ctx context.Context + + if skipSSL { + insecureClient := &http.Client{ + Transport: &http.Transport{ + TLSClientConfig: &tls.Config{ + InsecureSkipVerify: true, + }, + }, + } + + ctx = context.WithValue(context.TODO(), oauth2.HTTPClient, insecureClient) + } else { + ctx = context.TODO() + } + + var client *github.Client + oauth2Client := oauth2.NewClient(ctx, oauth2.StaticTokenSource( + &oauth2.Token{ + AccessToken: accessToken, + }, + )) + + if githubEndpoint != "" { + endpoint, err := url.Parse(githubEndpoint) + if err != nil { + return nil, fmt.Errorf("failed to parse v3 endpoint: %s", err) + } + + client, err = github.NewEnterpriseClient(endpoint.String(), endpoint.String(), oauth2Client) + if err != nil { + return nil, err + } + } else { + client = github.NewClient(oauth2Client) + } + + return &GithubClient{ + Owner: owner, + Repository: repository, + Client: client, + }, nil +} + +// ListPullRequests returns the list of pull requests for the configured repo +func (c *GithubClient) ListPullRequests() ([]*github.PullRequest, error) { + pulls, _, err := c.Client.PullRequests.List( + context.TODO(), + c.Owner, + c.Repository, + &github.PullRequestListOptions{ + // We want all states so we can sort through them later + State: "all", + }, + ) + if err != nil { + return nil, err + } + + return pulls, nil +} + +// GetPullRequest returns the specific pull request given its ID relative to the +// configured repo +func (c *GithubClient) GetPullRequest(prID int) (*github.PullRequest, error) { + pull, _, err := c.Client.PullRequests.Get( + context.TODO(), + c.Owner, + c.Repository, + prID, + ) + if err != nil { + return nil, err + } + return pull, nil +} + +// ListPullRequestComments returns the list of comments for the specific pull +// request given its ID relative to the configured repo +func (c *GithubClient) ListPullRequestComments(prID int) ([]*github.IssueComment, error) { + comments, _, err := c.Client.Issues.ListComments( + context.TODO(), + c.Owner, + c.Repository, + prID, + &github.IssueListCommentsOptions{}, + ) + if err != nil { + return nil, err + } + + return comments, nil +} + +// GetPulLRequestComment returns the specific comment given its unique Github ID +func (c *GithubClient) GetPullRequestComment(commentID int64) (*github.IssueComment, error) { + comment, _, err := c.Client.Issues.GetComment( + context.TODO(), + c.Owner, + c.Repository, + commentID, + ) + if err != nil { + return nil, err + } + + return comment, nil +} + +func (c *GithubClient) SetPullRequestState(prID int, state string) error { + validState := false + validStates := []string{"open", "closed"} + for _, s := range validStates { + if state == s { + validState = true + } + } + + if !validState { + return fmt.Errorf("invalid pull request state: %s", state) + } + + _, _, err := c.Client.Issues.Edit( + context.TODO(), + c.Owner, + c.Repository, + prID, &github.IssueRequest{ + State: &state, + }, + ) + + return err +} + +func (c *GithubClient) DeleteLastPullRequestComment(prID int) error { + comments, err := c.ListPullRequestComments(prID) + if err != nil { + return err + } + + // Retrieve the authenticated user provided by the access token + user, _, err := c.Client.Users.Get( + context.TODO(), + "", + ) + if err != nil { + return err + } + + // Only delete the last comment from the same author as the provided token + var commentID int64 + for _, comment := range comments { + fmt.Print(*comment.User.ID) + if *comment.User.ID == *user.ID { + commentID = *comment.ID + } + } + + if commentID > 0 { + _, err = c.Client.Issues.DeleteComment( + context.TODO(), + c.Owner, + c.Repository, + commentID, + ) + + return err + } + + return nil +} + +// AddPullRequestLabels adds the list of labels to the existing set of labels +// given the relative pull request ID to the configure repo +func (c *GithubClient) AddPullRequestLabels(prID int, labels []string) error { + _, _, err := c.Client.Issues.AddLabelsToIssue( + context.TODO(), + c.Owner, + c.Repository, + prID, + labels, + ) + + return err +} + +// RemovePullRequestLabels remove the list of labels from the set of existing +// labels given the relative pull request ID to the configured repo +func (c *GithubClient) RemovePullRequestLabels(prID int, labels []string) error { + for _, l := range labels { + _, err := c.Client.Issues.RemoveLabelForIssue( + context.TODO(), + c.Owner, + c.Repository, + prID, + l, + ) + + if err != nil { + return err + } + } + + return nil +} + +// ReplacePullRequestLabels overrides all existing labels with the given set of +// labels for the pull request ID relative to the configured repo +func (c *GithubClient) ReplacePullRequestLabels(prID int, labels []string) error { + _, _, err := c.Client.Issues.ReplaceLabelsForIssue( + context.TODO(), + c.Owner, + c.Repository, + prID, + labels, + ) + + return err +} + +// CreatePullRequestComment adds a new comment to the pull request given its +// ID relative to the configured repo +func (c *GithubClient) CreatePullRequestComment(prID int, comment string) error { + _, _, err := c.Client.Issues.CreateComment( + context.TODO(), + c.Owner, + c.Repository, + prID, + &github.IssueComment{ + Body: &comment, + }, + ) + return err +} + +func parseRepository(s string) (string, string, error) { + parts := strings.Split(s, "/") + if len(parts) != 2 { + return "", "", fmt.Errorf("malformed repository") + } + return parts[0], parts[1], nil +} + +// ParseCommentHTMLURL takes in a standard issue URL and returns the issue +// number, e.g.: +// https://github.com/octocat/Hello-World/issues/1347#issuecomment-1 +func ParseCommentHTMLURL(prUrl string) (int, error) { + u, err := url.Parse(prUrl) + if err != nil { + return -1, err + } + + parts := strings.Split(u.Path, "/") + i, err := strconv.Atoi(parts[len(parts)-1]) + if err != nil { + return -1, err + } + + return i, nil +} diff --git a/assets/check b/assets/check new file mode 100644 index 0000000..6a381a8 --- /dev/null +++ b/assets/check @@ -0,0 +1,3 @@ +#!/bin/bash + +/bin/github-pr-comment check $@ diff --git a/assets/in b/assets/in new file mode 100644 index 0000000..415782f --- /dev/null +++ b/assets/in @@ -0,0 +1,3 @@ +#!/bin/bash + +/bin/github-pr-comment in $1 diff --git a/assets/out b/assets/out new file mode 100644 index 0000000..0d71057 --- /dev/null +++ b/assets/out @@ -0,0 +1,3 @@ +#!/bin/bash + +/bin/github-pr-comment out $1 diff --git a/cmd/root.go b/cmd/root.go new file mode 100644 index 0000000..2382656 --- /dev/null +++ b/cmd/root.go @@ -0,0 +1,75 @@ +// SPDX-License-Identifier: BSD-3-Clause +// +// Authors: Alexander Jung +// +// Copyright (c) 2020, Alexander Jung. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +package cmd + +import ( + "os" + "fmt" + + "github.com/spf13/cobra" + "github.com/nderjung/concourse-github-pr-comment-resource/actions" +) + + +// rootCmd represents the base command when called without any subcommands +var rootCmd = &cobra.Command{ + // Use: "", + Use: "github-pr-comment [OPTIONS] [COMMANDS]", + Short: `Concourse Resouce to act on Github PR comments.`, + TraverseChildren: true, + Run: doRootCmd, +} + +// Execute adds all child commands to the root command and sets flags +// appropriately. +func Execute() { + if err := rootCmd.Execute(); err != nil { + fmt.Println(err) + os.Exit(1) + } +} + +func doRootCmd(cmd *cobra.Command, args []string) { + printVersionFlag, err := cmd.PersistentFlags().GetBool("version") + if err == nil && printVersionFlag { + printVersion(cmd, args) + os.Exit(0) + } +} + + +func init() { + rootCmd.PersistentFlags().BoolP("version", "v", false, "Display version number") + + rootCmd.AddCommand(actions.CheckCmd) + rootCmd.AddCommand(actions.InCmd) + rootCmd.AddCommand(actions.OutCmd) +} diff --git a/cmd/version.go b/cmd/version.go new file mode 100644 index 0000000..780c4cb --- /dev/null +++ b/cmd/version.go @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: BSD-3-Clause +// +// Authors: Alexander Jung +// +// Copyright (c) 2020, Alexander Jung. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +type Version struct { + Version string + Commit string + BuildTime string +} + +var version *Version + +func SetVersion(v *Version) { + version = v +} + +func printVersion(cmd *cobra.Command, args []string) { + fmt.Printf("github-pr-comment %s\n", version.Version) +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..5bf8136 --- /dev/null +++ b/go.mod @@ -0,0 +1,10 @@ +module github.com/nderjung/concourse-github-pr-comment-resource + +go 1.15 + +require ( + github.com/google/go-github v17.0.0+incompatible + github.com/google/go-github/v32 v32.1.0 + github.com/spf13/cobra v1.1.1 + golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..964218a --- /dev/null +++ b/go.sum @@ -0,0 +1,295 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= +cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= +cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= +cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= +cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= +cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= +cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= +cloud.google.com/go/firestore v1.1.0/go.mod h1:ulACoGHTpvq5r8rxGJ4ddJZBZqakUQqClKRT5SZwBmk= +cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= +cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= +dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= +github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= +github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= +github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= +github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= +github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= +github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= +github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= +github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= +github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= +github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= +github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= +github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= +github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= +github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= +github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= +github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= +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.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY= +github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ= +github.com/google/go-github/v32 v32.1.0 h1:GWkQOdXqviCPx7Q7Fj+KyPoGm4SwHRh8rheoPhd27II= +github.com/google/go-github/v32 v32.1.0/go.mod h1:rIEpZD9CTDQwDK9GDrtMTycQNA4JU3qBsCizh3q2WCI= +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/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= +github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= +github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= +github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= +github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= +github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= +github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q= +github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= +github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= +github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= +github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= +github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= +github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU= +github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU= +github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4= +github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90= +github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= +github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= +github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= +github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= +github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= +github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= +github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= +github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= +github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= +github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +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/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= +github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= +github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= +github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= +github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= +github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= +github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg= +github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY= +github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= +github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= +github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= +github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= +github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= +github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= +github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= +github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= +github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= +github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= +github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= +github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= +github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= +github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= +github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= +github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= +github.com/spf13/cobra v1.1.1 h1:KfztREH0tPxJJ+geloSLaAkaPkr4ki2Er5quFV1TDo4= +github.com/spf13/cobra v1.1.1/go.mod h1:WnodtKOvamDL/PwE2M4iKs8aMDBZ5Q5klgD3qfVJQMI= +github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= +github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= +github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= +go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= +go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= +go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= +go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= +go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5 h1:58fnuSXlxZmFdJyvtTFVmVhcMLU6v5fEb/ok4wyqtNU= +golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= +golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= +golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= +golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= +golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= +golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= +golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= +golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181220203305-927f97764cc3/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-20190213061140-3a22650c66bd/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-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/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 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0= +golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/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/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= +google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= +google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +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= +google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= +google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= +google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= +gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= +gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= +rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= diff --git a/main.go b/main.go new file mode 100644 index 0000000..5c0f964 --- /dev/null +++ b/main.go @@ -0,0 +1,52 @@ +package main +/* SPDX-License-Identifier: BSD-3-Clause */ +/* + * Authors: Alexander Jung + * + * Copyright (c) 2020, Alexander Jung. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +import ( + "github.com/nderjung/concourse-github-pr-comment-resource/cmd" +) + +var ( + version = "No version provided" + commit = "No commit provided" + buildTime = "No build timestamp provided" +) + +func main() { + cmd.SetVersion(&cmd.Version{ + Version: version, + Commit: commit, + BuildTime: buildTime, + }) + + cmd.Execute() +}