Skip to content

Commit

Permalink
Merge branch 'master' into v13
Browse files Browse the repository at this point in the history
# Conflicts:
#	lib/plugin/GitBase.js
#	lib/plugin/gitlab/GitLab.js
#	lib/shell.js
#	test/gitlab.js
  • Loading branch information
webpro committed Mar 2, 2020
2 parents a9aa238 + 2dc01ba commit 3586a78
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 33 deletions.
10 changes: 2 additions & 8 deletions README.md
Expand Up @@ -117,14 +117,8 @@ Release a new version:
release-it
```

You will be prompted to select the new version. To skip the first prompt, provide a specific increment or version:

```bash
release-it minor
release-it 0.8.3
```

For a "dry run", to show the interactivity and the commands it _would_ execute:
You will be prompted to select the new version, and more questions will follow based on your setup. For a "dry run" (to
show the interactivity and the commands it _would_ execute):

```bash
release-it --dry-run
Expand Down
2 changes: 2 additions & 0 deletions docs/prerequisites.md
Expand Up @@ -74,3 +74,5 @@ or `E404`, release-it will give a warning but continue.
When `github.release` and/or `gitlab.release` is set to `true`, release-it will check whether the `GITHUB_TOKEN` (or
`GITLAB_TOKEN`) environment variable is set. Otherwise it will throw an error and exit. The name of the variable can be
set with `github.tokenRef` and `gitlab.tokenRef`, respectively.

Then, it will authenticate, and verify whether the current user is a collaborator and authorized to publish a release.
9 changes: 6 additions & 3 deletions lib/metrics.js
Expand Up @@ -2,7 +2,7 @@ const { EOL } = require('os');
const got = require('got');
const supportsColor = require('supports-color');
const windowSize = require('window-size');
const uuid = require('uuid');
const { v4: uuidv4 } = require('uuid');
const osName = require('os-name');
const isCi = require('is-ci');
const debug = require('debug')('release-it:metrics');
Expand All @@ -12,7 +12,7 @@ const noop = Promise.resolve();

const cast = value => (value ? 1 : 0);

