Skip to content

Commit 0cea876

Browse files
rchtgptyashk2000
authored andcommitted
✨ cli: Add github issue title fetcher
1 parent 96c0584 commit 0cea876

File tree

7 files changed

+120
-23
lines changed

7 files changed

+120
-23
lines changed

index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
const chalk = require('chalk');
21
const clear = require('clear');
32
const figlet = require('figlet');
43
const cowsay = require('cowsay');
54
const files = require('./lib/files.js');
6-
const remoteUrl = require('./lib/remoteRepoLink.js');
7-
const { getCurrentDirectoryGitRemoteUrl } = require('./lib/remoteRepoLink.js');
5+
const { getQuestions } = require('./lib/inquirer.js');
86

97
clear();
108

11-
// prints tool name on start
9+
// displays Gitgo on start
1210
if (files.directoryExists('.git')) {
1311
console.log(figlet.textSync('Gitgo', {
1412
horizontalLayout: 'default',
1513
verticalLayout: 'default',
16-
}));
17-
getCurrentDirectoryGitRemoteUrl();
14+
}), '\n');
15+
// asks task based questions
16+
getQuestions();
1817
} else {
18+
// checks if the directory is a git based repo or not
1919
console.log(cowsay.say({
2020
text: 'Not a git repository!',
21-
T: "U "
21+
T: 'U '
2222
}
2323
));
2424
process.exit();

lib/files.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ const path = require('path');
33

44
module.exports = {
55
getCurrentDirectoryBase: () => {
6+
// gets the basename of the directory
67
return path.basename(process.cwd());
78
},
89

910
directoryExists: (filePath) => {
11+
// gets the whole directory list
1012
return fs.existsSync(filePath);
1113
}
1214
};

lib/inquirer.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
var inquirer = require('inquirer');
2+
var emoji = require('node-emoji')
3+
const { getIssue } = require('./issue.js');
4+
5+
module.exports = {
6+
getQuestions: async () => {
7+
8+
inquirer.prompt([
9+
{
10+
// expects issue number as response
11+
type: 'string', message: 'Which issue are you working on today?', name: 'issue'
12+
}
13+
])
14+
.then(answers => {
15+
const _issueNumber = answers['issue'];
16+
inquirer.prompt([{
17+
// displays emoji based MCQ
18+
type: 'list',
19+
message: 'What is the type of issue?',
20+
name: 'issueType',
21+
choices: [
22+
`${emoji.get(':tada:')} Initial commit`,
23+
`${emoji.get(':sparkles:')} Adding a new user-facing feature`,
24+
`${emoji.get(':art:')} Improving UI`,
25+
`${emoji.get(':package:')} Refactoring or improving code`,
26+
`${emoji.get(':racehorse:')} Improving performance`,
27+
`${emoji.get(':lock:')} Improving security`,
28+
`${emoji.get(':wrench:')} Updating configs`,
29+
`${emoji.get(':wheelchair:')} Improving accessibility`,
30+
`${emoji.get(':rocket:')} Improving dev tools`,
31+
`${emoji.get(':pencil:')} Writing docs`,
32+
`${emoji.get(':gem:')} New release`,
33+
`${emoji.get(':bug:')} Fixing a bug`,
34+
`${emoji.get(':boom:')} Fixing a crash`,
35+
`${emoji.get(':fire:')} Removing code/files`,
36+
`${emoji.get(':construction:')} WIP`,
37+
]
38+
}]).then(
39+
ans => {
40+
// passes issue number to the function which fetches the issue title
41+
getIssue(_issueNumber)
42+
}
43+
)
44+
})
45+
.catch(error => {
46+
if (error.isTtyError) {
47+
// Prompt couldn't render in the current environment
48+
} else {
49+
// Something else went wrong
50+
}
51+
});
52+
}
53+
};

lib/issue.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const axios = require('axios');
2+
const gitRemoteOriginUrl = require('git-remote-origin-url');
3+
var emoji = require('node-emoji');
4+
const chalk = require('chalk');
5+
6+
module.exports = {
7+
getIssue: (issueNumber) => {
8+
axios.get('https://api.github.com/users/dotrachit/repos')
9+
.then(async function (response) {
10+
for (repo in response.data) {
11+
if (response.data[repo]['clone_url'] === (await gitRemoteOriginUrl())) {
12+
var issueLink = response.data[repo]['issues_url'];
13+
const finalIssueNumber = issueNumber.replace('#', '')
14+
finalIssueLink = issueLink.
15+
replace('{/number}', `/${finalIssueNumber}`)
16+
axios.get(finalIssueLink)
17+
.then(function (res) {
18+
console.log(emoji.get(':smiley_cat:'), chalk.bold('Github Issue Title:'), res.data['title'])
19+
process.exit()
20+
})
21+
}
22+
};
23+
})
24+
.catch(function (error) {
25+
// handle error
26+
console.log(error);
27+
})
28+
}
29+
}

lib/remoteRepoLink.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

package-lock.json

Lines changed: 27 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@
2121
},
2222
"homepage": "https://github.com/dotrachit/gitgo#readme",
2323
"dependencies": {
24+
"axios": "^0.21.0",
2425
"chalk": "^4.1.0",
2526
"clear": "^0.1.0",
2627
"cowsay": "^1.4.0",
2728
"figlet": "^1.5.0",
2829
"git-remote-origin-url": "^3.1.0",
2930
"inquirer": "^7.3.3",
30-
"minimist": "^1.2.5",
31+
"node-emoji": "^1.10.0",
3132
"path": "^0.12.7"
3233
}
3334
}

0 commit comments

Comments
 (0)