jiraq.go (1749B)
1 // Command jiraq lists Jira issues matching the provided Jira query. 2 // Queries must be provided as a single quoted argument in JQL format, 3 // such as "project = EXAMPLE and status = Done". 4 // 5 // Its usage is: 6 // 7 // jiraq [ -u url ] query 8 // 9 // The flags are: 10 // 11 // -u url 12 // The URL pointing to the root of the JIRA REST API. 13 // 14 // # Examples 15 // 16 // Print an overview of all open tickets in the project "SRE": 17 // 18 // jiraq -u https://company.example.net 'project = SRE and status != done' 19 // 20 // Subsequent examples omit the "-u" flag for brevity. 21 // List all open tickets assigned to yourself in the project "SRE": 22 // 23 // jiraq 'project = SRE and status != done and assignee = currentuser()' 24 // 25 // Print issues updated since yesterday: 26 // 27 // query='project = SRE and status != done and updated >= -24h' 28 // jiraexport `jiraq "$query" | awk '{print $1}'` 29 package main 30 31 import ( 32 "flag" 33 "fmt" 34 "log" 35 "os" 36 "path" 37 "strings" 38 39 "olowe.co/issues/jira" 40 ) 41 42 var apiRoot = flag.String("u", "http://[::1]:8080", "base URL for the JIRA API") 43 44 const usage = "usage: jiraq [-u url] query" 45 46 func init() { 47 log.SetPrefix("jiraq: ") 48 log.SetFlags(0) 49 flag.Parse() 50 } 51 52 func main() { 53 if len(os.Args) == 1 { 54 log.Fatal(usage) 55 } 56 57 confDir, err := os.UserConfigDir() 58 if err != nil { 59 log.Fatal(err) 60 } 61 confDir = path.Join(confDir, "atlassian/jira") 62 config, err := readConfig(confDir) 63 if err != nil { 64 log.Fatalln("read config:", err) 65 } 66 67 client := &jira.Client{ 68 APIRoot: config.BaseURL, 69 Username: config.Username, 70 Password: config.Password, 71 } 72 73 issues, err := client.SearchIssues(strings.Join(flag.Args(), " ")) 74 if err != nil { 75 log.Fatal(err) 76 } 77 for _, is := range issues { 78 fmt.Printf("%s-%s\t%s\n", is.Project.Name(), is.Name(), is.Summary) 79 } 80 }