const cid = uuid.v4();
const cid = uuidv4();
const dimensions = windowSize ? windowSize.get() : { width: 0, height: 0 };
const vp = `${dimensions.width}x${dimensions.height}`;
const depths = ['1-bit', '4-bit', '8-bit', '24-bits'];
Expand Down Expand Up @@ -55,7 +55,10 @@ class Metrics {
form: true,
body: payload
})
.then(debug)
.then(res => {
const { url, statusCode, statusMessage, body, request } = res;
debug({ url, statusCode, statusMessage, body, request });
})
.catch(debug);
}
trackEvent(action, config) {
Expand Down
11 changes: 5 additions & 6 deletions lib/plugin/gitlab/GitLab.js
Expand Up @@ -51,8 +51,8 @@ class GitLab extends Release {
if (this.global.isDryRun) return true;
const endpoint = `user`;
try {
const { username } = await this.request(endpoint, { method: 'GET' });
this.setContext({ gitlab: { username } });
const { id, username } = await this.request(endpoint, { method: 'GET' });
this.setContext({ gitlab: { id, username } });
return true;
} catch (err) {
this.debug(err);
Expand All @@ -62,11 +62,10 @@ class GitLab extends Release {

async isCollaborator() {
if (this.global.isDryRun) return true;
const endpoint = `projects/${this.id}/members`;
const { username } = this.getContext('gitlab');
const { id } = this.getContext('gitlab');
const endpoint = `projects/${this.id}/members/all/${id}`;
try {
const body = await this.request(endpoint, { method: 'GET' });
const user = _.find(body, { username });
const user = await this.request(endpoint, { method: 'GET' });
return user && user.access_level >= 30;
} catch (err) {
this.debug(err);
Expand Down
6 changes: 3 additions & 3 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "release-it",
"version": "12.6.0",
"version": "12.6.2",
"description": "CLI release tool for Git repos and npm packages.",
"keywords": [
"build",
Expand Down Expand Up @@ -81,7 +81,7 @@
"supports-color": "7.1.0",
"update-notifier": "4.1.0",
"url-join": "4.0.1",
"uuid": "3.4.0",
"uuid": "7.0.1",
"window-size": "1.1.1",
"yaml": "1.7.2",
"yargs-parser": "17.0.0"
Expand All @@ -96,7 +96,7 @@
"eslint-plugin-import": "2.20.1",
"eslint-plugin-prettier": "3.1.2",
"markdown-toc": "1.2.0",
"mock-fs": "4.10.4",
"mock-fs": "4.11.0",
"mock-stdio": "1.0.3",
"nock": "12.0.1",
"nyc": "15.0.0",
Expand Down
14 changes: 7 additions & 7 deletions test/gitlab.js
Expand Up @@ -2,7 +2,7 @@ const test = require('ava');
const sinon = require('sinon');
const nock = require('nock');
const GitLab = require('../lib/plugin/gitlab/GitLab');
const { interceptUser, interceptMembers, interceptPublish, interceptAsset } = require('./stub/gitlab');
const { interceptUser, interceptCollaborator, interceptPublish, interceptAsset } = require('./stub/gitlab');
const { factory, runTasks } = require('./util');

const tokenRef = 'GITLAB_TOKEN';
Expand All @@ -20,7 +20,7 @@ test.serial('should validate token', async t => {
process.env[tokenRef] = '123'; // eslint-disable-line require-atomic-updates

interceptUser();
interceptMembers();
interceptCollaborator();
await t.notThrowsAsync(gitlab.init());
});

Expand All @@ -41,7 +41,7 @@ test.serial('should upload assets and release', async t => {
sinon.stub(gitlab, 'getLatestVersion').resolves('2.0.0');

interceptUser();
interceptMembers();
interceptCollaborator();
interceptAsset();
interceptPublish({
body: {
Expand Down Expand Up @@ -78,7 +78,7 @@ test.serial('should release to self-managed host', async t => {
sinon.stub(gitlab, 'getLatestVersion').resolves('1.0.0');

interceptUser({ host });
interceptMembers({ host });
interceptCollaborator({ host });

await runTasks(gitlab);

Expand All @@ -93,7 +93,7 @@ test.serial('should release to sub-grouped repo', async t => {
const gitlab = factory(GitLab, { options });

interceptUser({ owner: 'sub-group' });
interceptMembers({ owner: 'sub-group', group: 'group' });
interceptCollaborator({ owner: 'sub-group', group: 'group' });

await runTasks(gitlab);

Expand Down Expand Up @@ -121,7 +121,7 @@ test.serial('should throw for non-collaborator', async t => {
const options = { gitlab: { tokenRef, remoteUrl, host } };
const gitlab = factory(GitLab, { options });
const scope = nock(host);
scope.get(`/api/v4/projects/john%2Frepo/members`).reply(200, [{ username: 'emma' }]);
scope.get(`/api/v4/projects/john%2Frepo/members/all/1`).reply(200, { username: 'emma' });
interceptUser({ owner: 'john' });

await t.throwsAsync(runTasks(gitlab), {
Expand All @@ -136,7 +136,7 @@ test.serial('should throw for insufficient access level', async t => {
const options = { gitlab: { tokenRef, remoteUrl, host } };
const gitlab = factory(GitLab, { options });
const scope = nock(host);
scope.get(`/api/v4/projects/john%2Frepo/members`).reply(200, [{ username: 'john', access_level: 10 }]);
scope.get(`/api/v4/projects/john%2Frepo/members/all/1`).reply(200, { username: 'john', access_level: 10 });
interceptUser({ owner: 'john' });

await t.throwsAsync(runTasks(gitlab), {
Expand Down
14 changes: 10 additions & 4 deletions test/stub/gitlab.js
Expand Up @@ -3,12 +3,18 @@ const nock = require('nock');
module.exports.interceptUser = ({ host = 'https://gitlab.com', owner = 'user' } = {}) =>
nock(host)
.get('/api/v4/user')
.reply(200, { username: owner });
.reply(200, { id: 1, username: owner });

module.exports.interceptMembers = ({ host = 'https://gitlab.com', owner = 'user', project = 'repo', group } = {}) =>
module.exports.interceptCollaborator = ({
host = 'https://gitlab.com',
owner = 'user',
project = 'repo',
group,
userId = 1
} = {}) =>
nock(host)
.get(`/api/v4/projects/${group ? `${group}%2F` : ''}${owner}%2F${project}/members`)
.reply(200, [{ username: owner, access_level: 30 }]);
.get(`/api/v4/projects/${group ? `${group}%2F` : ''}${owner}%2F${project}/members/all/${userId}`)
.reply(200, { id: userId, username: owner, access_level: 30 });

module.exports.interceptPublish = ({ host = 'https://gitlab.com', owner = 'user', project = 'repo', body } = {}) =>
nock(host)
Expand Down
4 changes: 2 additions & 2 deletions test/tasks.js
Expand Up @@ -13,7 +13,7 @@ const { mkTmpDir, gitAdd } = require('./util/helpers');
const ShellStub = require('./stub/shell');
const {
interceptUser: interceptGitLabUser,
interceptMembers: interceptGitLabMembers,
interceptCollaborator: interceptGitLabCollaborator,
interceptPublish: interceptGitLabPublish,
interceptAsset: interceptGitLabAsset
} = require('./stub/gitlab');
Expand Down Expand Up @@ -218,7 +218,7 @@ test.serial('should release all the things (pre-release, github, gitlab)', async
interceptGitHubPublish({ owner, project, body: { draft: false, tag_name: 'v1.1.0-alpha.0' } });

interceptGitLabUser({ owner });
interceptGitLabMembers({ owner, project });
interceptGitLabCollaborator({ owner, project });
interceptGitLabAsset({ owner, project });
interceptGitLabPublish({
owner,
Expand Down

0 comments on commit 3586a78

Please sign in to comment.