-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgh-issues.js
executable file
·109 lines (98 loc) · 3.3 KB
/
gh-issues.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env node
const { program } = require('commander');
const { version, description } = require('./package.json');
const {
getUserLogin,
getThisRepoIssues,
getRepoIssues,
getIssue,
getAssignedIssuesByUser,
getAssignedIssuesByOrg,
openIssue,
updateIssueState,
updateIssue,
} = require('./issues');
// Command line options
program
.name("gh issues")
.version(version)
.description(description)
.usage('[options]')
.option('-n, --repo <name>', 'specify repo name')
.option('-org, --organization <name>', 'specify organization name')
.option('-s, --state <state>', 'specify issue state [open|closed|all], default state is open', "open")
.option('-a, --assigned', 'get issues assigned to user', false)
.option('-i, --issue <number>', 'specify an issue')
.option('-o, --open', 'open an issue')
.option('-r, --reopen <number>', 'reopen an issue')
.option('-c, --close <number>', 'close an issue')
.option('-t, --title <title>', 'set title')
.option('-b, --body <body>', 'set body', '')
.option('-m, --modify <number>', 'modify issue data');
program.addHelpText('after', `
* Option '-a' do not accept other options
* Options '-o', '-r', '-c' are only available for current repository
`
);
program.parse(process.argv);
const options = program.opts();
// Choose what to execute
if (options.modify) {
// title and body can be modified
let modifiers = [
{ "title": options.title },
{ "body": options.body },
]
let fields = "";
modifiers.forEach(element => {
if (element[Object.keys(element)[0]]) {
fields += `-f ${Object.keys(element)[0]}="${element[Object.keys(element)[0]]}" `;
}
});
console.log(updateIssue(":owner", ":repo", options.modify, fields));
}
else if (options.repo) {
if (options.user) {
if (options.issue)
console.log(getIssue(options.user, options.repo, options.issue));
else
console.log(getRepoIssues(options.user, options.repo, options.state));
}
else if (options.organization) {
if (options.issue)
console.log(getIssue(options.organization, options.repo, options.issue));
else
console.log(getRepoIssues(options.organization, options.repo, options.state));
}
else {
// This option uses auth user
if (options.issue)
console.log(getIssue(getUserLogin(), options.repo, options.issue));
else
console.log(getRepoIssues(getUserLogin(), options.repo, options.state));
}
}
else if (options.assigned) {
console.log(getAssignedIssuesByUser(options.state));
}
else if (options.organization) {
console.log(getAssignedIssuesByOrg(options.organization, options.state));
}
else if (options.user) {
console.log(getRepoIssues());
}
else if (options.open && options.title) {
console.log(openIssue(options.title, options.body, ":owner", ":repo"));
}
else if (options.close) {
console.log(updateIssueState(":owner", ":repo", options.close, "close"));
}
else if (options.reopen) {
console.log(updateIssueState(":owner", ":repo", options.reopen, "open"));
}
else {
if (options.issue)
console.log(getIssue(":owner", ":repo", options.issue));
else
console.log(getThisRepoIssues(options.state));
}