-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
95 lines (83 loc) · 2.88 KB
/
main.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package main
import (
"fmt"
"log"
"os/exec"
"runtime"
"github.com/Songmu/prompter"
"github.com/atotto/clipboard"
"github.com/fatih/color"
"github.com/rickschubert/jira-ticket/constants"
"github.com/rickschubert/jira-ticket/jira"
"github.com/rickschubert/jira-ticket/parsecliargs"
"github.com/rickschubert/jira-ticket/sdetbugnotification"
)
func openLinkInBrowser(link string) {
color.Green(fmt.Sprintf("Your new ticket has been successfully created! The link is %s \nWe will now try to open the new ticket for you in the browser.", link))
os := runtime.GOOS
switch os {
case "windows":
cmd := exec.Command("start", link)
cmd.Run()
case "darwin":
cmd := exec.Command("open", link)
cmd.Run()
case "linux":
_, err := exec.Command("which xdg-open").Output()
if err != nil {
color.Red(fmt.Sprintf("Unable to open link, please install xdg-open."))
}
cmd := exec.Command("xdg-open", link)
cmd.Run()
default:
color.Red(fmt.Sprintf("Unable to open link for unsupported OS '%s'.\n", os))
}
}
func getClipboardContent() string {
content, err := clipboard.ReadAll()
if err != nil {
return ""
} else {
return content
}
}
func getNewTicketInput(cliArgsPassed parsecliargs.CliArgs, clipboardContent string) jira.CreateNewticketInput {
var newTicketInfo jira.CreateNewticketInput
newTicketInfo.Labels = cliArgsPassed.Labels
newTicketInfo.ProjectId = cliArgsPassed.Project.Id
newTicketInfo.IssueType = cliArgsPassed.Project.IssueType
newTicketInfo.AssigneeUserId = cliArgsPassed.Project.Assignee
newTicketInfo.PriorityId = cliArgsPassed.PriorityJiraID
title, description := parsecliargs.GetTicketTitleAndDescription(cliArgsPassed, clipboardContent)
newTicketInfo.Title = title
newTicketInfo.Description = description
return newTicketInfo
}
func main() {
cliArgsPassed := parsecliargs.ValidateCommandLineArguments()
clipboardContent := getClipboardContent()
if cliArgsPassed.ParseFromClipboard {
showClipboardAndAskIfOkay(clipboardContent)
}
newTicketInput := getNewTicketInput(cliArgsPassed, clipboardContent)
if cliArgsPassed.SelfAssign {
newTicketInput.AssigneeUserId = constants.GetSettings().UserId
}
if cliArgsPassed.TransitioningJiraID != "" {
newTicketInput.TransitionId = cliArgsPassed.TransitioningJiraID
}
if cliArgsPassed.PriorityJiraID != "" {
newTicketInput.PriorityId = cliArgsPassed.PriorityJiraID
}
ticketInfo := jira.CreateNewTicket(newTicketInput)
openLinkInBrowser(ticketInfo.Link)
if cliArgsPassed.CreateKnownSDETBugNotification {
sdetbugnotification.CreateNotification(ticketInfo.Key, newTicketInput.Title, newTicketInput.Description)
}
}
func showClipboardAndAskIfOkay(clipboardContent string) {
promptMsg := fmt.Sprintf("The following text is in your clipboard. Are you sure you want to attach this to the ticket or parse a ticket out of it?\n\n%s\n\n", clipboardContent)
if !prompter.YN(promptMsg, false) {
log.Fatal("Exiting program.")
}
}