Skip to content

πŸ”Œ A Buildkite plugin for posting comments from a step to a PR.

Notifications You must be signed in to change notification settings

wrapbook/pr-commenter-buildkite-plugin

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

65 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

PR Commenter Plugin Build status

A Buildkite plugin written in Go that enables commenting on pull requests that builds are triggered from.

The plugin uses the /issues endpoint as that doesn't require a commit SHA or file name in order to post the comment; this comment will post to the conversation tab and won't be associated with any file changes.

The plugin has been tested and built using go 1.20.3, so it is not guaranteed to work on versions <1.20.3.

The plugin binary will get built in the step and output as a pre-exit hook. This ensures that it runs as the last command on the step and is able to get the exit code of the step that it runs on (necessary for the default message).

The use of this plugin requires that clusters are being used and that the secret is available on that cluster, else the plugin will error.

πŸ‘©β€πŸ’» Usage

Add the following to your pipeline.yml:

    steps:
        command: echo "~~~ :github: Add approval comment Pull Request"
        plugins:
            - pr-commenter#v0.4.0:
                message: "LGTM!"
                secret-name: GITHUB_TOKEN

Enabling "Sticky" comments

Set allow-repeats: false in order to post and update a single comment.

    steps:
        command: echo "~~~ :github: Add approval comment Pull Request"
        plugins:
            - pr-commenter#v0.4.0:
                message: "LGTM!"
                secret-name: GITHUB_TOKEN
                allow-repeats: false

Dynamic Message Content

Since the value of message is set/interpolated at the start of the pipeline (upload), message-path can be used to post message content generated during a step.

    steps:
        command: echo "~~~ :github: Add approval comment Pull Request"
        plugins:
            - pr-commenter#v0.4.0:
                message-path: "pr-comment.md"
                secret-name: GITHUB_TOKEN
                allow-repeats: false

πŸ“’ Options

secret-name (optional, string)

The environment variable that contains the value of the GitHub API token. If not set, the plugin will try to get the URL from the default configuration.

Default: GITHUB_TOKEN

message (optional, string)

The message which should be posted to the PR. This can be a dynamic value, such as $BUILDKITE_COMMAND

Default: [${BUILDKITE_BUILD_URL}#${BUILDKITE_JOB_ID}](${BUILDKITE_BUILD_URL}#${BUILDKITE_JOB_ID}) exited with code ${BUILDKITE_COMMAND_EXIT_STATUS}

message-path (optional, string)

The path to a file containing the message which should be posted to the PR. If both message and message-path are set, the plugin will use the value provided for message.

Default: null

allow-repeats (optional, boolean)

Whether to Allow identical comments to be posted every time the plugin is run. Disabling this (allow-repeats: false) will cause the plugin to post a single "sticky" comment, which will be updated on subsequent runs if the message changes.

Default: true

message-id (optional, string)

An additional unique identifier for the comment generated by the plugin instance; useful if using "sticky" comments (allow-repeats: false) and using the plugin multiple times in a single step.

Default: null

Compatibility

Elastic Stack Agent Stack K8s Hosted (Mac) Hosted (Linux) Notes
βœ… ⚠️ βœ… βœ… K8s: The go binary will need to be available on the agents
  • βœ… Fully supported (all combinations of attributes have been tested to pass)
  • ⚠️ Partially supported (some combinations cause errors/issues)

πŸ› οΈ Development

Running the tests

The tests are written using Go's built-in testing package.

Tests can be run using:

go test -v ./...

πŸ’ͺ Contributing

We welcome all contributions to improve this plugin! To contribute, please follow these guidelines:

  • Fork the repository
  • Make your changes and ensure that the tests pass.
  • Write clear and concise commit messages.
  • Submit a pull request.

By contributing, you agree to license your contributions under the LICENSE file of this repository.

License

MIT (see LICENSE)

About

πŸ”Œ A Buildkite plugin for posting comments from a step to a PR.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 94.8%
  • Shell 5.2%