Skip to content
This repository was archived by the owner on May 20, 2020. It is now read-only.

Commit 7adfd15

Browse files
committed
Move topics subcommand to repos
To align with how the GitHub API is organised
1 parent c8f6009 commit 7adfd15

8 files changed

+42
-42
lines changed

src/commands/topics.js src/commands/repos.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
* This project follows the example provided in the Yargs documentation for command hierarchy and directory structure.
33
* @see: https://github.com/yargs/yargs/blob/master/docs/advanced.md#commanddirdirectory-opts
44
*/
5-
exports.command = 'topics <subcommand> [...options]'
6-
exports.desc = 'Manage GitHub topics'
5+
exports.command = 'repos <subcommand> [...options]'
6+
exports.desc = 'Manage GitHub repositories'
77
exports.builder = function(yargs) {
8-
return yargs.commandDir('topics')
8+
return yargs.commandDir('repos')
99
}
1010
exports.handler = function() {}

src/commands/topics/add.js src/commands/repos/add-topics.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* const result = await octokit.repos.replaceTopics()
55
*/
66
const flow = require('lodash.flow')
7-
const { withGitHubUrl, withTopic } = require('../../lib/common-yargs')
7+
const { withGitHubUrl, withTopics } = require('../../lib/common-yargs')
88
const printOutput = require('../../lib/print-output')
99
const { addTopics } = require('../../lib/topics')
1010

