Skip to content
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
1 change: 1 addition & 0 deletions .gitgo
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"cleanup": "fire",
"wip": "construction"
},
"existing_branches": [],
"current_branch": "",
"current_emoji": "",
"current_commit_message": ""
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.vscode/
node_modules/
lib/dist
lib/funcs/dist/
78 changes: 23 additions & 55 deletions lib/funcs/generate.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
var issue_title;
var issue_labels = [];
const reader = require('./jsonReader');
const { createSentence } = require('sentence-engine');
const cowsay = require('cowsay');

var retext = require('retext');
var pos = require('retext-pos');
var keywords = require('retext-keywords');
var toString = require('nlcst-to-string');
var emoji = require('node-emoji');
var branch_names = [];

stopwords = ['a', 'the'];

function branchName() {
reader.jsonReader('../../.gitgo', (err, conf) => {
reader.jsonReader('./.gitgo', (err, conf) => {
if (err) {
console.log(err)
return
Expand All @@ -25,74 +20,47 @@ function branchName() {
.process(conf.current_issue.title, done)

function done(err, file) {
if (err) throw err

if (err) throw err;
var keywords_list = []
file.data.keywords.forEach(function (keyword) {
keywords_list.push(toString(keyword.matches[0].node))
})

console.log()
var key_phrases = []
file.data.keyphrases.forEach(function (phrase) {
key_phrases.push(phrase.matches[0].nodes.map(stringify).join(''));
function stringify(value) {
return toString(value)
}
};

key_phrases.forEach(function (phrase) {
phrase = phrase.split(" ").join("-").toLowerCase();
branch_names.push(phrase);
})
});
})

if (branch_names.length == 0) {
keyword_bn = keywords_list.join("-");
branch_names.push(keyword_bn);
}

if (branch_names.length == 0) {
keyword_bn = keywords_list.join("-");
branch_names.push(keyword_bn);
for (var item = 0; item < branch_names.length; item++) {
if (conf.existing_branches.includes(branch_names[item])) {
branch_names.pop(branch_names[item])
}
}
if (branch_names.length === 0) {
console.log(cowsay.say({
text: "Couldn't figure out a branch name for you :(",
T: 'U '
}
))
} else {
console.log("Suggested branch name")
console.log(branch_names);

})
}
});

}

function suggestCommitMsg() {
reader.jsonReader('../../.gitgo', (err, conf) => {
if (err) {
console.log(err)
return
}
}

issue_labels = conf.current_issue.labels;
issue_title = conf.current_issue.title;
issue_title = remove_stopwords(issue_title);
const commitTemplate = '{emoticon} {label}: {commitMsg}';
const vocabulary = {
emoticon: [`${emoji.get(':tada:')}`, `${emoji.get(':rocket:')}`, `${emoji.get(':sparkles:')}`],
label: issue_labels,
commitMsg: [issue_title]
};
const anInstanceOfTheSentenceClass = createSentence(commitTemplate, vocabulary, { capitalize: true });
console.log("Suggested commit message")
console.log(anInstanceOfTheSentenceClass.value);
});
};

function remove_stopwords(str) {
res = []
words = str.split(' ')
for (i = 0; i < words.length; i++) {
word_clean = words[i].split(".").join("")
if (!stopwords.includes(word_clean)) {
res.push(word_clean)
}
}
return (res.join(' '))
}

branchName();
suggestCommitMsg()
suggestCommitMsg()
suggestCommitMsg()
18 changes: 15 additions & 3 deletions lib/issue.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
const axios = require('axios');
const gitRemoteOriginUrl = require('git-remote-origin-url');
const reader = require('./funcs/jsonReader')
const reader = require('./funcs/jsonReader');
var emoji = require('node-emoji');
const chalk = require('chalk');
var titleOfIssue;
let labelsOfIssue = [];
const fs = require('fs');
const { data } = require('retext');
var finalIssueNumber;
let existingBranches = [];
let range = n => Array.from(Array(n).keys())

module.exports = {
getIssue: async (issueNumber) => {
Expand All @@ -19,9 +22,17 @@ module.exports = {
for (repo in response.data) {
if (response.data[repo]['clone_url'] === (await gitRemoteOriginUrl())) {
var issueLink = response.data[repo]['issues_url'];
finalIssueNumber = issueNumber.replace('#', '')
var branchLink = response.data[repo]['branches_url'];
finalBranchLink = branchLink.replace('{/branch}', '');
finalIssueNumber = issueNumber.replace('#', '');
axios.get(finalBranchLink).then(function (branchNamesRes) {
let branchData = branchNamesRes['data'];
for (i in range(branchData.length)) {
existingBranches.push(branchData[i]['name'])
}
})
finalIssueLink = issueLink.
replace('{/number}', `/${finalIssueNumber}`)
replace('{/number}', `/${finalIssueNumber}`);
axios.get(finalIssueLink)
.then(function (res) {
titleOfIssue = res.data['title'];
Expand All @@ -37,6 +48,7 @@ module.exports = {
conf.current_issue.title = titleOfIssue;
conf.current_issue.labels = labelsOfIssue;
conf.current_issue.number = finalIssueNumber;
conf.existing_branches = existingBranches;
fs.writeFile('./.gitgo', JSON.stringify(conf, null, 2), (err) => {
if (err) console.log('Error writing file:', err)
})
Expand Down