Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
bin
gitlab.env.yml
.nyc_output
.gitlabrc
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
### Changed

- The `--url` option became optional. When omitted, the plugin will infer the URL from the git remote.
- The `--token` option became optional if a `.gitlabrc` file exists.

## [v1.0.10] - 2017-08-18

Expand Down
41 changes: 38 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $ npm install -g gitlab-ci-variables-setter-cli

## Usage

Put all required variable key/values on a properties file named `gitlab.env.yml`. For example:
Put all required variable key/values on a properties file named `gitlab.env.yml`, e.g:

```yml
AWS_CREDENTIALS: |
Expand All @@ -37,18 +37,53 @@ Run the following command from the directory that contains the properties file,

```sh
$ setAllVars --token <gitlab-token> --url <gitlab-project-url>
Set AWS_CREDENTIALS = <value> for gitlab-org/gitlab-ce.
Set NPM_INSTALL_TOKEN = <value> for gitlab-org/gitlab-ce.
Completed setting variables on Gitlab CI.
```

By default, all existing variables on Gitlab CI will be overridden. If you wish to ignore existing variables, add a `--do-not-force` option, i.e.
By default, all existing variables on Gitlab CI will be overridden. If you wish to ignore existing variables, add a `--do-not-force` option, e.g:

```sh
$ setAllVars --token <gitlab-token> --url <gitlab-project-url> --do-not-force
Skipping AWS_CREDENTIALS, already set for gitlab-org/gitlab-ce.
Skipping NPM_INSTALL_TOKEN, already set for gitlab-org/gitlab-ce.
Completed setting variables on Gitlab CI.
```

If your working directory is a git repostory of your project, the `--url` option can be omitted, i.e:
If your working directory is a git repostory of your project, the `--url` option can be omitted, e.g:

```sh
$ setAllVars --token <gitlab-token>
No URL specified, using git remote `origin`.
Set AWS_CREDENTIALS = <value> for gitlab-org/gitlab-ce.
Set NPM_INSTALL_TOKEN = <value> for gitlab-org/gitlab-ce.
Completed setting variables on Gitlab CI.
```

> Omitting `--url` will derive the URL from the remote named `origin`.

This project supports `.gitlabrc` files using [rc](https://www.npmjs.com/package/rc).
If `--token` is not specified, this project can use a `.gitlabrc`, e.g:

```ini
token: this-is-my-gitlab-token
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be = instead of :

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

```

```sh
$ setAllVars --url <gitlab-project-url>
Set AWS_CREDENTIALS = <value> for gitlab-org/gitlab-ce.
Set NPM_INSTALL_TOKEN = <value> for gitlab-org/gitlab-ce.
Completed setting variables on Gitlab CI.
```

Essentially, if your project is a git repository, and you have `.gitlabrc` file,
no options are required and this tool can be invoked simply as:

```sh
$ setAllVars
No URL specified, using git remote `origin`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder whether the app should display the same message for URL, e.g. not token provided, using token found under .gitlabrc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do

Set AWS_CREDENTIALS = <value> for gitlab-org/gitlab-ce.
Set NPM_INSTALL_TOKEN = <value> for gitlab-org/gitlab-ce.
Completed setting variables on Gitlab CI.
```
26 changes: 24 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"version": "1.0.10",
"description": "CLI tool to allow setting multiple pipeline variables on Gitlab CI.",
"author": "Khoa Tran",
"contributors": [
"Brendan Abbott <brendan@bloodbone.ws>"
],
"license": "MIT",
"keywords": [
"gitlab",
Expand Down Expand Up @@ -34,6 +37,7 @@
"git-remote-origin-url": "^2.0.0",
"git-url-parse": "^7.0.0",
"js-yaml": "^3.9.1",
"rc": "^1.2.1",
"url-parse": "^1.1.9"
},
"devDependencies": {
Expand Down
8 changes: 5 additions & 3 deletions src/setAllVariables.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import program from 'commander';
import fs from 'fs';
import rc from 'rc';
import gitRemoteOriginUrl from 'git-remote-origin-url';
import getUrlFromGitRemote from './lib/git';
import gitlabCI from './lib/gitlab-ci';
Expand All @@ -10,15 +11,16 @@ import loadPropertiesFile from './lib/properties-file';
const gitlabEnvFileName = 'gitlab.env.yml';

async function execute(cmd) {
const conf = rc('gitlab');
const errors = [];

// Check for token
if (cmd.token === undefined) {
if (!conf.token) {
errors.push('No Gitlab token given.');
}

// If there is no url provided, get it!
let url = cmd.url;
let url = conf.url;
if (!url) {
try {
url = await getUrlFromGitRemote(gitRemoteOriginUrl);
Expand Down Expand Up @@ -48,7 +50,7 @@ async function execute(cmd) {
}

const properties = loadPropertiesFile(path);
const handler = gitlabCI(url, cmd.token);
const handler = gitlabCI(url, conf.token);
await handler.setVariables(properties, forceUpdate);

console.log('Completed setting variables on Gitlab CI.');
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1787,8 +1787,8 @@ istanbul-lib-hook@^1.0.7:
append-transform "^0.4.0"

istanbul-lib-instrument@^1.7.4:
version "1.7.4"
resolved "https://registry.yarnpkg.com/istanbul-lib-instrument/-/istanbul-lib-instrument-1.7.4.tgz#e9fd920e4767f3d19edc765e2d6b3f5ccbd0eea8"
version "1.7.5"
resolved "https://registry.yarnpkg.com/istanbul-lib-instrument/-/istanbul-lib-instrument-1.7.5.tgz#adb596f8f0cb8b95e739206351a38a586af21b1e"
dependencies:
babel-generator "^6.18.0"
babel-template "^6.16.0"
Expand Down Expand Up @@ -2444,7 +2444,7 @@ randomatic@^1.1.3:
is-number "^3.0.0"
kind-of "^4.0.0"

rc@^1.1.7:
rc@^1.1.7, rc@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/rc/-/rc-1.2.1.tgz#2e03e8e42ee450b8cb3dce65be1bf8974e1dfd95"
dependencies:
Expand Down