Skip to content

Commit

Permalink
feat: add support for isPr, pr and prBranch for GitLab CI/CD
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdlg committed Oct 8, 2019
1 parent a4fa062 commit dca0daa
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ if (isCI) {
| [Codeship](https://documentation.codeship.com/basic/builds-and-configuration/set-environment-variables/#default-environment-variables) | `codeship` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :x: | :x: | :x: | :x: | :white_check_mark: | :x: |
| [Drone](https://readme.drone.io/reference/environ/) | `drone` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| [GitHub Actions](https://help.github.com/en/articles/virtual-environments-for-github-actions#environment-variables) | `github` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :x: | :x: | :x: | :x: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| [GitLab CI/CD](https://docs.gitlab.com/ce/ci/variables/README.html) | `gitlab` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :x: | :x: | :white_check_mark: | :white_check_mark: |
| [GitLab CI/CD](https://docs.gitlab.com/ce/ci/variables/README.html) | `gitlab` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| [Jenkins](https://wiki.jenkins.io/display/JENKINS/Building+a+software+project) | `jenkins` | :white_check_mark: | [:warning:](#jenkins) | :white_check_mark: | :x: | :white_check_mark: | :white_check_mark: | :x: | :x: | [:warning:](#jenkins) | [:warning:](#jenkins) | [:warning:](#jenkins) | :white_check_mark: | :white_check_mark: |
| [Puppet](https://puppet.com/docs/pipelines-for-apps/enterprise/environment-variable.html) | `puppet` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: | :white_check_mark: | :x: | :x: | :x: | :x: | :x: | :x: | :white_check_mark: |
| [Sail CI](https://sail.ci/docs/environment-variables) | `sail` | :white_check_mark: | [:warning:](#sail) | :white_check_mark: | :x: | :x: | :x: | :x: | :x: | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: | :white_check_mark: |
Expand Down
8 changes: 7 additions & 1 deletion services/gitlab.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ module.exports = {
return Boolean(env.GITLAB_CI);
},
configuration({env}) {
const pr = env.CI_MERGE_REQUEST_ID;
const isPr = Boolean(pr);

return {
name: 'GitLab CI/CD',
service: 'gitlab',
Expand All @@ -14,7 +17,10 @@ module.exports = {
buildUrl: `${env.CI_PROJECT_URL}/pipelines/${env.CI_PIPELINE_ID}`,
job: env.CI_JOB_ID,
jobUrl: `${env.CI_PROJECT_URL}/-/jobs/${env.CI_JOB_ID}`,
branch: env.CI_COMMIT_REF_NAME,
branch: isPr ? env.CI_MERGE_REQUEST_TARGET_BRANCH_NAME : env.CI_COMMIT_REF_NAME,
pr,
isPr,
prBranch: env.CI_MERGE_REQUEST_SOURCE_BRANCH_NAME,
slug: env.CI_PROJECT_PATH,
root: env.CI_PROJECT_DIR,
};
Expand Down
32 changes: 32 additions & 0 deletions test/services/gitlab.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,38 @@ test('Push', t => {
root: '/',
job: '1213',
jobUrl: 'https://gitlab.com/owner/repo/-/jobs/1213',
pr: undefined,
isPr: false,
prBranch: undefined,
slug: 'owner/repo',
});
});

test('PR', t => {
t.deepEqual(
gitlab.configuration({
env: {
...env,
CI_MERGE_REQUEST_ID: '10',
CI_MERGE_REQUEST_TARGET_BRANCH_NAME: 'master',
CI_MERGE_REQUEST_SOURCE_BRANCH_NAME: 'pr-branch',
},
}),
{
name: 'GitLab CI/CD',
service: 'gitlab',
commit: '5678',
tag: 'tag_name',
build: '91011',
buildUrl: 'https://gitlab.com/owner/repo/pipelines/91011',
branch: 'master',
root: '/',
job: '1213',
jobUrl: 'https://gitlab.com/owner/repo/-/jobs/1213',
pr: '10',
isPr: true,
prBranch: 'pr-branch',
slug: 'owner/repo',
}
);
});

0 comments on commit dca0daa

Please sign in to comment.