-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateHandler.go
More file actions
46 lines (38 loc) · 874 Bytes
/
createHandler.go
File metadata and controls
46 lines (38 loc) · 874 Bytes
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
package main
import (
"flag"
"fmt"
// "gopl/ch4/gitcmd/cli"
"log"
"os"
)
var createFlag = flag.NewFlagSet("create", flag.ExitOnError)
var createFlagTitle = createFlag.String("title", "", "title of issue")
var createFlagBody = createFlag.String("body", "", "body of issue")
func createIssue(title, body, token string) {
editor := os.Getenv("EDITOR")
// get repo
repo := fetchRepo()
var data map[string]string
if editor != "" {
fields := map[string]string{
"title": "",
"body": "",
}
data = getFromEditor(editor, fields)
} else {
data = map[string]string{
"title": title,
}
if body != "" { data["body"] = body }
}
if data["title"] == "" {
log.Fatal("error: title field is required")
}
result, err := Create(repo, data, token)
if err != nil {
log.Fatal(err)
}
fmt.Println("Issue Created successfully")
displayIssue(result)
}