Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(breaking/version): raw versions only, usage cleanup #603

Merged
merged 5 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,6 @@ rdme custompages:single path-to-markdown-file
rdme versions
```

If you wish to see the raw JSON output from our API in this response, supply the `--raw` flag.

#### Get All Information About a Particular Version

```sh
Expand All @@ -277,7 +275,7 @@ If you wish to see the raw JSON output from our API in this response, supply the
#### Create a New Version

```sh
rdme versions:create <version> | --version={project-version}
rdme versions:create <version>
```

##### Create a New Version
Expand All @@ -287,15 +285,15 @@ If you wish to automate the process of creating a new project version, and not h
For example:

```sh
rdme versions:create <version> | --version={project-version} --fork={version-fork} --main={boolean} --beta={boolean} --isPublic={boolean}
rdme versions:create <version> --fork={version-fork} --main={true|false} --beta={true|false} --isPublic={true|false}
```

See `rdme versions:create --help` for a full list of flags.

#### Update a Version

```sh
rdme versions:update --version={project-version}
rdme versions:update <version>
```

Like `versions:create`, if you wish to automate this process and not be blocked by CLI input, you can supply the necessary flags to this command. See `rdme versions:update --help` for more information.
Expand All @@ -305,7 +303,7 @@ Like `versions:create`, if you wish to automate this process and not be blocked
You can remove a specific version from your project, as well as all of the attached specs

```sh
rdme versions:delete --version={project-version}
rdme versions:delete <version>
```

### Categories
Expand Down
7 changes: 3 additions & 4 deletions __tests__/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,9 @@ Usage

Options

--key string Project API key
--version string A specific project version to view.
--raw Return raw output from the API instead of in a \\"pretty\\" format.
-h, --help Display this usage guide
--key string Project API key
--version string A specific project version to view.
-h, --help Display this usage guide

Related commands

Expand Down
4 changes: 4 additions & 0 deletions __tests__/cmds/logout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import configStore from '../../src/lib/configstore';
const cmd = new Command();

