ci-env
Advanced tools
Comparing version 1.11.1 to 1.12.0
20
index.js
let drone = require('./utils/drone') | ||
// platform denotes code hosting provider i.e github, gitlab, bitbucket etc. | ||
// Had to introduce this variable as there are cases when CI is run on the same platform where code is hosted as those cases need to be handled differently. | ||
// Default value is github | ||
let platform = 'github'; | ||
let repo, sha, event, commit_message, pull_request_number, branch, ci, jobUrl, buildUrl | ||
@@ -59,2 +63,14 @@ | ||
ci = 'drone' | ||
} else if (process.env.GITLAB_CI){ | ||
// Reference: https://docs.gitlab.com/ee/ci/variables/predefined_variables.html | ||
// except buildUrl we get all the other variables for gitlab CI | ||
repo = process.env.CI_PROJECT_PATH | ||
branch = process.env.CI_COMMIT_REF_NAME | ||
commit_message = process.env.CI_COMMIT_MESSAGE | ||
pull_request_number = (process.env.CI_MERGE_REQUEST_ID || '') // no pull request numnber in case the CI is run for the branch without a pull request | ||
sha=process.env.CI_COMMIT_SHA | ||
event = process.env.CI_PIPELINE_SOURCE | ||
jobUrl = process.env.CI_JOB_URL | ||
platform = 'gitlab' | ||
ci = 'gitlab' | ||
} else if (process.env.CI_NAME === 'codeship') { | ||
@@ -114,3 +130,3 @@ // Reference: https://documentation.codeship.com/basic/builds-and-configuration/set-environment-variables/#default-environment-variables | ||
commit_message = process.env.CI_COMMIT_MESSAGE | ||
pull_request_number = process.env.CI_PULL_REQUEST_NUMBER | ||
pull_request_number = process.env.CI_MERGE_REQUEST_ID | ||
branch = process.env.CI_BRANCH | ||
@@ -120,2 +136,2 @@ ci = 'custom' | ||
module.exports = { repo, sha, event, commit_message, branch, pull_request_number, ci, jobUrl, buildUrl } | ||
module.exports = { repo, sha, event, commit_message, branch, pull_request_number, ci, platform, jobUrl, buildUrl } |
{ | ||
"name": "ci-env", | ||
"version": "1.11.1", | ||
"version": "1.12.0", | ||
"description": "Environment variables exposed by CI tools", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -10,3 +10,3 @@ <p align="center"> | ||
Supports travis, circle, wercker, drone, codeship, now(zeit), netlify and GitHub Actions. | ||
Supports travis, circle, gitlab, wercker, drone, codeship, now(zeit), netlify and GitHub Actions. | ||
@@ -13,0 +13,0 @@ Kinda supports custom CI as well. [Specs here](https://github.com/siddharthkp/ci-env/blob/master/index.js#L68-L79) |
27
test.js
@@ -12,3 +12,4 @@ const test = require("ava"); | ||
branch, | ||
ci | ||
ci, | ||
platform | ||
} = require("./index"); | ||
@@ -34,5 +35,9 @@ | ||
else if (process.env.GITHUB_ACTION) t.is(ci, "github_actions"); | ||
else if (process.env.GITLAB_CI) t.is(ci, "gitlab"); | ||
}); | ||
test("repo is correctly set", t => t.is(repo, "siddharthkp/ci-env")); | ||
test("repo is correctly set", t => { | ||
if (process.env.GITLAB_CI) t.is(repo, process.env.CI_PROJECT_PATH); | ||
else t.is(repo, "siddharthkp/ci-env"); | ||
}); | ||
@@ -46,3 +51,4 @@ test("sha is set", t => { | ||
process.env.DRONE_COMMIT || | ||
process.env.GITHUB_SHA; | ||
process.env.GITHUB_SHA || | ||
process.env.CI_COMMIT_SHA; //gitlab | ||
@@ -63,5 +69,7 @@ t.is(sha, real_sha); | ||
test("pull_request_number is set", t => { | ||
let circlePullRequestNumber; | ||
let pullRequestNumber; | ||
if (process.env.CI_PULL_REQUEST) | ||
circlePullRequestNumber = process.env.CI_PULL_REQUEST.split("/").pop(); | ||
pullRequestNumber = process.env.CI_PULL_REQUEST.split("/").pop(); | ||
if(process.env.GITHUB_ACTION && event === "pull_request") | ||
pullRequestNumber = process.env.GITHUB_REF.split('/')[2]; | ||
@@ -71,3 +79,4 @@ const real_pull_request_number = | ||
process.env.DRONE_PULL_REQUEST || | ||
circlePullRequestNumber || | ||
process.env.CI_MERGE_REQUEST_ID || //gitlab | ||
pullRequestNumber || | ||
""; // wercker does not expose pull request number | ||
@@ -84,2 +93,3 @@ | ||
}`; | ||
else if (process.env.GITLAB_CI) real_jobUrl = process.env.CI_JOB_URL; | ||
t.is(jobUrl, real_jobUrl); | ||
@@ -111,3 +121,3 @@ }); | ||
branch, | ||
process.env.TRAVIS_PULL_REQUEST_BRANCH || process.env.GITHUB_REF | ||
process.env.TRAVIS_PULL_REQUEST_BRANCH || process.env.GITHUB_HEAD_REF | ||
); | ||
@@ -121,3 +131,4 @@ else { | ||
process.env.CI_BRANCH || // codeship | ||
process.env.GITHUB_REF; | ||
process.env.CI_COMMIT_REF_NAME || // gitlab | ||
process.env.GITHUB_REF.split('/')[2] | ||
@@ -124,0 +135,0 @@ t.is(branch, real_branch); |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 6 instances in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
14915
13
277
121