go.fuchsia.dev/infra@v0.0.0-20240507153436-9b593402251b/cmd/issuetracker/main.go (about) 1 // Copyright 2023 The Fuchsia Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // This is a thin wrapper around the IssueTracker API. It's specifically intended 6 // for use by the tree-closer, which needs to open an issue for every time it closes 7 // the tree. 8 package main 9 10 import ( 11 "encoding/json" 12 "flag" 13 "fmt" 14 "log" 15 "os" 16 "strconv" 17 18 "go.fuchsia.dev/infra/issuetracker" 19 ) 20 21 func main() { 22 newIssueCmd := flag.NewFlagSet("new-issue", flag.ExitOnError) 23 summary := newIssueCmd.String("summary", "", "title of the issue") 24 description := newIssueCmd.String("description", "", "issue body text") 25 componentID := newIssueCmd.Int64("component-id", 0, "component to file under") 26 27 if len(os.Args) < 2 { 28 log.Fatalf("expected subcommand") 29 } 30 31 switch os.Args[1] { 32 case newIssueCmd.Name(): 33 newIssueCmd.Parse(os.Args[2:]) 34 err := createNewIssue(*summary, *description, *componentID) 35 if err != nil { 36 log.Fatalf("failed to create issue: %s", err) 37 } 38 default: 39 log.Fatalf("invalid subcommand: %q", os.Args[1]) 40 } 41 } 42 43 func createNewIssue(summary, description string, componentID int64) error { 44 mr, err := issuetracker.NewIssueTrackerFromLUCIContext() 45 if err != nil { 46 return err 47 } 48 req := issuetracker.Issue{ 49 IssueState: issuetracker.IssueState{ 50 ComponentID: strconv.Itoa(int(componentID)), 51 Type: "BUG", 52 Status: "NEW", 53 Priority: "P2", 54 Severity: "S2", 55 Title: summary, 56 AccessLimit: issuetracker.AccessLimit{ 57 AccessLevel: "LIMIT_VIEW_TRUSTED", 58 }, 59 }, 60 IssueComment: issuetracker.IssueComment{ 61 Comment: description, 62 FormattingMode: "MARKDOWN", 63 }, 64 } 65 66 resp, err := mr.AddIssue(req) 67 if err != nil { 68 return err 69 } 70 output, err := json.Marshal(resp) 71 if err != nil { 72 return err 73 } 74 fmt.Println(string(output)) 75 return nil 76 }