Skip to content

Commit

Permalink
Contexts (#218)
Browse files Browse the repository at this point in the history
* update cli commands to create git contexts
  • Loading branch information
Oleg Sucharevich authored Aug 19, 2018
1 parent f154a37 commit 2193f55
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const command = new Command({
required: true,
})
.option('username', {
describe: 'username that has permissions to use app password',
describe: 'username that has permissions to use application password',
alias: 'u',
required: true,
});
Expand All @@ -45,8 +45,6 @@ const command = new Command({
type: 'git.bitbucket',
data: {
sharingPolicy: argv.sharingPolicy,
host: 'bitbucket.org',
useSSL: true,
auth: {
type: 'basic',
username: argv.username,
Expand Down
29 changes: 16 additions & 13 deletions lib/interface/cli/commands/context/create/git/types/github.cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const {
} = require('../../../../../../../logic/index').api;

const LINK = 'https://github.com/settings/tokens';

const DEFAULT_API_HOST = 'api.github.com';
const DEFAULT_API_PREFIX = '/';

const command = new Command({
command: 'github <name>',
Expand All @@ -27,18 +28,16 @@ const command = new Command({
alias: 't',
required: true,
})
.option('use-ssl', {
describe: 'Connect to the git host using ssl',
choices: [true, false],
type: 'boolean',
alias: 's',
default: true,
required: true,
})
.option('host', {
describe: 'Host name of your github (without protocol)',
alias: 'h',
default: 'github.com',
default: DEFAULT_API_HOST,
required: true,
})
.option('api', {
describe: 'Prefix of the api on the given host',
alias: 'a',
default: DEFAULT_API_PREFIX,
required: true,
});
return yargs;
Expand All @@ -54,17 +53,21 @@ const command = new Command({
type: 'git.github',
data: {
sharingPolicy: argv.sharingPolicy,
host: argv.host || 'github.com',
useSSL: Boolean(argv.useSSL) || true,
auth: {
type: 'basic',
username: 'x-oauth-basic',
password: argv.accessToken,
},
},
},
};

if (argv.apiPathPrefix !== DEFAULT_API_PREFIX) {
data.spec.data.auth.apiPathPrefix = argv.apiPathPrefix;
}

if (argv.host !== DEFAULT_API_HOST) {
data.spec.data.auth.apiHost = argv.host;
}

if (!data.metadata.name || !data.spec.type) {
throw new CFError('Name and type must be provided');
Expand Down
24 changes: 9 additions & 15 deletions lib/interface/cli/commands/context/create/git/types/gitlab.cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const {
} = require('../../../../../../../logic/index').api;

const LINK = 'https://gitlab.com/profile/personal_access_tokens';
const DEFAULT_API_URL = 'https://gitlab.com/api/v4/';


const command = new Command({
Expand All @@ -27,18 +28,10 @@ const command = new Command({
alias: 't',
required: true,
})
.option('use-ssl', {
describe: 'Connect to the git host using ssl',
choices: [true, false],
type: 'boolean',
alias: 's',
default: true,
required: true,
})
.option('host', {
describe: 'Host name of your gitlab (without protocol)',
alias: 'h',
default: 'gitlab.com',
.option('api-url', {
describe: 'URL of the api',
alias: 'a',
default: 'https://gitlab.com/api/v4/',
required: true,
});
return yargs;
Expand All @@ -54,17 +47,18 @@ const command = new Command({
type: 'git.gitlab',
data: {
sharingPolicy: argv.sharingPolicy,
host: argv.host || 'gitlab.com',
useSSL: Boolean(argv.useSSL) || true,
auth: {
type: 'basic',
username: 'oauth2',
password: argv.accessToken,
},
},
},
};

if (argv.apiUrl !== DEFAULT_API_URL) {
data.spec.data.auth.apiURL = argv.apiUrl;
}


if (!data.metadata.name || !data.spec.type) {
throw new CFError('Name and type must be provided');
Expand Down
17 changes: 4 additions & 13 deletions lib/interface/cli/commands/context/create/git/types/stash.cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,9 @@ const command = new Command({
alias: 'p',
required: true,
})
.option('host', {
describe: 'Host name of your stash (without protocol, may include port)',
alias: 'h',
required: true,
})
.option('use-ssl', {
describe: 'Connect to the git host using ssl',
choices: [true, false],
type: 'boolean',
alias: 's',
default: true,
.option('api-url', {
describe: 'URL of the api',
alias: 'a',
required: true,
});
return yargs;
Expand All @@ -57,12 +49,11 @@ const command = new Command({
type: 'git.stash',
data: {
sharingPolicy: argv.sharingPolicy,
host: argv.host || 'stash.com',
useSSL: Boolean(argv.useSSL) || true,
auth: {
type: 'basic',
username: argv.username,
password: argv.password,
apiURL: argv.apiUrl,
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "codefresh",
"version": "0.8.73",
"version": "0.8.74",
"description": "Codefresh command line utility",
"main": "index.js",
"preferGlobal": true,
Expand Down

0 comments on commit 2193f55

Please sign in to comment.