@@ -18,7 +18,7 @@ const builder = yargs => {
1818
withGitHubUrl({
1919
describe: 'The URL of the GitHub repository to list the topics of.',
2020
}),
21-
withTopic({
21+
withTopics({
2222
required: true,
2323
}),
2424
])
@@ -32,9 +32,9 @@ const builder = yargs => {
3232
* @param {string} argv.token
3333
* @param {string} argv.json
3434
* @param {object} argv.githubUrl - The GitHub url parsed in the withGitHubUrl() yarg option into appropriate properties, such as `owner` and `repo`.
35-
* @param {string|array} argv.topic - The topic/s to add
35+
* @param {array} argv.topics - The topics to add
3636
*/
37-
const handler = async ({ token, json, githubUrl, topic: topicsToAdd }) => {
37+
const handler = async ({ token, json, githubUrl, topics: topicsToAdd }) => {
3838
try {
3939
const topics = await addTopics({ githubUrl, token, topics: topicsToAdd })
4040
if (json) {
@@ -49,7 +49,7 @@ const handler = async ({ token, json, githubUrl, topic: topicsToAdd }) => {
4949
}
5050

5151
module.exports = {
52-
command: 'add <github-url>',
52+
command: 'add-topics <github-url>',
5353
desc: 'Add topics to a repository.',
5454
builder,
5555
handler,

src/commands/topics/list.js src/commands/repos/list-topics.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const handler = async args => {
4646
}
4747

4848
module.exports = {
49-
command: 'list <github-url>',
49+
command: 'list-topics <github-url>',
5050
desc: 'List all topics of a repository.',
5151
builder,
5252
handler,

src/commands/topics/remove.js src/commands/repos/remove-topics.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/**
22
* @see: https://octokit.github.io/rest.js/#octokit-routes-repos-replace-topics
3-
* Add topics to a repository.
3+
* Remove topics from a repository.
44
* const result = await octokit.repos.replaceTopics()
55
*/
66
const flow = require('lodash.flow')
7-
const { withGitHubUrl, withTopic } = require('../../lib/common-yargs')
7+
const { withGitHubUrl, withTopics } = require('../../lib/common-yargs')
88
const printOutput = require('../../lib/print-output')
99
const { removeTopics } = require('../../lib/topics')
1010

@@ -18,25 +18,25 @@ const builder = yargs => {
1818
withGitHubUrl({
1919
describe: 'The URL of the GitHub repository to list the topics of.',
2020
}),
21-
withTopic({
21+
withTopics({
2222
required: true,
2323
}),
2424
])
2525
return baseOptions(yargs).example('github-url', 'Pattern: https://github.com/[owner]/[repository]')
2626
}
2727

2828
/**
29-
* Add topics to a repository.
29+
* Remove topics from a repository.
3030
*
3131
* @param {object} argv - argv parsed and filtered by yargs
3232
* @param {string} argv.token
3333
* @param {string} argv.json
3434
* @param {object} argv.githubUrl - The GitHub url parsed in the withGitHubUrl() yarg option into appropriate properties, such as `owner` and `repo`.
35-
* @param {string|array} argv.topic - The topic/s to remove
35+
* @param {array} argv.topics - The topics to remove
3636
*/
37-
const handler = async ({ token, json, githubUrl, topic: topicsToAdd }) => {
37+
const handler = async ({ token, json, githubUrl, topics: topicsToRemove }) => {
3838
try {
39-
const topics = await removeTopics({ githubUrl, token, topics: topicsToAdd })
39+
const topics = await removeTopics({ githubUrl, token, topics: topicsToRemove })
4040
if (json) {
4141
printOutput({ json, resource: topics })
4242
} else {
@@ -49,7 +49,7 @@ const handler = async ({ token, json, githubUrl, topic: topicsToAdd }) => {
4949
}
5050

5151
module.exports = {
52-
command: 'remove <github-url>',
52+
command: 'remove-topics <github-url>',
5353
desc: 'Remove topics from a repository.',
5454
builder,
5555
handler,

src/lib/common-yargs.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,15 @@ const withGitHubUrl = options => yargs => {
180180
)
181181
}
182182

183-
const withTopic = options => yargs => {
183+
const withTopics = options => yargs => {
184184
return yargs
185185
.option(
186-
'topic',
186+
'topics',
187187
Object.assign(
188188
{
189-
alias: ['topics'],
189+
alias: ['topic'],
190190
type: 'string',
191-
describe: 'GitHub topic to add. To add more than one, add multiple option and values or a comma separated list',
191+
describe: 'GitHub topics to add. To add more than one, add multiple options or a comma separated list',
192192
},
193193
options
194194
)
@@ -205,5 +205,5 @@ module.exports = {
205205
withReviewers,
206206
withTeamReviewers,
207207
withGitHubUrl,
208-
withTopic,
208+
withTopics,
209209
}

test/commands/topics/add.test.js test/commands/repos/add-topics.test.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const nock = require('nock')
22
const commonTests = require('../../common-tests')
3-
const yargsModule = require('../../../src/commands/topics/add')
3+
const yargsModule = require('../../../src/commands/repos/add-topics')
44

55
beforeEach(() => {
66
jest
@@ -20,11 +20,11 @@ afterEach(() => {
2020
/**
2121
* Common Yargs tests
2222
*/
23-
const command = 'topics add'
23+
const command = 'repos add-topics'
2424
const requiredArguments = {
2525
options: {
2626
token: 'Test-Token',
27-
topic: 'hello',
27+
topics: ['hello'],
2828
},
2929
positionals: {
3030
'github-url': 'https://github.com/Test-Owner/Test-Repo',
@@ -33,7 +33,7 @@ const requiredArguments = {
3333
commonTests.describeYargs(yargsModule, command, requiredArguments)
3434

3535
describe('Add topic', () => {
36-
test('triggers a network requests on the GitHub API', async () => {
36+
test('triggers network requests on the GitHub API', async () => {
3737
nock('https://api.github.com')
3838
.get('/repos/Test-Owner/Test-Repo/topics')
3939
.reply(200, {
@@ -50,7 +50,7 @@ describe('Add topic', () => {
5050
const args = {
5151
token: 'Test-Token',
5252
githubUrl: { owner: 'Test-Owner', repo: 'Test-Repo' },
53-
topic: 'app',
53+
topics: ['app'],
5454
}
5555

5656
await yargsModule.handler(args)
@@ -72,7 +72,7 @@ describe('Add topic', () => {
7272
const args = {
7373
token: 'Test-Token',
7474
githubUrl: { owner: 'Test-Owner', repo: 'Test-Repo' },
75-
topic: 'hello',
75+
topics: ['hello'],
7676
}
7777
await yargsModule.handler(args)
7878
expect(console.log).toBeCalledWith('hello')
@@ -93,7 +93,7 @@ describe('Add topic', () => {
9393
const args = {
9494
token: 'Test-Token',
9595
githubUrl: { owner: 'Test-Owner', repo: 'Test-Repo' },
96-
topic: 'app',
96+
topics: ['app'],
9797
}
9898
await yargsModule.handler(args)
9999
expect(console.log).toBeCalledWith('customer-products\napp')
@@ -117,7 +117,7 @@ describe('Error output', () => {
117117
const args = {
118118
token: 'Test-Token',
119119
githubUrl: { owner: 'Test-Owner', repo: 'Test-Repo' },
120-
topic: 'app',
120+
topics: ['app'],
121121
}
122122
await yargsModule.handler(args)
123123
expect(errorResponse.isDone()).toBe(true)
@@ -137,7 +137,7 @@ describe('Error output', () => {
137137
const args = {
138138
token: 'Test-Token',
139139
githubUrl: { owner: 'Test-Owner', repo: 'Test-Repo' },
140-
topic: 'app',
140+
topics: ['app'],
141141
}
142142
await yargsModule.handler(args)
143143
expect(console.log).toBeCalledWith(expect.stringMatching(/Not found/i))

test/commands/topics/list.test.js test/commands/repos/list-topics.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const nock = require('nock')
22
const commonTests = require('../../common-tests')
3-
const yargsModule = require('../../../src/commands/topics/list')
3+
const yargsModule = require('../../../src/commands/repos/list-topics')
44

55
beforeEach(() => {
66
jest
@@ -20,7 +20,7 @@ afterEach(() => {
2020
/**
2121
* Common Yargs tests
2222
*/
23-
const command = 'topics list'
23+
const command = 'repos list-topics'
2424
const requiredArguments = {
2525
options: {
2626
token: 'Test-Token',

test/commands/topics/remove.test.js test/commands/repos/remove-topics.test.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const nock = require('nock')
22
const commonTests = require('../../common-tests')
3-
const yargsModule = require('../../../src/commands/topics/remove')
3+
const yargsModule = require('../../../src/commands/repos/remove-topics')
44

55
beforeEach(() => {
66
jest
@@ -20,11 +20,11 @@ afterEach(() => {
2020
/**
2121
* Common Yargs tests
2222
*/
23-
const command = 'topics remove'
23+
const command = 'repos remove-topics'
2424
const requiredArguments = {
2525
options: {
2626
token: 'Test-Token',
27-
topic: 'hello',
27+
topics: ['hello'],
2828
},
2929
positionals: {
3030
'github-url': 'https://github.com/Test-Owner/Test-Repo',
@@ -33,7 +33,7 @@ const requiredArguments = {
3333
commonTests.describeYargs(yargsModule, command, requiredArguments)
3434

3535
describe('Remove topic', () => {
36-
test('triggers a network requests on the GitHub API', async () => {
36+
test('triggers network requests on the GitHub API', async () => {
3737
nock('https://api.github.com')
3838
.get('/repos/Test-Owner/Test-Repo/topics')
3939
.reply(200, {
@@ -50,7 +50,7 @@ describe('Remove topic', () => {
5050
const args = {
5151
token: 'Test-Token',
5252
githubUrl: { owner: 'Test-Owner', repo: 'Test-Repo' },
53-
topic: 'app',
53+
topics: ['app'],
5454
}
5555

5656
await yargsModule.handler(args)
@@ -72,7 +72,7 @@ describe('Remove topic', () => {
7272
const args = {
7373
token: 'Test-Token',
7474
githubUrl: { owner: 'Test-Owner', repo: 'Test-Repo' },
75-
topic: 'hello',
75+
topics: ['hello'],
7676
}
7777
await yargsModule.handler(args)
7878
expect(console.log).toBeCalledWith('')
@@ -93,7 +93,7 @@ describe('Remove topic', () => {
9393
const args = {
9494
token: 'Test-Token',
9595
githubUrl: { owner: 'Test-Owner', repo: 'Test-Repo' },
96-
topic: 'app',
96+
topics: ['app'],
9797
}
9898
await yargsModule.handler(args)
9999
expect(console.log).toBeCalledWith('customer-products\nnew')
@@ -117,7 +117,7 @@ describe('Error output', () => {
117117
const args = {
118118
token: 'Test-Token',
119119
githubUrl: { owner: 'Test-Owner', repo: 'Test-Repo' },
120-
topic: 'customer-products',
120+
topics: ['customer-products'],
121121
}
122122
await yargsModule.handler(args)
123123
expect(errorResponse.isDone()).toBe(true)
@@ -137,7 +137,7 @@ describe('Error output', () => {
137137
const args = {
138138
token: 'Test-Token',
139139
githubUrl: { owner: 'Test-Owner', repo: 'Test-Repo' },
140-
topic: 'customer-products',
140+
topics: ['customer-products'],
141141
}
142142
await yargsModule.handler(args)
143143
expect(console.log).toBeCalledWith(expect.stringMatching(/Not found/i))

0 commit comments

Comments
 (0)