Skip to content

Commit 542ddeb

Browse files
author
Brendan Abbott
committed
Make --token optional (through .gitlabrc file)
1 parent e2688d9 commit 542ddeb

File tree

6 files changed

+56
-12
lines changed

6 files changed

+56
-12
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ node_modules
22
bin
33
gitlab.env.yml
44
.nyc_output
5+
.gitlabrc

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,14 @@ By default, all existing variables on gitlab ci will be overridden. If you wish
4141
```sh
4242
$ setAllVars --url <gitlab-project-url> --token <gitlab-token> --do-not-force
4343
```
44+
45+
This project supports `.gitlabrc` files using [rc](https://www.npmjs.com/package/rc).
46+
If `--token` is not specified, this project can use a `.gitlabrc`, e.g:
47+
48+
```ini
49+
token: this-is-my-gitlab-token
50+
```
51+
52+
```sh
53+
$ setAllVars --url <gitlab-project-url>
54+
```

package-lock.json

Lines changed: 29 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
"version": "1.0.10",
44
"description": "CLI tool to handle gitlab CI project variables",
55
"author": "Khoa Tran",
6+
"contributors": [
7+
"Brendan Abbott <brendan@bloodbone.ws>"
8+
],
69
"license": "MIT",
710
"keywords": [
811
"gitlab",
@@ -32,6 +35,7 @@
3235
"bluebird": "^3.5.0",
3336
"commander": "^2.11.0",
3437
"js-yaml": "^3.9.1",
38+
"rc": "^1.2.1",
3539
"url-parse": "^1.1.9"
3640
},
3741
"devDependencies": {

src/setAllVariables.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
import program from 'commander';
44
import fs from 'fs';
5+
import rc from 'rc';
56
import loadPropertiesFile from './lib/properties-file';
67
import gitlabCI from './lib/gitlab-ci';
78

89
const gitlabEnvFileName = 'gitlab.env.yml';
910

1011
/**
11-
* Validate CLI options
12+
* Validate options (from CLI, or merged from `.gitlabrc` file)
1213
*
1314
* @param {Object} options
1415
* @return {Array} array of errors. Empty array if no errors
@@ -28,7 +29,9 @@ function validate(options = {}) {
2829
}
2930

3031
async function execute(cmd) {
31-
const errors = validate(cmd);
32+
const conf = rc('gitlab');
33+
34+
const errors = validate(conf);
3235
if (errors.length > 0) {
3336
console.error(errors.join('\n'));
3437
process.exit(1);
@@ -49,7 +52,7 @@ async function execute(cmd) {
4952
}
5053

5154
const properties = loadPropertiesFile(path);
52-
const handler = gitlabCI(cmd.url, cmd.token);
55+
const handler = gitlabCI(cmd.url, conf.token);
5356
await handler.setVariables(properties, forceUpdate);
5457

5558
console.log('Completed setting variables on Gitlab CI.');

yarn.lock

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,10 @@ babel-messages@^6.23.0:
367367
dependencies:
368368
babel-runtime "^6.22.0"
369369

370+
babel-plugin-add-module-exports@^0.2.1:
371+
version "0.2.1"
372+
resolved "https://registry.yarnpkg.com/babel-plugin-add-module-exports/-/babel-plugin-add-module-exports-0.2.1.tgz#9ae9a1f4a8dc67f0cdec4f4aeda1e43a5ff65e25"
373+
370374
babel-plugin-check-es2015-constants@^6.22.0:
371375
version "6.22.0"
372376
resolved "https://registry.yarnpkg.com/babel-plugin-check-es2015-constants/-/babel-plugin-check-es2015-constants-6.22.0.tgz#35157b101426fd2ffd3da3f75c7d1e91835bbf8a"
@@ -584,12 +588,6 @@ babel-plugin-transform-regenerator@^6.22.0:
584588
dependencies:
585589
regenerator-transform "0.9.11"
586590

587-
babel-plugin-transform-runtime@^6.23.0:
588-
version "6.23.0"
589-
resolved "https://registry.yarnpkg.com/babel-plugin-transform-runtime/-/babel-plugin-transform-runtime-6.23.0.tgz#88490d446502ea9b8e7efb0fe09ec4d99479b1ee"
590-
dependencies:
591-
babel-runtime "^6.22.0"
592-
593591
babel-plugin-transform-strict-mode@^6.24.1:
594592
version "6.24.1"
595593
resolved "https://registry.yarnpkg.com/babel-plugin-transform-strict-mode/-/babel-plugin-transform-strict-mode-6.24.1.tgz#d5faf7aa578a65bbe591cf5edae04a0c67020758"
@@ -2398,7 +2396,7 @@ randomatic@^1.1.3:
23982396
is-number "^3.0.0"
23992397
kind-of "^4.0.0"
24002398

2401-
rc@^1.1.7:
2399+
rc@^1.1.7, rc@^1.2.1:
24022400
version "1.2.1"
24032401
resolved "https://registry.yarnpkg.com/rc/-/rc-1.2.1.tgz#2e03e8e42ee450b8cb3dce65be1bf8974e1dfd95"
24042402
dependencies:

0 commit comments

Comments
 (0)