Categorygithub.com/nderjung/concourse-github-pr-comment-resource

# README

concourse-github-pr-comment-resource

resource-pipeline

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 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:

ParameterRequiredExampleDefaultDescription
repositoryYesnderjung/limpThe repository to listen for PR comments on.
disable_git_lfsNotruefalseDisable Git LFS, skipping an attempt to convert pointers of files tracked into their corresponding objects when checked out into a working copy.
access_tokenYesThe personal access token of the account used to access, monitor and post comments on the repository in question.
github_endpointNohttps://api.github.comEndpoint used to connect to the Github v3 API.
skip_sslNotruefalseWhether to skip SSL verification of the Github API.
only_mergeableNotruefalseWhether to react to (non-)mergeable pull requests.
statesNo["closed"]["open"]The state of the pull request to react on.
ignore_draftsNotruefalseDisable triggering of the resource if the pull request is in Draft status.
ignore_statesNo["open"][]The state of the pull request to not react on.
labelsNo["bug"][]The labels of the pull request to react on.
ignore_labelsNo["lifecycle/stale"][]The labels of the pull request not to react on.
commentsNo["^ping$"][]The regular expressions of the latest comment to react on.
commenter_associationNo["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".
ignore_commentsNo["ing$"][]The regular expressions of the latest comment not to react on.
map_comment_metaNotruefalseWhether to map any regular expression keys and their corresponding values to the meta object provided in in.
review_statesNo["commented", "changes_requested"][]The state of the review, any combination of approved, changes_requeste and/or commented.
whenNofirstlatestThe comment or review to select, one of either all, latest or first.

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:

ParameterRequiredDefaultDescription
comment_fileNocomment.txtA unique path to save the body of the comment.
source_pathNosourceThe path to save the source within the resource.
git_depthNo0Git clone depth.
submodulesNofalseWhether to clone Git submodules.
fetch_tagsNofalseWhether to fetch Git tags.
integration_toolNorebaseHow to merge the PR source, selection between rebase, merge, checkout.
skip_downloadNofalseDoes not clone the pull request.

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.

KeyDescription
pr_idThe ID of the pull request relative to the repository.
comment_idThe unique ID provided by Github for the comment.
bodyThe content of the comment.
created_atThe timestamp of the comment.
updated_atThe timestamp of when the comment was last updated.
author_associationThe association the author of the comment has with the repository.
html_urlThe URL to the comment.
user_idThe unique ID of the comment author on Github.
user_loginThe username of the comment author on Github.
user_nameThe name of the comment author on Github.
user_emailThe email of the comment author on Github.
user_avatar_urlThe avatar URL for the comment author.
user_html_urlThe URL to the comment author's profile on Github.
pr_head_refThe branch name from the HEAD of Pull Request.
pr_head_shaThe commit SHA from the HEAD of the Pull Request.
pr_base_refThe branch name from the base of the Pull Request.
pr_base_shaThe commit SHA from the base of the Pull Request.

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,
  • Any additional attributes mapped from parsing comments using Golang's name grouping. More details can be found here.

out

ParameterRequiredExampleDefaultDescription
pathYespr-commentThe name given to the resource in a in/get step.
stateNoclosedThe state to set the PR. Options include open and closed.
commentNopongThe string to use as a new comment on the PR.
comment_fileNopong.txtThe path to the file to read and post as a new comment on the PR.
labelsNo[""]The finite set of labels to replace on the PR.
add_labelsNo["cicd/tested"]Additional labels to add to the PR.
remove_labelsNo["cicd/await"]Labels to remove from the PR.
delete_last_commentNotruefalseWhether 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.

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":

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.

# Packages

SPDX-License-Identifier: BSD-3-Clause Authors: Alexander Jung <[email protected]> Copyright (c) 2020, Alexander Jung.
SPDX-License-Identifier: BSD-3-Clause Authors: Alexander Jung <[email protected]> Copyright (c) 2020, Alexander Jung.
SPDX-License-Identifier: BSD-3-Clause Authors: Alexander Jung <[email protected]> Copyright (c) 2020, Alexander Jung.