describe('rdme logout', () => {
afterEach(() => {
configStore.clear();
Copy link
Member

Choose a reason for hiding this comment

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

Oh is us not clearing this out why sometimes the login test flakes out?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think so 😬 the test bed seems a little flakier now that I added so many tests messing with configstore so I'm hoping this addresses that

});

it("should report the user as logged out if they aren't logged in", () => {
configStore.delete('email');
configStore.delete('project');
Expand Down
4 changes: 4 additions & 0 deletions __tests__/cmds/open.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import configStore from '../../src/lib/configstore';
const cmd = new Command();

describe('rdme open', () => {
afterEach(() => {
configStore.clear();
});

it('should error if no project provided', () => {
configStore.delete('project');

Expand Down
38 changes: 8 additions & 30 deletions __tests__/cmds/versions/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { Version } from '../../../src/cmds/versions';

import nock from 'nock';

import VersionsCommand from '../../../src/cmds/versions';
Expand All @@ -7,7 +9,7 @@ const key = 'API_KEY';
const version = '1.0.0';
const version2 = '2.0.0';

const versionPayload = {
const versionPayload: Version = {
createdAt: '2019-06-17T22:39:56.462Z',
is_deprecated: false,
is_hidden: false,
Expand All @@ -17,7 +19,7 @@ const versionPayload = {
version,
};

const version2Payload = {
const version2Payload: Version = {
createdAt: '2019-06-17T22:39:56.462Z',
is_deprecated: false,
is_hidden: false,
Expand Down Expand Up @@ -46,20 +48,8 @@ describe('rdme versions', () => {
.basicAuth({ user: key })
.reply(200, [versionPayload, version2Payload]);

const table = await versions.run({ key });
expect(table).toContain(version);
expect(table).toContain(version2);
mockRequest.done();
});

it('should make a request to get a list of existing versions and return them in a raw format', async () => {
const mockRequest = getAPIMock()
.get('/api/v1/version')
.basicAuth({ user: key })
.reply(200, [versionPayload, version2Payload]);

const raw = await versions.run({ key, raw: true });
expect(raw).toStrictEqual(JSON.stringify([versionPayload, version2Payload], null, 2));
const output = await versions.run({ key });
expect(output).toStrictEqual(JSON.stringify([versionPayload, version2Payload], null, 2));
mockRequest.done();
});

Expand All @@ -69,20 +59,8 @@ describe('rdme versions', () => {
.basicAuth({ user: key })
.reply(200, versionPayload);

const table = await versions.run({ key, version });
expect(table).toContain(version);
expect(table).not.toContain(version2);
mockRequest.done();
});

it('should get a specific version object if version flag provided and return it in a raw format', async () => {
const mockRequest = getAPIMock()
.get(`/api/v1/version/${version}`)
.basicAuth({ user: key })
.reply(200, versionPayload);

const raw = await versions.run({ key, version, raw: true });
expect(raw).toStrictEqual(JSON.stringify(versionPayload, null, 2));
const output = await versions.run({ key, version });
expect(output).toStrictEqual(JSON.stringify(versionPayload, null, 2));
mockRequest.done();
});
});
4 changes: 4 additions & 0 deletions __tests__/cmds/whoami.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import configStore from '../../src/lib/configstore';
const cmd = new Command();

describe('rdme whoami', () => {
afterEach(() => {
configStore.clear();
});

it('should error if user is not authenticated', () => {
configStore.delete('email');
configStore.delete('project');
Expand Down
48 changes: 0 additions & 48 deletions package-lock.json

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

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"@actions/core": "^1.6.0",
"@npmcli/ci-detect": "^2.0.0",
"chalk": "^4.1.2",
"cli-table": "^0.3.1",
"command-line-args": "^5.2.0",
"command-line-usage": "^6.0.2",
"config": "^3.1.0",
Expand Down Expand Up @@ -67,7 +66,6 @@
"@readme/better-ajv-errors": "^1.5.0",
"@readme/eslint-config": "^10.1.0",
"@readme/oas-examples": "^5.3.0",
"@types/cli-table": "^0.3.0",
"@types/command-line-args": "^5.2.0",
"@types/command-line-usage": "^5.0.2",
"@types/config": "^3.3.0",
Expand Down
21 changes: 12 additions & 9 deletions src/cmds/versions/create.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Version } from '.';
import type { CommandOptions } from '../../lib/baseCommand';

import config from 'config';
Expand All @@ -23,7 +24,7 @@ export default class CreateVersionCommand extends Command {
super();

this.command = 'versions:create';
this.usage = 'versions:create --version=<version> [options]';
this.usage = 'versions:create <version> [options]';
this.description = 'Create a new version for your project.';
this.cmdCategory = CommandCategories.VERSIONS;
this.position = 2;
Expand Down Expand Up @@ -71,6 +72,15 @@ export default class CreateVersionCommand extends Command {

const promptResponse = await promptTerminal(versionPrompt);

const body: Version = {
version,
codename: codename || '',
is_stable: main === 'true' || promptResponse.is_stable,
is_beta: beta === 'true' || promptResponse.is_beta,
from: fork || promptResponse.from,
is_hidden: promptResponse.is_stable ? false : !(isPublic === 'true' || promptResponse.is_hidden),
};

return fetch(`${config.get('host')}/api/v1/version`, {
method: 'post',
headers: cleanHeaders(
Expand All @@ -80,14 +90,7 @@ export default class CreateVersionCommand extends Command {
'Content-Type': 'application/json',
})
),
body: JSON.stringify({
version,
codename: codename || '',
is_stable: main === 'true' || promptResponse.is_stable,
is_beta: beta === 'true' || promptResponse.is_beta,
from: fork || promptResponse.from,
is_hidden: promptResponse.is_stable ? false : !(isPublic === 'true' || promptResponse.is_hidden),
}),
body: JSON.stringify(body),
})
.then(handleRes)
.then(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/cmds/versions/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class DeleteVersionCommand extends Command {
super();

this.command = 'versions:delete';
this.usage = 'versions:delete --version=<version> [options]';
this.usage = 'versions:delete <version> [options]';
this.description = 'Delete a version associated with your ReadMe project.';
this.cmdCategory = CommandCategories.VERSIONS;
this.position = 4;
Expand Down
Loading