Github Pull Request Resource
Tracks pull requests made to a particular github repo. In the spirit of Travis CI, a status of pending, success, or failure will be set on the pull request, which much be explicitly defined in your pipeline.
Deploying to Concourse
You can use the docker image by defining the resource type in your pipeline YAML.
For example:
resource_types:
- name: pull-request
type: docker-image
source:
repository: jtarchie/pr
Source Configuration
-
repo
: Required. The repo name on github. Example:jtarchie/pullrequest-resource
-
access_token
: Required. An access token withrepo:status
access is required for public repos. An access tocken withrepo
access is required for private repos. -
uri
: Optional. The URI to the github repo. By default, it assumes https://github.com/`repo`. -
base_url
: Optional The base URL for the Concourse deployment, used for linking to builds. On newer versions of Concourse ( >= v0.71.0) , the resource will automatically sets the URL. -
private_key
: Optional. Private key to use when pulling/pushing. Example:private_key: | -----BEGIN RSA PRIVATE KEY----- MIIEowIBAAKCAQEAtCS10/f7W7lkQaSgD/mVeaSOvSF9ql4hf/zfMwfVGgHWjj+W <Lots more text> DWiJL+OFeg9kawcUL6hQ8JeXPhlImG6RTUffma9+iGQyyBMCGd1l -----END RSA PRIVATE KEY-----
-
api_endpoint
: Optional. If the repository is located on a GitHub Enterprise instance you need to specify the base api endpoint (e.g. "https://<hostname>/api/v3/"). -
every
: Optional If set totrue
, it will override thecheck
step so every pull request can be iterated through, without relying on a status being on it. This feature should only be used in concourse version 1.2.x and higher and theversion: every
. -
username
: Optional. Username for HTTP(S) auth when pulling/pushing. This is needed when only HTTP/HTTPS protocol for git is available (which does not support private key auth) and auth is required. -
password
: Optional. Password for HTTP(S) auth when pulling/pushing. -
skip_ssl_verification
: Optional. Skips git ssl verification by exportingGIT_SSL_NO_VERIFY=true
. -
git_config
: Optional. If specified as (list of pairsname
andvalue
) it will configure git global options, setting each name with each value.This can be useful to set options like
credential.helper
or similar.See the
git-config(1)
manual page for more information and documentation of existing git options.
Behavior
check
: Check for new pull requests
Concourse resources always iterate over the latest version. This maps well to
semver and git, but not with pull requests. To find the latests pull
requests, check
queries for all PRs, selects only PRs without concourse-ci
status messages, and then only returns the oldest one from list.
To ensure that check
can iterate over all PRs, you must explicitly define an
out
for the PR.
in
: Clone the repository, at the given pull request ref
Clones the repository to the destination, and locks it down to a given ref.
Submodules are initialized and updated recursively, there is no option to to disable that, currently.
There is git config
information set on the repo about the PR, which can be consumed within your tasks.
For example:
git config --get pullrequest.url # returns the URL to the pull request
git config --get pullrequest.branch # returns the branch name used for the pull request
git config --get pullrequest.id # returns the ID number of the PR
out
: Update the status of a pull request
Set the status message for concourse-ci
context on specified pull request.
Parameters
-
path
: Required. The path of the repository to reference the pull request. -
status
: Required. The status of success, failure, error, or pending.on_success
andon_falure
triggers may be useful for you when you wanted to reflect build result to the PR (see the example below).
-
context
: Optional. The context on the specified pull request (defaults tostatus
). Any context will be prepended withconcourse-ci
, so a context ofunit-tests
will appear asconcourse-ci/unit-tests
on Github.
Example pipeline
This is what I am currently using to test this resource on Concourse.
resource_types:
- name: pull-request
type: docker-image
source:
repository: jtarchie/pr
resources:
- name: repo
type: pull-request
source:
access_token: acecss_token
private_key: |
-----BEGIN RSA PRIVATE KEY-----
My private key.
-----END RSA PRIVATE KEY-----
repo: jtarchie/pullrequest-resource
jobs:
- name: test pull request
plan:
- get: repo
trigger: true
- put: repo
params:
path: repo
status: pending
- task: do something with git
config:
platform: linux
image: docker:///concourse/git-resource
run:
path: sh
args:
- -c
- cd repo && git --no-pager show
inputs:
- name: repo
path: ""
on_success:
put: repo
params:
path: repo
status: success
on_failure:
put: repo
params:
path: repo
status: failure
Tests
Tests can be run two ways, for local feedback and to see how it will run on the resource container.
- Local, requires
ruby
gem install bundler
bundle install
bundle exec rspec
- Container, requires requires
ruby
anddocker
gem install bundler
bundle install
rake test