Skip to content

Commit d8941d2

Browse files
author
Thomas Detoux
committed
Add the original branch name as a git config value to be used later in the pipeline
1 parent f799484 commit d8941d2

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ It will allow you to build all versions instead of only the latest.
8787

8888
Submodules are initialized and updated recursively.
8989

90+
Note: the name of the branch from which the pull request has been created is stored in the special git config `pullrequest.branch` so that you can use it as reference in your pipeline.
91+
9092
#### Parameters
9193

9294
* `depth`: *Optional.* If a positive integer is given, *shallow* clone the repository using the `--depth` option. Using this flag voids your warranty.

assets/in

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,30 @@ if [ -z "$target_commit" ]; then
132132
exit 1
133133
fi
134134

135+
# parse uri and retrieve host
136+
uri_parser "$uri"
137+
repo_host="${uri_schema}://${uri_address}"
138+
repo_host=${repo_host}$(getBasePathOfBitbucket)
139+
140+
# determine repository name for calling REST api
141+
repo_name=$(basename "$uri" | sed "s/.git$//")
142+
repo_project=$(basename $(dirname "$uri"))
143+
144+
# verify target branch of prq
145+
prq=$(bitbucket_pullrequest "$repo_host" "$repo_project" "$repo_name" "$prq_id" "" "$skip_ssl_verification")
146+
147+
if [ "$prq" != "ERROR" ]; then
148+
branch=$(echo "$prq" | jq -r '.fromRef.displayId')
149+
fi
150+
151+
135152
# expose configuration of pull request that can be used in container
136153
git config --add pullrequest.id $prq_id
137154
git config --add pullrequest.source $source_commit
138155
git config --add pullrequest.target $target_commit
139156
git config --add pullrequest.merge $ref
140157
git config --add pullrequest.date "$prq_date"
158+
git config --add pullrequest.branch "$branch"
141159

142160
jq -n "{
143161
version: $(jq '.version' < "$payload"),

0 commit comments

Comments
 (0)