-
Notifications
You must be signed in to change notification settings - Fork 0
/
command_file.js
executable file
·106 lines (95 loc) · 3.31 KB
/
command_file.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
#!/usr/bin/env node
let program = require('commander');
const path = require('path');
const { readOriginURL, readUpstreamURL } = require('./lib/readGitRepoURL.js');
const { fileIssue } = require('./lib/gitIssueReport.js');
const { readToken, writeToken } = require('./lib/readToken.js');
const { readData } = require('./lib/readTitleBodyFromEditor.js')
process.env.githubToken = readToken();
program
.version('0.0.1');
program
.command('token <token>')
.action(async function (token) {
await writeToken(token);
process.exit();
});
program
.command('finline <title> [<body>]')
.option('-o, --origin', 'file issue in the master(origin) repo')
.option('-u, --upstream', 'file issue in the upstream(parent) repo')
.action(async function (title, body, cmd) {
if(!process.env.githubToken) {
console.log('Please set your githubToken:\n' + 'gitiss token <token>');
process.exit();
}
if(cmd.origin) {
const url = await readOriginURL(process.cwd());
await fileIssue(url, process.env.githubToken, {
title: title,
body: body
});
} else if(cmd.upstream) {
const url = await readUpstreamURL(process.cwd());
await fileIssue(url, process.env.githubToken, {
title: title,
body: body
});
}
});
program
.command('feditor')
.option('-o, --origin', 'file issue in the master(origin) repo')
.option('-u, --upstream', 'file issue in the upstream(parent) repo')
.action(function (cmd) {
if(!process.env.githubToken) {
console.log('Please set your githubToken:\n' + 'gitiss token <token>');
process.exit();
}
const fs = require('fs');
fs.writeFileSync(__dirname + '/commit_message_file.txt',
'TITLE: \n' +
'BODY: \n' +
'\n\n\n#### GITISS #### INSTRUCTIONS Below:\n\n' +
'** Press `a` to insert text\n' +
'** Type `TITLE:` and then enter the title(compulsory)\n' +
'** Type `BODY:` and then enter the body(not compulsory)\n\n' +
'** Example: \nTITLE: sample_title \nBODY: body_text\n\n' +
'** When done editing press `Esc` and type `:wq`\n');
const child_process = require('child_process');
const vim = child_process.spawn('vim', [__dirname + '/commit_message_file.txt'], { stdio: 'inherit' });
vim.on('error', () => {
console.log('It seems there is no vim installed \n\nRun: sudo apt install vim\n');
})
vim.on('close', async (code) => {
console.log('write process exited with code: ' + code);
const data2 = await readData();
if(!data2.title || data2.title==='') {
console.log('ERROR! your title was empty');
} else {
if(cmd.origin) {
const url = await readOriginURL(process.cwd());
if(url==0) {
console.log('no origin url found');
process.exit();
}
await fileIssue(url, process.env.githubToken, {
title: data2.title,
body: data2.body
});
} else if(cmd.upstream) {
const url = await readUpstreamURL(process.cwd());
if(url==0) {
console.log('no upstream url found');
process.exit();
}
await fileIssue(url, process.env.githubToken, {
title: data2.title,
body: data2.body
});
}
}
});
});
program
.parse(process.argv);