|
| 1 | +var issue_title; |
| 2 | +var issue_labels = []; |
| 3 | +const reader = require('./jsonReader'); |
| 4 | +const { createSentence } = require('sentence-engine'); |
| 5 | + |
| 6 | +var retext = require('retext'); |
| 7 | +var pos = require('retext-pos'); |
| 8 | +var keywords = require('retext-keywords'); |
| 9 | +var toString = require('nlcst-to-string'); |
| 10 | +var emoji = require('node-emoji'); |
| 11 | +var branch_names = []; |
| 12 | + |
| 13 | +stopwords = ['a', 'the']; |
| 14 | + |
| 15 | +function branchName() { |
| 16 | + reader.jsonReader('../../.gitgo', (err, conf) => { |
| 17 | + if (err) { |
| 18 | + console.log(err) |
| 19 | + return |
| 20 | + } |
| 21 | + issue_title = conf.current_issue.title; |
| 22 | + retext() |
| 23 | + .use(pos) |
| 24 | + .use(keywords) |
| 25 | + .process(conf.current_issue.title, done) |
| 26 | + |
| 27 | + function done(err, file) { |
| 28 | + if (err) throw err |
| 29 | + |
| 30 | + var keywords_list = [] |
| 31 | + file.data.keywords.forEach(function (keyword) { |
| 32 | + keywords_list.push(toString(keyword.matches[0].node)) |
| 33 | + }) |
| 34 | + |
| 35 | + console.log() |
| 36 | + var key_phrases = [] |
| 37 | + file.data.keyphrases.forEach(function (phrase) { |
| 38 | + key_phrases.push(phrase.matches[0].nodes.map(stringify).join('')); |
| 39 | + function stringify(value) { |
| 40 | + return toString(value) |
| 41 | + } |
| 42 | + |
| 43 | + key_phrases.forEach(function (phrase) { |
| 44 | + phrase = phrase.split(" ").join("-").toLowerCase(); |
| 45 | + branch_names.push(phrase); |
| 46 | + }) |
| 47 | + |
| 48 | + if (branch_names.length == 0) { |
| 49 | + keyword_bn = keywords_list.join("-"); |
| 50 | + branch_names.push(keyword_bn); |
| 51 | + } |
| 52 | + console.log("Suggested branch name") |
| 53 | + console.log(branch_names); |
| 54 | + |
| 55 | + }) |
| 56 | + } |
| 57 | + }); |
| 58 | + |
| 59 | +} |
| 60 | + |
| 61 | +function suggestCommitMsg() { |
| 62 | + reader.jsonReader('../../.gitgo', (err, conf) => { |
| 63 | + if (err) { |
| 64 | + console.log(err) |
| 65 | + return |
| 66 | + } |
| 67 | + |
| 68 | + issue_labels = conf.current_issue.labels; |
| 69 | + issue_title = conf.current_issue.title; |
| 70 | + issue_title = remove_stopwords(issue_title); |
| 71 | + const commitTemplate = '{emoticon} {label}: {commitMsg}'; |
| 72 | + const vocabulary = { |
| 73 | + emoticon: [`${emoji.get(':tada:')}`, `${emoji.get(':rocket:')}`, `${emoji.get(':sparkles:')}`], |
| 74 | + label: issue_labels, |
| 75 | + commitMsg: [issue_title] |
| 76 | + }; |
| 77 | + const anInstanceOfTheSentenceClass = createSentence(commitTemplate, vocabulary, { capitalize: true }); |
| 78 | + console.log("Suggested commit message") |
| 79 | + console.log(anInstanceOfTheSentenceClass.value); |
| 80 | + }); |
| 81 | +}; |
| 82 | + |
| 83 | +function remove_stopwords(str) { |
| 84 | + res = [] |
| 85 | + words = str.split(' ') |
| 86 | + for (i = 0; i < words.length; i++) { |
| 87 | + word_clean = words[i].split(".").join("") |
| 88 | + if (!stopwords.includes(word_clean)) { |
| 89 | + res.push(word_clean) |
| 90 | + } |
| 91 | + } |
| 92 | + return (res.join(' ')) |
| 93 | +} |
| 94 | + |
| 95 | + |
| 96 | +branchName(); |
| 97 | +suggestCommitMsg(); |
| 98 | +suggestCommitMsg(); |
| 99 | +suggestCommitMsg(); |
| 100 | + |
| 101 | + |
| 102 | + |
| 103 | + |
| 104 | + |
| 105 | + |
0 commit comments