-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerator.go
70 lines (61 loc) · 1.57 KB
/
generator.go
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
package main
import (
"fmt"
"log"
"os"
)
func main() {
// validate and parse inputs
baseUrl := os.Getenv("JIRA_BASE_URL")
userName := os.Getenv("JIRA_USER_NAME")
apiToken := os.Getenv("JIRA_API_TOKEN")
if len(baseUrl) == 0 || len(userName) == 0 || len(apiToken) == 0 {
fmt.Println("Required environment variables: $JIRA_BASE_URL, $JIRA_USER_NAME and $JIRA_API_TOKEN.")
return
}
if len(os.Args) < 2 {
fmt.Println("Required command argument: start commit or tag")
return
}
startCommit := os.Args[1]
endCommit := ""
if len(os.Args) > 2 {
endCommit = os.Args[2]
}
// pull commit messages
commitMessages, err := getCommitMessages(startCommit, endCommit)
if err != nil {
log.Fatal(err)
}
printArray(Green+"commit messages", commitMessages)
// extract issue numbers
issueNumbers, commitsWithoutIssueNumber, err := extractJiraIssueNumbers(commitMessages)
if err != nil {
log.Fatal(err)
}
if len(commitsWithoutIssueNumber) > 0 {
printArray(Red+"commit messages without issue number", commitsWithoutIssueNumber)
}
printArray(Green+"jira issues", issueNumbers)
// pull issue details
details, issuesNotFound, err := getJiraIssues(issueNumbers, baseUrl, userName, apiToken)
if err != nil {
log.Fatal(err)
}
if len(issuesNotFound) > 0 {
printArray(Red+"issue not found", issuesNotFound)
}
printArray(Green+"issue details", details)
}
const (
Red = "\033[31m"
Green = "\033[32m"
Reset = "\033[0m"
)
func printArray(title string, data []string) {
fmt.Println(title + Reset)
for _, str := range data {
fmt.Printf("%s\n", str)
}
fmt.Println("")
}