Skip to content

Commit

Permalink
Add branch parameter to source configuration
Browse files Browse the repository at this point in the history
This allows checking for pull requests against a given branch,
instead of all pull requests on the repository.
  • Loading branch information
rjosephwright authored and idr0id committed Dec 28, 2018
1 parent 85299c6 commit ca9c58c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ resource](https://github.com/concourse/git-resource). The `branch` configuration
from the original resource is ignored.
* `bitbucket_type`: *Optional*. `cloud` for BitBucket Cloud or `server` for a self-hosted BitBucket Server. `default: server`
* `dir`: *Optional*. set to name of the resource if resource name is different than repository name
* `branch`: *Optional*. if given, only pull requests against this branch will be checked

### Example

Expand Down
7 changes: 6 additions & 1 deletion assets/check
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ password=`jq -r '.source.password // ""' < ${payload}`
project=`jq -r '.source.project // ""' < ${payload}`
repository=`jq -r '.source.repository // ""' < ${payload}`
limit=`jq -r '.source.limit // 100' < ${payload}`
source_branch=`jq -r '.source.branch // ""' < ${payload}`
# version
version_updated_at=`jq -r '.version.updated_at // 0' < ${payload}`

Expand All @@ -38,7 +39,8 @@ fi

# Bitbucket Cloud and (self-hosted) Server APIs are a bit different
if [[ "$bitbucket_type" == "server" ]]; then
uri="${base_url}/rest/api/1.0/projects/${project}/repos/${repository}/pull-requests?limit=${limit}&state=open"
[[ "${source_branch}" ]] && branch_param="&at=refs/heads/${source_branch}"
uri="${base_url}/rest/api/1.0/projects/${project}/repos/${repository}/pull-requests?limit=${limit}&state=open${branch_param}"

curl -sS --fail -u ${username}:${password} $uri | jq -r \
'.values
Expand All @@ -62,6 +64,9 @@ elif [[ "$bitbucket_type" == "cloud" ]]; then
prs="[]"
while read -r pullrequest; do
branch=$(echo "$pullrequest" | jq -r '.source.branch.name')
if [[ "${source_branch}" ]]; then
[[ "${branch}" = "${source_branch}" ]] || continue
fi
id=$(echo "$pullrequest" | jq -r '.id')
title=$(echo "$pullrequest" | jq -r '.title')
commit=$(echo "$pullrequest" | jq -r '.source.commit.hash')
Expand Down

0 comments on commit ca9c58c

Please sign in to comment.