Skip to content

Commit 1a1cec2

Browse files
codablockUdjinM6
authored andcommitted
Fix pull request detection in .gitlab-ci.yml (#3256)
* Fix pull request detection on Gitlab CI * Fix CI_COMMIT_BEFORE_SHA
1 parent 31afa9c commit 1a1cec2

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

.gitlab-ci.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,22 @@ stages:
6565
- pip3 install jinja2
6666

6767
# Setup some environment variables
68-
- if [ "$CI_EXTERNAL_PULL_REQUEST_IID" != "" ]; then export PULL_REQUEST="true"; else export PULL_REQUEST="false"; fi
68+
- |
69+
if [ "$CI_EXTERNAL_PULL_REQUEST_IID" != "" ]; then
70+
export PULL_REQUEST="true"
71+
else
72+
# CI_EXTERNAL_PULL_REQUEST_IID is false every time until https://gitlab.com/gitlab-org/gitlab/issues/5667 is done
73+
# Until then, we're using https://github.com/brndnmtthws/labhub atm to mirror Github pull requests as branches into Gitlab,
74+
# which allows us to use Gitlab CI for Github. The following check detects such mirrored branches.
75+
if [[ $CI_COMMIT_REF_NAME =~ ^pr-[^/]*/[^/]*/[^/]*/[^/]*$ ]]; then
76+
export PULL_REQUEST="true"
77+
# CI_COMMIT_BEFORE_SHA is also invalid until #5667 is implemented, so we need to figure it out by ourself
78+
git fetch origin develop
79+
export CI_COMMIT_BEFORE_SHA="$(git merge-base origin/develop HEAD)"
80+
else
81+
export PULL_REQUEST="false"
82+
fi
83+
fi
6984
- export COMMIT_RANGE="$CI_COMMIT_BEFORE_SHA..$CI_COMMIT_SHA"
7085
- export JOB_NUMBER="$CI_JOB_ID"
7186
- export HOST_SRC_DIR=$CI_PROJECT_DIR

0 commit comments

Comments
 (0)