Skip to content

Commit 5c22bb8

Browse files
author
Rory Price-Coggins
committed
chore: support comment_file arg to post PR comment with contents from file
1 parent afcaf83 commit 5c22bb8

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## This was forked from the original [aoldershaw/github-pr-resource](https://github.com/aoldershaw/github-pr-resource)
2-
to add an additional security check when looking at PR approvals.
2+
to add an additional security check when looking at PR approvals.
33

44
You can find it on Dockerhub as the `tasruntime/github-pr-instances-resource` image.
55

@@ -201,11 +201,12 @@ empty commit to the PR*.
201201
| `base_context` | No | `concourse-ci` | Base context (prefix) used for the status context. Defaults to `concourse-ci`. |
202202
| `context` | No | `unit-test` | A context to use for the status, which is prefixed by `base_context`. Defaults to `"status"`. |
203203
| `comment` | No | `hello world!` | A comment to add to the pull request. |
204+
| `comment_file` | No | `my-output/comment.txt` | Path to file containing a comment to add to the pull request |
204205
| `target_url` | No | `$ATC_EXTERNAL_URL/builds/$BUILD_ID` | The target URL for the status, where users are sent when clicking details (defaults to the Concourse build page). |
205206
| `description` | No | `Concourse CI build failed` | The description status on the specified pull request. |
206207
| `delete_previous_comments` | No | `true` | Boolean. Previous comments made on the pull request by this resource will be deleted before making the new comment. Useful for removing outdated information. |
207208

208-
Note that `comment`, `context,` and `target_url` will all expand environment variables, so in the examples above `$ATC_EXTERNAL_URL` will be replaced by the public URL of the Concourse ATCs.
209+
Note that `comment`, `comment_file`, `context,` and `target_url` will all expand environment variables, so in the examples above `$ATC_EXTERNAL_URL` will be replaced by the public URL of the Concourse ATCs.
209210
See https://concourse-ci.org/implementing-resource-types.html#resource-metadata for more details about metadata that is available via environment variables.
210211

211212
## Example

pr/out.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,21 @@ func Put(request PutRequest, github models.Github, inputDir string) (*PutRespons
6565
}
6666
}
6767

68+
// Set comment from a file if specfied
69+
if p := request.Params; p.CommentFile != "" {
70+
content, err := ioutil.ReadFile(filepath.Join(inputDir, p.CommentFile))
71+
if err != nil {
72+
return nil, fmt.Errorf("failed to read comment file: %s", err)
73+
}
74+
comment := string(content)
75+
if comment != "" {
76+
err = github.PostComment(prNumber, safeExpandEnv(comment))
77+
if err != nil {
78+
return nil, fmt.Errorf("failed to post comment: %s", err)
79+
}
80+
}
81+
}
82+
6883
return &PutResponse{
6984
Version: version,
7085
Metadata: metadata,
@@ -89,6 +104,7 @@ type PutParameters struct {
89104
Description string `json:"description"`
90105
Status string `json:"status"`
91106
Comment string `json:"comment"`
107+
CommentFile string `json:"comment_file"`
92108
DeletePreviousComments bool `json:"delete_previous_comments"`
93109
}
94110

0 commit comments

Comments
 (0)