This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-helper.js
47 lines (42 loc) · 1.47 KB
/
git-helper.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
const { execSync } = require('child_process')
const { die } = require('./util')
// Grab local remote info using system git for use when a repo param isn't provided
exports.getLocalRepoName = function() {
let rawRemoteOutput;
try {
rawRemoteOutput = execSync(`git remote -v 2>/dev/null`).toString()
if (!rawRemoteOutput.includes('github')){
throw new Error()
}
} catch (err) {
die('ERR: Only public Github repos (and *nix environments) are currently supported. Did you mean to use "-r user/repo"?')
}
//This is a bit wild, but works well enough, and might just work on windows too?
let remoteUrl = rawRemoteOutput.split(/\s+/)[1]
let repoName = remoteUrl.split(/[\/:]/).slice(-2).join('/').toLowerCase()
return repoName
}
// Output full issue information
exports.printFullIssueById = function(issueId, issueCache){
const issueById = issueCache.find((item) => item.number == issueId)
if (issueById){
console.log(exports.issueFullText(issueById))
} else {
die(`Issue ${issueId} not found locally - might be the cache, or it might not exist`)
}
}
exports.username = function(){
return 'user'
}
exports.issueSummaryText = function(issue) {
let result = `#${issue.number} ${issue.title} `
if (issue.milestone){
result += `(milestone: '${issue.milestone.title}')`
}
return result
}
exports.issueFullText = function(issue) {
let baseResult = exports.issueSummaryText(issue)
baseResult += `\n\nDESC:\n${issue.body}\n`
return baseResult
}