diff --git a/.gitignore b/.gitignore index 947c90cd..45803faa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,5 @@ # Binaries build/* -# Taskfile -.task - -# Task installation in Travis -bin/task - # Editor .idea/ diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index d9698cfd..00000000 --- a/.travis.yml +++ /dev/null @@ -1,13 +0,0 @@ -language: go -sudo: false -matrix: - include: - - os: osx - go: 1.14.x - - os: linux - go: 1.14.x -notifications: - email: false -script: -- curl -sL https://taskfile.dev/install.sh | sh -- ./bin/task ci diff --git a/CODEOWNERS b/CODEOWNERS index 3d6b4d64..5276aa95 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -1,2 +1,3 @@ # Default. Unless we have a more specific match. * @telia-oss/golang +* @gstackio/staff diff --git a/Dockerfile b/Dockerfile index 9fd206cb..79d23ff4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,31 @@ -FROM golang:1.21.6 AS builder +ARG golang="golang:1.21.6" +ARG alpine="alpine:3.19.1" + + +FROM ${golang} AS builder + +ENV DEBIAN_FRONTEND=noninteractive +RUN apt-get -y -qq update \ + && apt-get -y -qq install "make" + ADD . /go/src/github.com/telia-oss/github-pr-resource WORKDIR /go/src/github.com/telia-oss/github-pr-resource -RUN curl -sL https://taskfile.dev/install.sh | sh /dev/stdin v3.33.1 -RUN ./bin/task build -FROM alpine:3.19.1 AS resource -COPY --from=builder /go/src/github.com/telia-oss/github-pr-resource/build /opt/resource +RUN go version \ + && make all + + +FROM ${alpine} AS resource RUN apk add --update --no-cache \ git \ git-lfs \ openssh \ - git-crypt \ - && chmod +x /opt/resource/* + git-crypt COPY scripts/askpass.sh /usr/local/bin/askpass.sh +COPY --from=builder /go/src/github.com/telia-oss/github-pr-resource/build /opt/resource +RUN chmod +x /opt/resource/* + + FROM resource -LABEL MAINTAINER=telia-oss +LABEL MAINTAINER=orange-cloudfoundry diff --git a/Makefile b/Makefile index 675d27c0..56fad148 100644 --- a/Makefile +++ b/Makefile @@ -16,10 +16,13 @@ e2e: test go test -race -v ./... -tags=e2e check: cmd/check/main.go + CGO_ENABLED=0 \ go build -o "build/check" -ldflags="-s -w" -v "cmd/check/main.go" in: cmd/in/main.go + CGO_ENABLED=0 \ go build -o "build/in" -ldflags="-s -w" -v "cmd/in/main.go" out: cmd/out/main.go + CGO_ENABLED=0 \ go build -o "build/out" -ldflags="-s -w" -v "cmd/out/main.go" diff --git a/README.md b/README.md index 8994e9d0..52346031 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,24 @@ Inspired by [the original][original-resource], with some important differences: Make sure to check out [#migrating](#migrating) to learn more. + +### Maintainance notice + +This project is a fork of [telia-oss/github-pr-resource][telia_repo], which +hasn't received any maintenance for years, as telia-oss/github-pr-resource#246 +can testify and explain. + +As exmplained in [this comment][maintainance_takeover_comment], the project +here is to take over the maintenance, merge [pending contributions][pending_contributions] +that have been submitted as PRs to the original repo and bring significant +features, and at some point build a solution for a growing code base of +automated tests. + +[telia_repo]: https://github.com/telia-oss/github-pr-resource +[maintainance_takeover_comment]: https://github.com/telia-oss/github-pr-resource/issues/246#issuecomment-2105230468 +[pending_contributions]: https://github.com/telia-oss/github-pr-resource/pulls + + ## Source Configuration | Parameter | Required | Example | Description | @@ -84,8 +102,16 @@ input. Because the base of the PR is not locked to a specific commit in versions requested version and the metadata emitted by `get` are available to your tasks as JSON: - `.git/resource/version.json` - `.git/resource/metadata.json` +- `.git/resource/metadata-map.json` - `.git/resource/changed_files` (if enabled by `list_changed_files`) +The `metadata.json` file contains an array of objects, one for each key-value +pair, with a `name` key and a `value` key. In order to support the +[`load_var` step][load_var_step], another `metadata-map.json` provides the +same informtion with a plain key-value format. + +[load_var_step]: https://concourse-ci.org/load-var-step.html + The information in `metadata.json` is also available as individual files in the `.git/resource` directory, e.g. the `base_sha` is available as `.git/resource/base_sha`. For a complete list of available (individual) metadata files, please check the code [here](https://github.com/telia-oss/github-pr-resource/blob/master/in.go#L66). @@ -94,6 +120,7 @@ is available as `.git/resource/base_sha`. For a complete list of available (indi - `author_email`: the e-mail address of the pull request author - `base_name`: the base branch of the pull request - `base_sha`: the commit of the base branch of the pull request +- `body`: the description of the pull request - `head_name`: the branch associated with the pull request - `head_sha`: the latest commit hash of the branch associated with the pull request - `message`: the message of the last commit of the pull request, as designated by `head_sha` @@ -265,13 +292,16 @@ If you are coming from [jtarchie/github-pullrequest-resource][original-resource] #### Metadata stored in the `.git` directory The original resource stores [a bunch of metadata][metadata] related to the -pull request as `git config`, or plain files in the `.git` directory. This -resource provide most metadata with possibly different names, and the files -are to be found in the `.git/reource` directory. +pull request as entries in `.git/config`, or plain files in the `.git/` +directory. + +This resource provide all these metadata, but with possibly different names, +and only as files to be found in the `.git/resource` directory. -If you were using the metadata stored in Git config, you need to update your -code. For example `git config --get pullrequest.url` in some Bash code can be -replaced by `echo $(< .git/resource/url)`. +With this resource, no entry is added to the `.git/config` file. If you were +using the metadata stored in Git config, you need to update your code. For +example `git config --get pullrequest.url` in some Bash code can be replaced +by `echo $(< .git/resource/url)`. Here is the list of changes: @@ -282,7 +312,7 @@ Here is the list of changes: - `.git/branch` -> `.git/resource/head_name` - `.git/head_sha` -> `.git/resource/head_sha` - `.git/userlogin` -> `.git/resource/author` -- `.git/body` -> _no equivalent_ +- `.git/body` -> `.git/resource/body` [metadata]: https://github.com/jtarchie/github-pullrequest-resource#in-clone-the-repository-at-the-given-pull-request-ref diff --git a/Taskfile.yml b/Taskfile.yml deleted file mode 100644 index 6197a975..00000000 --- a/Taskfile.yml +++ /dev/null @@ -1,66 +0,0 @@ -version: '2' - -vars: - BUILD_DIR: build - DOCKER_REPO: loggregatorbot/github-pr-resource - -tasks: - default: - cmds: - - task: test - - generate: - desc: Generate test fakes - cmds: - - go generate ./... - sources: - - github.go - - git.go - generates: - - fakes/*.go - method: checksum - - test: - desc: Run test suite - deps: [generate] - cmds: - - gofmt -s -l -w . - - go vet -v ./... - - go test -race -v ./... - - e2e: - desc: Run E2E test suite - cmds: - - task: test - - go test -race -v ./... -tags=e2e - - docker: - desc: Build docker image under dev tag. - cmds: - - docker build -t {{.DOCKER_REPO}}:dev . - - build: - desc: Build check/in/out artifacts - cmds: - - task: test - - task: go-build - vars: {BINARY: check} - - task: go-build - vars: {BINARY: in} - - task: go-build - vars: {BINARY: out} - - go-build: - cmds: - - go build -o {{.BUILD_DIR}}/{{.BINARY}}{{exeExt}} -ldflags="-s -w" -v cmd/{{.BINARY}}/main.go - env: - CGO_ENABLED: '0' - GOOS: '{{OS}}' - GOARCH: '{{ARCH}}' - - ci: - desc: CI build and tests - cmds: - - task: build - - if [ -n "$(git status --porcelain)" ];then echo "Diff in generated files and/or formatting" && exit 1; fi - silent: true diff --git a/ci/pipeline.yml b/ci/pipeline.yml index c9191192..43694fb3 100644 --- a/ci/pipeline.yml +++ b/ci/pipeline.yml @@ -60,8 +60,8 @@ meta: fail_moji: ":airplane_arriving:" upset_moji: ":sadpanda:" pipeline_url: (( concat meta.url "/teams/${BUILD_TEAM_NAME}/pipelines/${BUILD_PIPELINE_NAME}" )) - fail_link: (( concat "<" meta.slack.pipeline_url "/jobs/${BUILD_JOB_NAME}/builds/${BUILD_NAME}| Concourse Failure! " meta.slack.upset_moji ">" )) - fail_text: '(( concat meta.slack.fail_link " " meta.pipeline ": `${BUILD_JOB_NAME}` job failed" ))' + fail_link: (( concat "<" meta.slack.pipeline_url "/jobs/${BUILD_JOB_NAME}/builds/${BUILD_NAME}| Let's go fix it!>" )) + fail_text: '(( concat meta.pipeline ": `${BUILD_JOB_NAME}` job has failed " meta.slack.upset_moji " " meta.slack.fail_link " :hammer_and_wrench:" ))' groups: - name: (( grab meta.name )) @@ -102,6 +102,7 @@ jobs: on_failure: put: notify + no_get: true params: channel: (( grab meta.slack.channel )) username: (( grab meta.slack.username )) @@ -170,6 +171,7 @@ jobs: on_success: put: notify + no_get: true params: channel: (( grab meta.slack.channel )) username: (( grab meta.slack.username )) @@ -213,6 +215,7 @@ jobs: params: { file: version/number } on_failure: put: notify + no_get: true params: channel: (( grab meta.slack.channel )) username: (( grab meta.slack.username )) @@ -227,6 +230,7 @@ jobs: - { put: version, params: { file: version/number } } on_failure: put: notify + no_get: true params: channel: (( grab meta.slack.channel )) username: (( grab meta.slack.username )) @@ -241,6 +245,7 @@ jobs: - { put: version, params: { file: version/number } } on_failure: put: notify + no_get: true params: channel: (( grab meta.slack.channel )) username: (( grab meta.slack.username )) @@ -317,6 +322,7 @@ jobs: body: gh/notes.md on_failure: put: notify + no_get: true params: channel: (( grab meta.slack.channel )) username: (( grab meta.slack.username )) diff --git a/ci/release_notes.md b/ci/release_notes.md deleted file mode 100644 index 5bc7e4ff..00000000 --- a/ci/release_notes.md +++ /dev/null @@ -1,4 +0,0 @@ -### Improvements - -- Bumped the [go-github](https://github.com/google/go-github) API to v58, the latest available. -- Bumped other Go dependencies to latest versions. diff --git a/ci/settings.yml b/ci/settings.yml index 119a0baa..5662ec98 100644 --- a/ci/settings.yml +++ b/ci/settings.yml @@ -161,18 +161,22 @@ jobs: | xargs -0 -I{} cp -a {} "repo-bumped" cd "repo-bumped" || exit 115 - awk '/^go /{print $2}' go.mod > ../golang-info/previous-version + awk '/^toolchain /{sub(/go/,"",$2); print $2}' go.mod \ + > ../golang-info/previous-version + ( set -x - go_version=$( - go version \ - | awk '{sub(/go/,"",$3); sub(/\.[[:digit:]]+$/,"",$3); print $3}' - ) - sed -i -Ee "s/^go [[:digit:].]+\$/go ${go_version}/" go.mod + toolchain_version=$(go version | awk '{print $3}') + go_version=${toolchain_version#"go"} + inferred_go_min_version="${go_version%.*}.0" + sed -i -Ee "s/^go [[:digit:].]+\$/go ${inferred_go_min_version}/" go.mod + sed -i -Ee "s/^toolchain go[[:digit:].]+\$/toolchain ${toolchain_version}/" go.mod go get -t -u ./... go mod tidy - echo "${go_version}" > ../golang-info/version + echo "${toolchain_version}" > ../golang-info/toolchain-version + echo "${go_version}" > ../golang-info/version + echo "${inferred_go_min_version}" > ../golang-info/min-version ) - task: build-docker-image @@ -188,6 +192,7 @@ jobs: caches: [ path: cache ] run: { path: build } params: + DEBUG: true IMAGE_ARG_golang: golang-latest/image.tar IMAGE_ARG_alpine: alpine-latest/image.tar output_mapping: @@ -245,6 +250,7 @@ jobs: on_failure: put: notify + no_get: true params: channel: (( grab meta.slack.channel )) username: (( grab meta.slack.username )) @@ -252,6 +258,7 @@ jobs: text: (( grab meta.slack.fail_text )) on_success: put: notify + no_get: true params: channel: (( grab meta.slack.channel )) username: (( grab meta.slack.username )) diff --git a/e2e/e2e_test.go b/e2e/e2e_test.go index 0cb7beb8..15fbe71b 100644 --- a/e2e/e2e_test.go +++ b/e2e/e2e_test.go @@ -17,7 +17,7 @@ import ( resource "github.com/telia-oss/github-pr-resource" - "github.com/google/go-github/v42/github" + "github.com/google/go-github/v61/github" "github.com/shurcooL/githubv4" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/github.go b/github.go index e73df8a5..c1410aa9 100644 --- a/github.go +++ b/github.go @@ -12,7 +12,7 @@ import ( "strconv" "strings" - "github.com/google/go-github/v58/github" + "github.com/google/go-github/v61/github" "github.com/shurcooL/githubv4" "golang.org/x/oauth2" ) @@ -435,7 +435,7 @@ func (m *GithubClient) DeletePreviousComments(prNumber string) error { } for _, e := range getComments.Repository.PullRequest.Comments.Edges { - if e.Node.Author.Login == getComments.Viewer.Login { + if cleanBotUserName(e.Node.Author.Login) == cleanBotUserName(getComments.Viewer.Login) { _, err := m.V3.Issues.DeleteComment(context.TODO(), m.Owner, m.Repository, e.Node.DatabaseId) if err != nil { return err @@ -453,3 +453,10 @@ func parseRepository(s string) (string, string, error) { } return parts[0], parts[1], nil } + +func cleanBotUserName(username string) string { + if strings.HasSuffix(username, "[bot]") { + return strings.TrimSuffix(username, "[bot]") + } + return username +} diff --git a/github_test.go b/github_test.go index 58a419d2..84e22d07 100644 --- a/github_test.go +++ b/github_test.go @@ -25,3 +25,50 @@ func TestListTeamMembers(t *testing.T) { require.Contains(t, val, "thelinuxfoundation") } + +func Test_cleanBotUserName(t *testing.T) { + type args struct { + username string + } + tests := []struct { + name string + args args + want string + }{ + { + name: "Main Test Case", + args: args{ + username: "infratest[bot]", + }, + want: "infratest", + }, + { + name: "Without suffix bot", + args: args{ + username: "infratest", + }, + want: "infratest", + }, + { + name: "Bot only", + args: args{ + username: "[bot]", + }, + want: "", + }, + { + name: "Bot at start", + args: args{ + username: "[bot]infratest", + }, + want: "[bot]infratest", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := cleanBotUserName(tt.args.username); got != tt.want { + t.Errorf("cleanBotUserName() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/go.mod b/go.mod index 9ece34d9..19c7075f 100644 --- a/go.mod +++ b/go.mod @@ -1,27 +1,26 @@ module github.com/telia-oss/github-pr-resource require ( - github.com/google/go-github/v42 v42.0.0 - github.com/google/go-github/v58 v58.0.0 + github.com/google/go-github/v61 v61.0.0 github.com/maxbrunsfeld/counterfeiter/v6 v6.4.1 - github.com/shurcooL/githubv4 v0.0.0-20240120211514-18a1ae0e79dc - github.com/stretchr/testify v1.8.4 - golang.org/x/oauth2 v0.16.0 + github.com/shurcooL/githubv4 v0.0.0-20240429030203-be2daab69064 + github.com/stretchr/testify v1.9.0 + golang.org/x/oauth2 v0.20.0 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect - github.com/golang/protobuf v1.5.3 // indirect github.com/google/go-querystring v1.1.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/shurcooL/graphql v0.0.0-20230722043721-ed46e5a46466 // indirect - golang.org/x/crypto v0.18.0 // indirect - golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect + golang.org/x/mod v0.8.0 // indirect + golang.org/x/net v0.10.0 // indirect golang.org/x/sys v0.16.0 // indirect - golang.org/x/tools v0.1.12 // indirect - google.golang.org/appengine v1.6.8 // indirect - google.golang.org/protobuf v1.32.0 // indirect + golang.org/x/text v0.14.0 // indirect + golang.org/x/tools v0.6.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) -go 1.21 +go 1.21.0 + +toolchain go1.21.10 diff --git a/go.sum b/go.sum index bde97900..83d07a69 100644 --- a/go.sum +++ b/go.sum @@ -8,21 +8,14 @@ github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrU github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= -github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/go-github/v42 v42.0.0 h1:YNT0FwjPrEysRkLIiKuEfSvBPCGKphW5aS5PxwaoLec= -github.com/google/go-github/v42 v42.0.0/go.mod h1:jgg/jvyI0YlDOM1/ps6XYh04HNQ3vKf0CVko62/EhRg= -github.com/google/go-github/v58 v58.0.0 h1:Una7GGERlF/37XfkPwpzYJe0Vp4dt2k1kCjlxwjIvzw= -github.com/google/go-github/v58 v58.0.0/go.mod h1:k4hxDKEfoWpSqFlc8LTpGd9fu2KrV1YAa6Hi6FmDNY4= +github.com/google/go-github/v61 v61.0.0 h1:VwQCBwhyE9JclCI+22/7mLB1PuU9eowCXKY5pNlu1go= +github.com/google/go-github/v61 v61.0.0/go.mod h1:0WR+KmsWX75G2EbpyGsGmradjo3IiciuI4BmdVCobQY= github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= @@ -43,39 +36,34 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sclevine/spec v1.4.0 h1:z/Q9idDcay5m5irkZ28M7PtQM4aOISzOpj4bUPkDee8= github.com/sclevine/spec v1.4.0/go.mod h1:LvpgJaFyvQzRvc1kaDs0bulYwzC70PbiYjC4QnFHkOM= -github.com/shurcooL/githubv4 v0.0.0-20240120211514-18a1ae0e79dc h1:vH0NQbIDk+mJLvBliNGfcQgUmhlniWBDXC79oRxfZA0= -github.com/shurcooL/githubv4 v0.0.0-20240120211514-18a1ae0e79dc/go.mod h1:zqMwyHmnN/eDOZOdiTohqIUKUrTFX62PNlu7IJdu0q8= +github.com/shurcooL/githubv4 v0.0.0-20240429030203-be2daab69064 h1:RCQBSFx5JrsbHltqTtJ+kN3U0Y3a/N/GlVdmRSoxzyE= +github.com/shurcooL/githubv4 v0.0.0-20240429030203-be2daab69064/go.mod h1:zqMwyHmnN/eDOZOdiTohqIUKUrTFX62PNlu7IJdu0q8= github.com/shurcooL/graphql v0.0.0-20230722043721-ed46e5a46466 h1:17JxqqJY66GmZVHkmAsGEkcIu0oCe3AM420QDgGwZx0= github.com/shurcooL/graphql v0.0.0-20230722043721-ed46e5a46466/go.mod h1:9dIRpgIY7hVhoqfe0/FcYp0bpInZaT7dc3BYOprrIUE= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc= -golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210331212208-0fccb6fa2b5c/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo= -golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= -golang.org/x/oauth2 v0.16.0 h1:aDkGMBSYxElaoP81NpoUoz2oo2R2wHdZpGToUxfyQrQ= -golang.org/x/oauth2 v0.16.0/go.mod h1:hqZ+0LWXsiVoZpeld6jVt06P3adbS2Uu911W1SsJv2o= +golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= +golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/oauth2 v0.20.0 h1:4mQdhULixXKP1rwYBW0vAijoXnkTG0BLCDRzfe1idMo= +golang.org/x/oauth2 v0.20.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/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-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -85,41 +73,29 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= -golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM= -google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I= -google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b h1:QRR6H1YWRnHb4Y/HeNFCTJLFVxaq6wH4YuVdsUOr75U= gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/in.go b/in.go index fa0eb242..7fae4400 100644 --- a/in.go +++ b/in.go @@ -43,6 +43,7 @@ func Get(request GetRequest, github Github, git Git, outputDir string) (*GetResp var metadata Metadata metadata.Add("pr", strconv.Itoa(pull.Number)) metadata.Add("title", pull.Title) + metadata.Add("body", pull.Body) metadata.Add("url", pull.URL) metadata.Add("head_name", pull.HeadRefName) metadata.Add("head_sha", pull.Tip.OID) @@ -81,6 +82,17 @@ func Get(request GetRequest, github Github, git Git, outputDir string) (*GetResp } } + metadataMap := make(map[string]string) + for _, d := range metadata { + metadataMap[d.Name] = d.Value + } + if b, err = json.Marshal(metadataMap); err != nil { + return nil, fmt.Errorf("failed to marshal map of metadata: %s", err) + } + if err := ioutil.WriteFile(filepath.Join(path, "metadata-map.json"), b, 0644); err != nil { + return nil, fmt.Errorf("failed to write metadata map file: %s", err) + } + switch tool := request.Params.IntegrationTool; tool { case "rebase": if err := git.Rebase(pull.BaseRefName, pull.Tip.OID, request.Params.Submodules); err != nil { diff --git a/in_test.go b/in_test.go index ce0b0b34..f4a6089a 100644 --- a/in_test.go +++ b/in_test.go @@ -17,15 +17,16 @@ import ( func TestGet(t *testing.T) { tests := []struct { - description string - source resource.Source - version resource.Version - parameters resource.GetParameters - pullRequest *resource.PullRequest - versionString string - metadataString string - files []resource.ChangedFileObject - filesString string + description string + source resource.Source + version resource.Version + parameters resource.GetParameters + pullRequest *resource.PullRequest + versionString string + metadataString string + metadataMapString string + files []resource.ChangedFileObject + filesString string }{ { description: "get works", @@ -39,10 +40,11 @@ func TestGet(t *testing.T) { CommittedDate: time.Time{}, State: githubv4.PullRequestStateOpen, }, - parameters: resource.GetParameters{}, - pullRequest: createTestPR(1, "master", "anonymous", false, false, 0, nil, false, githubv4.PullRequestStateOpen), - versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z","state":"OPEN"}`, - metadataString: `[{"name":"pr","value":"1"},{"name":"title","value":"pr1 title"},{"name":"url","value":"pr1 url"},{"name":"head_name","value":"pr1"},{"name":"head_sha","value":"oid1"},{"name":"base_name","value":"master"},{"name":"base_sha","value":"sha"},{"name":"message","value":"commit message1"},{"name":"author","value":"login1"},{"name":"author_email","value":"user@example.com"},{"name":"state","value":"OPEN"}]`, + parameters: resource.GetParameters{}, + pullRequest: createTestPR(1, "master", "anonymous", false, false, 0, nil, false, githubv4.PullRequestStateOpen), + versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z","state":"OPEN"}`, + metadataString: `[{"name":"pr","value":"1"},{"name":"title","value":"pr1 title"},{"name":"body","value":"pr1 body"},{"name":"url","value":"pr1 url"},{"name":"head_name","value":"pr1"},{"name":"head_sha","value":"oid1"},{"name":"base_name","value":"master"},{"name":"base_sha","value":"sha"},{"name":"message","value":"commit message1"},{"name":"author","value":"login1"},{"name":"author_email","value":"user@example.com"},{"name":"state","value":"OPEN"}]`, + metadataMapString: `{"author":"login1","author_email":"user@example.com","base_name":"master","base_sha":"sha","body":"pr1 body","head_name":"pr1","head_sha":"oid1","message":"commit message1","pr":"1","state":"OPEN","title":"pr1 title","url":"pr1 url"}`, }, { description: "get supports unlocking with git crypt", @@ -57,10 +59,11 @@ func TestGet(t *testing.T) { CommittedDate: time.Time{}, State: githubv4.PullRequestStateOpen, }, - parameters: resource.GetParameters{}, - pullRequest: createTestPR(1, "master", "anonymous", false, false, 0, nil, false, githubv4.PullRequestStateOpen), - versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z","state":"OPEN"}`, - metadataString: `[{"name":"pr","value":"1"},{"name":"title","value":"pr1 title"},{"name":"url","value":"pr1 url"},{"name":"head_name","value":"pr1"},{"name":"head_sha","value":"oid1"},{"name":"base_name","value":"master"},{"name":"base_sha","value":"sha"},{"name":"message","value":"commit message1"},{"name":"author","value":"login1"},{"name":"author_email","value":"user@example.com"},{"name":"state","value":"OPEN"}]`, + parameters: resource.GetParameters{}, + pullRequest: createTestPR(1, "master", "anonymous", false, false, 0, nil, false, githubv4.PullRequestStateOpen), + versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z","state":"OPEN"}`, + metadataString: `[{"name":"pr","value":"1"},{"name":"title","value":"pr1 title"},{"name":"body","value":"pr1 body"},{"name":"url","value":"pr1 url"},{"name":"head_name","value":"pr1"},{"name":"head_sha","value":"oid1"},{"name":"base_name","value":"master"},{"name":"base_sha","value":"sha"},{"name":"message","value":"commit message1"},{"name":"author","value":"login1"},{"name":"author_email","value":"user@example.com"},{"name":"state","value":"OPEN"}]`, + metadataMapString: `{"author":"login1","author_email":"user@example.com","base_name":"master","base_sha":"sha","body":"pr1 body","head_name":"pr1","head_sha":"oid1","message":"commit message1","pr":"1","state":"OPEN","title":"pr1 title","url":"pr1 url"}`, }, { description: "get supports rebasing", @@ -77,9 +80,10 @@ func TestGet(t *testing.T) { parameters: resource.GetParameters{ IntegrationTool: "rebase", }, - pullRequest: createTestPR(1, "master", "anonymous", false, false, 0, nil, false, githubv4.PullRequestStateOpen), - versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z","state":"OPEN"}`, - metadataString: `[{"name":"pr","value":"1"},{"name":"title","value":"pr1 title"},{"name":"url","value":"pr1 url"},{"name":"head_name","value":"pr1"},{"name":"head_sha","value":"oid1"},{"name":"base_name","value":"master"},{"name":"base_sha","value":"sha"},{"name":"message","value":"commit message1"},{"name":"author","value":"login1"},{"name":"author_email","value":"user@example.com"},{"name":"state","value":"OPEN"}]`, + pullRequest: createTestPR(1, "master", "anonymous", false, false, 0, nil, false, githubv4.PullRequestStateOpen), + versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z","state":"OPEN"}`, + metadataString: `[{"name":"pr","value":"1"},{"name":"title","value":"pr1 title"},{"name":"body","value":"pr1 body"},{"name":"url","value":"pr1 url"},{"name":"head_name","value":"pr1"},{"name":"head_sha","value":"oid1"},{"name":"base_name","value":"master"},{"name":"base_sha","value":"sha"},{"name":"message","value":"commit message1"},{"name":"author","value":"login1"},{"name":"author_email","value":"user@example.com"},{"name":"state","value":"OPEN"}]`, + metadataMapString: `{"author":"login1","author_email":"user@example.com","base_name":"master","base_sha":"sha","body":"pr1 body","head_name":"pr1","head_sha":"oid1","message":"commit message1","pr":"1","state":"OPEN","title":"pr1 title","url":"pr1 url"}`, }, { description: "get supports checkout", @@ -96,9 +100,10 @@ func TestGet(t *testing.T) { parameters: resource.GetParameters{ IntegrationTool: "checkout", }, - pullRequest: createTestPR(1, "master", "anonymous", false, false, 0, nil, false, githubv4.PullRequestStateOpen), - versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z","state":"OPEN"}`, - metadataString: `[{"name":"pr","value":"1"},{"name":"title","value":"pr1 title"},{"name":"url","value":"pr1 url"},{"name":"head_name","value":"pr1"},{"name":"head_sha","value":"oid1"},{"name":"base_name","value":"master"},{"name":"base_sha","value":"sha"},{"name":"message","value":"commit message1"},{"name":"author","value":"login1"},{"name":"author_email","value":"user@example.com"},{"name":"state","value":"OPEN"}]`, + pullRequest: createTestPR(1, "master", "anonymous", false, false, 0, nil, false, githubv4.PullRequestStateOpen), + versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z","state":"OPEN"}`, + metadataString: `[{"name":"pr","value":"1"},{"name":"title","value":"pr1 title"},{"name":"body","value":"pr1 body"},{"name":"url","value":"pr1 url"},{"name":"head_name","value":"pr1"},{"name":"head_sha","value":"oid1"},{"name":"base_name","value":"master"},{"name":"base_sha","value":"sha"},{"name":"message","value":"commit message1"},{"name":"author","value":"login1"},{"name":"author_email","value":"user@example.com"},{"name":"state","value":"OPEN"}]`, + metadataMapString: `{"author":"login1","author_email":"user@example.com","base_name":"master","base_sha":"sha","body":"pr1 body","head_name":"pr1","head_sha":"oid1","message":"commit message1","pr":"1","state":"OPEN","title":"pr1 title","url":"pr1 url"}`, }, { description: "get supports git_depth", @@ -115,9 +120,10 @@ func TestGet(t *testing.T) { parameters: resource.GetParameters{ GitDepth: 2, }, - pullRequest: createTestPR(1, "master", "anonymous", false, false, 0, nil, false, githubv4.PullRequestStateOpen), - versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z","state":"OPEN"}`, - metadataString: `[{"name":"pr","value":"1"},{"name":"title","value":"pr1 title"},{"name":"url","value":"pr1 url"},{"name":"head_name","value":"pr1"},{"name":"head_sha","value":"oid1"},{"name":"base_name","value":"master"},{"name":"base_sha","value":"sha"},{"name":"message","value":"commit message1"},{"name":"author","value":"login1"},{"name":"author_email","value":"user@example.com"},{"name":"state","value":"OPEN"}]`, + pullRequest: createTestPR(1, "master", "anonymous", false, false, 0, nil, false, githubv4.PullRequestStateOpen), + versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z","state":"OPEN"}`, + metadataString: `[{"name":"pr","value":"1"},{"name":"title","value":"pr1 title"},{"name":"body","value":"pr1 body"},{"name":"url","value":"pr1 url"},{"name":"head_name","value":"pr1"},{"name":"head_sha","value":"oid1"},{"name":"base_name","value":"master"},{"name":"base_sha","value":"sha"},{"name":"message","value":"commit message1"},{"name":"author","value":"login1"},{"name":"author_email","value":"user@example.com"},{"name":"state","value":"OPEN"}]`, + metadataMapString: `{"author":"login1","author_email":"user@example.com","base_name":"master","base_sha":"sha","body":"pr1 body","head_name":"pr1","head_sha":"oid1","message":"commit message1","pr":"1","state":"OPEN","title":"pr1 title","url":"pr1 url"}`, }, { description: "get supports list_changed_files", @@ -143,9 +149,10 @@ func TestGet(t *testing.T) { Path: "Other.md", }, }, - versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z","state":"OPEN"}`, - metadataString: `[{"name":"pr","value":"1"},{"name":"title","value":"pr1 title"},{"name":"url","value":"pr1 url"},{"name":"head_name","value":"pr1"},{"name":"head_sha","value":"oid1"},{"name":"base_name","value":"master"},{"name":"base_sha","value":"sha"},{"name":"message","value":"commit message1"},{"name":"author","value":"login1"},{"name":"author_email","value":"user@example.com"},{"name":"state","value":"OPEN"}]`, - filesString: "README.md\nOther.md\n", + versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z","state":"OPEN"}`, + metadataString: `[{"name":"pr","value":"1"},{"name":"title","value":"pr1 title"},{"name":"body","value":"pr1 body"},{"name":"url","value":"pr1 url"},{"name":"head_name","value":"pr1"},{"name":"head_sha","value":"oid1"},{"name":"base_name","value":"master"},{"name":"base_sha","value":"sha"},{"name":"message","value":"commit message1"},{"name":"author","value":"login1"},{"name":"author_email","value":"user@example.com"},{"name":"state","value":"OPEN"}]`, + metadataMapString: `{"author":"login1","author_email":"user@example.com","base_name":"master","base_sha":"sha","body":"pr1 body","head_name":"pr1","head_sha":"oid1","message":"commit message1","pr":"1","state":"OPEN","title":"pr1 title","url":"pr1 url"}`, + filesString: "README.md\nOther.md\n", }, } @@ -178,6 +185,9 @@ func TestGet(t *testing.T) { metadata := readTestFile(t, filepath.Join(dir, ".git", "resource", "metadata.json")) assert.Equal(t, tc.metadataString, metadata) + metadataMap := readTestFile(t, filepath.Join(dir, ".git", "resource", "metadata-map.json")) + assert.Equal(t, tc.metadataMapString, metadataMap) + // Verify individual files files := map[string]string{ "pr": "1", @@ -190,6 +200,7 @@ func TestGet(t *testing.T) { "author": "login1", "author_email": "user@example.com", "title": "pr1 title", + "body": "pr1 body", } for filename, expected := range files { @@ -343,6 +354,7 @@ func createTestPR( ID: fmt.Sprintf("pr%s", n), Number: count, Title: fmt.Sprintf("pr%s title", n), + Body: fmt.Sprintf("pr%s body", n), URL: fmt.Sprintf("pr%s url", n), BaseRefName: baseName, HeadRefName: fmt.Sprintf("pr%s", n), diff --git a/models.go b/models.go index 8372fcfe..6695308f 100644 --- a/models.go +++ b/models.go @@ -103,6 +103,7 @@ type PullRequestObject struct { ID string Number int Title string + Body string URL string BaseRefName string HeadRefName string