-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from paulRbr/deploy-basic-command
deploy: first take to handle `bump deploy` command 🎉
- Loading branch information
Showing
10 changed files
with
285 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import Command from '../command'; | ||
import * as flags from '../flags'; | ||
import { fileArg } from '../args'; | ||
import { cli } from '../cli'; | ||
import { VersionRequest } from '../api/models'; | ||
|
||
export default class Deploy extends Command { | ||
static description = | ||
'Create a new version of your documentation from the given file or URL'; | ||
|
||
static examples = [ | ||
`Deploy a new version of an existing documentation | ||
$> bump deploy FILE --doc <your_doc_id_or_slug> --token <your_doc_token> | ||
* Let's deploy a new documentation version on Bump... done | ||
* Your new documentation version will soon be ready | ||
`, | ||
`Deploy a new version of an existing documentation attached to a hub | ||
$> bump deploy FILE --doc <doc_slug> --hub <your_hub_id_or_slug> --token <your_doc_token> | ||
* Let's deploy a new documentation version on Bump... done | ||
* Your new documentation version will soon be ready | ||
`, | ||
]; | ||
|
||
static flags = { | ||
help: flags.help({ char: 'h' }), | ||
doc: flags.doc(), | ||
'doc-name': flags.docName(), | ||
hub: flags.hub(), | ||
token: flags.token(), | ||
'auto-create': flags.autoCreate(), | ||
}; | ||
|
||
static args = [fileArg]; | ||
|
||
/* | ||
Oclif doesn't type parsed args & flags correctly and especially | ||
required-ness which is not known by the compiler, thus the use of | ||
the non-null assertion '!' in this command. | ||
See https://github.com/oclif/oclif/issues/301 for details | ||
*/ | ||
async run(): Promise<void> { | ||
const { args, flags } = this.parse(Deploy); | ||
const [api, references] = await this.prepareDefinition(args.FILE); | ||
|
||
cli.action.start("* Let's deploy a new documentation version on Bump"); | ||
|
||
const request: VersionRequest = { | ||
documentation: flags.doc!, // eslint-disable-line @typescript-eslint/no-non-null-assertion | ||
hub: flags.hub, | ||
documentation_name: flags['doc-name'], | ||
auto_create_documentation: flags['auto-create'], | ||
definition: JSON.stringify(api.definition), | ||
references, | ||
}; | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
const response = await this.bump.postVersion(request, flags.token!); | ||
|
||
cli.action.stop(); | ||
|
||
if (response.status === 201) { | ||
cli.styledSuccess('Your new documentation version will soon be ready'); | ||
} else if (response.status === 204) { | ||
this.warn('Your documentation has not changed!'); | ||
} | ||
|
||
return; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import base, { expect } from '@oclif/test'; | ||
import nock from 'nock'; | ||
|
||
nock.disableNetConnect(); | ||
|
||
const test = base.env({ BUMP_TOKEN: 'BAR' }); | ||
|
||
describe('deploy subcommand', () => { | ||
describe('Successful deploy', () => { | ||
test | ||
.nock('https://bump.sh', (api) => api.post('/api/v1/versions').reply(201)) | ||
.stdout() | ||
.stderr() | ||
.command(['deploy', 'examples/valid/openapi.v3.json', '--doc', 'coucou']) | ||
.it('sends version to Bump', ({ stdout, stderr }) => { | ||
expect(stderr).to.match(/Let's deploy a new documentation version/); | ||
expect(stdout).to.contain('Your new documentation version will soon be ready'); | ||
}); | ||
|
||
test | ||
.nock('https://bump.sh', (api) => api.post('/api/v1/versions').reply(204)) | ||
.stderr() | ||
.command(['deploy', 'examples/valid/openapi.v3.json', '--doc', 'coucou']) | ||
.it('sends version to Bump', ({ stderr }) => { | ||
expect(stderr).to.contain("Let's deploy a new documentation version"); | ||
expect(stderr).to.contain('Your documentation has not changed!'); | ||
}); | ||
|
||
test | ||
.env({ BUMP_ID: 'coucou' }) | ||
.nock('https://bump.sh', (api) => api.post('/api/v1/versions').reply(201)) | ||
.stdout() | ||
.stderr() | ||
.command(['deploy', 'examples/valid/openapi.v3.json']) | ||
.it( | ||
'sends version to Bump with doc read from env variable', | ||
({ stdout, stderr }) => { | ||
expect(stderr).to.match(/Let's deploy a new documentation version/); | ||
expect(stdout).to.contain('Your new documentation version will soon be ready'); | ||
}, | ||
); | ||
}); | ||
|
||
describe('Server errors', () => { | ||
describe('Authentication error', () => { | ||
test | ||
.nock('https://bump.sh', (api) => api.post('/api/v1/versions').reply(401)) | ||
.stdout() | ||
.stderr() | ||
.command(['deploy', 'examples/valid/openapi.v3.json', '--doc', 'coucou']) | ||
.catch((err) => { | ||
expect(err.message).to.contain('not allowed to deploy'); | ||
throw err; | ||
}) | ||
.exit(101) | ||
.it("Doesn't create a deployed version", ({ stdout }) => { | ||
expect(stdout).to.not.contain( | ||
'Your new documentation version will soon be ready', | ||
); | ||
}); | ||
}); | ||
|
||
describe('Not found error', () => { | ||
test | ||
.nock('https://bump.sh', (api) => api.post('/api/v1/versions').reply(404)) | ||
.stdout() | ||
.stderr() | ||
.command(['deploy', 'examples/valid/openapi.v3.json', '--doc', 'coucou']) | ||
.catch((err) => { | ||
expect(err.message).to.contain( | ||
"It seems the documentation provided doesn't exist", | ||
); | ||
throw err; | ||
}) | ||
.exit(104) | ||
.it("Doesn't create a deployed version", ({ stdout }) => { | ||
expect(stdout).to.not.contain( | ||
'Your new documentation version will soon be ready', | ||
); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('User bad usages', () => { | ||
test | ||
.command(['deploy', 'FILE', '--doc', 'coucou']) | ||
.catch((err) => expect(err.message).to.match(/no such file or directory/)) | ||
.it('Fails deploying an inexistant file'); | ||
|
||
test | ||
.command(['deploy']) | ||
.exit(2) | ||
.it('exits with status 2 when no file argument is provided'); | ||
|
||
test | ||
.command(['deploy', 'examples/valid/openapi.v3.json']) | ||
.catch((err) => expect(err.message).to.match(/missing required flag(.|\n)+--doc/im)) | ||
.it('fails when no documentation id or slug is provided'); | ||
|
||
test | ||
.env({ BUMP_TOKEN: '' }, { clear: true }) | ||
.command(['deploy', 'examples/valid/openapi.v3.json', '--doc', 'coucou']) | ||
.catch((err) => | ||
expect(err.message).to.match(/missing required flag(.|\n)+--token/im), | ||
) | ||
.it('fails when no access token is provided'); | ||
}); | ||
}); |
Oops, something went wrong.