@samitouri / QOS-React-2 / commits / c46dd23f4a

[rrm] Add commands for npm access checking/granting

Paul O’Shannessy committed Jul 25, 2016 at 15:45 UTC c46dd23f4a26bc272a59aec6c1d2f7263f6b96b2
5 files changed +127
scripts/release-manager/cli.js
+2
@@ -31,6 +31,8 @@ const COMMANDS = [
31 'stable-prs',
32 'version',
33 'npm-publish',
34 + 'npm-check-access',
35 + 'npm-grant-access',
36 ];
37
38
scripts/release-manager/commands/npm-check-access.js new
+40
@@ -0,0 +1,40 @@
1 +'use strict';
2 +
3 +const npmUtils = require('./utils/npm');
4 +const chalk = require('chalk');
5 +const opn = require('opn');
6 +
7 +module.exports = function(vorpal, app) {
8 + vorpal
9 + .command('npm-check-access')
10 + .description('Check to ensure you have correct access to npm packages')
11 + .action(function(args) {
12 + return new Promise((resolve, reject) => {
13 + const username = npmUtils.whoami(app);
14 + if (!username) {
15 + return reject(
16 + `${chalk.red('FAILED')} You aren't logged in to npm. Please run ` +
17 + `${chalk.underline(`npm adduser`)} and try again.`
18 + );
19 + }
20 +
21 + this.log(`${chalk.green('OK')} Logged in as ${chalk.bold(username)}`);
22 +
23 + const packagesNeedingAccess = npmUtils.packagesNeedingAccess(app, username);
24 +
25 + if (packagesNeedingAccess.length) {
26 + this.log(
27 + `${chalk.red('FAILED')} You don't have access to all of the packages ` +
28 + `you need. We just opened a URL to file a new issue requesting access.`
29 + );
30 + opn(
31 + npmUtils.generateAccessNeededIssue(username, packagesNeedingAccess),
32 + {wait: false}
33 + ).then(resolve);
34 + } else {
35 + this.log(`${chalk.green('OK')} You can publish all React packages`);
36 + resolve();
37 + }
38 + });
39 + });
40 +};
scripts/release-manager/commands/npm-grant-access.js new
+36
@@ -0,0 +1,36 @@
1 +'use strict';
2 +
3 +const npmUtils = require('./utils/npm');
4 +const chalk = require('chalk');
5 +
6 +module.exports = function(vorpal, app) {
7 + vorpal
8 + .command('npm-grant-access')
9 + .description('Grant access to somebody to publish React. Assumes you ran "npm-check-access" first.')
10 + .action(function(args) {
11 + return new Promise((resolve, reject) => {
12 + this.prompt({
13 + type: 'input',
14 + message: 'Who would you like to grant access to? ',
15 + name: 'username',
16 + }).then((answers) => {
17 + if (!answers.username) {
18 + return reject('ABORTING');
19 + }
20 +
21 + const packagesNeedingAccess = npmUtils.packagesNeedingAccess(app, answers.username);
22 +
23 + if (packagesNeedingAccess.length) {
24 + this.log(`${chalk.yellow('PENDING')} Granting access to ${packagesNeedingAccess}`);
25 + npmUtils.grantAccess(app, answers.username, packagesNeedingAccess);
26 + this.log(`${chalk.green('OK')} Access has been granted to ${answers.username}.`);
27 + resolve();
28 + } else {
29 + this.log(`${chalk.green('OK')} ${answers.username} already has access.`);
30 + resolve();
31 + }
32 +
33 + });
34 + });
35 + });
36 +};
scripts/release-manager/commands/utils/npm.js new
+48
@@ -0,0 +1,48 @@
1 +'use strict';
2 +
3 +const querystring = require('querystring');
4 +
5 +const PACKAGES = [
6 + 'react-addons-create-fragment',
7 + 'react-addons-css-transition-group',
8 + 'react-addons-linked-state-mixin',
9 + 'react-addons-perf',
10 + 'react-addons-pure-render-mixin',
11 + 'react-addons-shallow-compare',
12 + 'react-addons-test-utils',
13 + 'react-addons-transition-group',
14 + 'react-addons-update',
15 + 'react-dom',
16 + 'react-native-renderer',
17 + 'react',
18 +];
19 +
20 +function whoami(app) {
21 + return app.execInRepo('npm whoami');
22 +}
23 +
24 +function packagesNeedingAccess(app, username) {
25 + let packages = JSON.parse(app.execInRepo(`npm access ls-packages ${username}`));
26 + return PACKAGES.filter((pkg) => packages[pkg] !== 'read-write');
27 +}
28 +
29 +function generateAccessNeededIssue(username, packages) {
30 + let data = {
31 + title: `npm access request: ${username}`,
32 + body: `In order to publish React to npm I need access to the following repositories:
33 +${packages.map((pkg) => `- [${pkg}](https://npm.im/${pkg})`).join('\n')}`,
34 + };
35 + return `https://github.com/facebook/react/issues/new?${querystring.stringify(data)}`;
36 +}
37 +
38 +function grantAccess(app, username, packages) {
39 + packages.forEach((pkg) => {
40 + app.execInRepo(`npm owner add ${username} ${pkg}`);
41 + });
42 +}
43 +
44 +module.exports.PACKAGES = PACKAGES;
45 +module.exports.whoami = whoami;
46 +module.exports.packagesNeedingAccess = packagesNeedingAccess;
47 +module.exports.generateAccessNeededIssue = generateAccessNeededIssue;
48 +module.exports.grantAccess = grantAccess;
scripts/release-manager/package.json
+1
@@ -9,6 +9,7 @@
9 "colors": "^1.1.2",
10 "github-api": "^2.2.0",
11 "glob": "^7.0.5",
12 + "opn": "^4.0.2",
13 "semver": "^5.3.0",
14 "vorpal": "^1.10.10"
15 },