Skip to content

Commit

Permalink
Merge pull request #8 from cloudfoundry-community/pr-body-metadata
Browse files Browse the repository at this point in the history
Add PR body in the metadata provided by 'get' steps
  • Loading branch information
bgandon authored May 11, 2024
2 parents a58f6c2 + df17544 commit 4f80193
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 19 deletions.
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,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`
Expand Down Expand Up @@ -291,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.

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)`.
This resource provide all these metadata, but with possibly different names,
and only as files to be found in the `.git/resource` directory.

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:

Expand All @@ -308,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

Expand Down
1 change: 1 addition & 0 deletions in.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 14 additions & 12 deletions in_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ func TestGet(t *testing.T) {
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"}]`,
metadataMapString: `{"author":"login1","author_email":"user@example.com","base_name":"master","base_sha":"sha","head_name":"pr1","head_sha":"oid1","message":"commit message1","pr":"1","state":"OPEN","title":"pr1 title","url":"pr1 url"}`,
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",
Expand All @@ -62,8 +62,8 @@ func TestGet(t *testing.T) {
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"}]`,
metadataMapString: `{"author":"login1","author_email":"user@example.com","base_name":"master","base_sha":"sha","head_name":"pr1","head_sha":"oid1","message":"commit message1","pr":"1","state":"OPEN","title":"pr1 title","url":"pr1 url"}`,
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",
Expand All @@ -82,8 +82,8 @@ func TestGet(t *testing.T) {
},
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"}]`,
metadataMapString: `{"author":"login1","author_email":"user@example.com","base_name":"master","base_sha":"sha","head_name":"pr1","head_sha":"oid1","message":"commit message1","pr":"1","state":"OPEN","title":"pr1 title","url":"pr1 url"}`,
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",
Expand All @@ -102,8 +102,8 @@ func TestGet(t *testing.T) {
},
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"}]`,
metadataMapString: `{"author":"login1","author_email":"user@example.com","base_name":"master","base_sha":"sha","head_name":"pr1","head_sha":"oid1","message":"commit message1","pr":"1","state":"OPEN","title":"pr1 title","url":"pr1 url"}`,
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",
Expand All @@ -122,8 +122,8 @@ func TestGet(t *testing.T) {
},
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"}]`,
metadataMapString: `{"author":"login1","author_email":"user@example.com","base_name":"master","base_sha":"sha","head_name":"pr1","head_sha":"oid1","message":"commit message1","pr":"1","state":"OPEN","title":"pr1 title","url":"pr1 url"}`,
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",
Expand All @@ -150,8 +150,8 @@ func TestGet(t *testing.T) {
},
},
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"}]`,
metadataMapString: `{"author":"login1","author_email":"user@example.com","base_name":"master","base_sha":"sha","head_name":"pr1","head_sha":"oid1","message":"commit message1","pr":"1","state":"OPEN","title":"pr1 title","url":"pr1 url"}`,
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",
},
}
Expand Down Expand Up @@ -200,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 {
Expand Down Expand Up @@ -353,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),
Expand Down
1 change: 1 addition & 0 deletions models.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ type PullRequestObject struct {
ID string
Number int
Title string
Body string
URL string
BaseRefName string
HeadRefName string
Expand Down

0 comments on commit 4f80193

Please sign in to comment.