-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdateHandler.go
More file actions
53 lines (45 loc) · 1.24 KB
/
updateHandler.go
File metadata and controls
53 lines (45 loc) · 1.24 KB
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
package main
import (
"flag"
"fmt"
// "gopl/ch4/gitcmd/cli"
"log"
"os"
)
var updateFlag = flag.NewFlagSet("update", flag.ExitOnError)
var updateFlagNumber = updateFlag.Int("n", 0, "the issue number on github")
var updateFlagTitle = updateFlag.String("title", "", "title of issue")
var updateFlagBody = updateFlag.String("body", "", "body of issue")
var updateFlagState = updateFlag.String("state", "", "state of issue")
func updateIssue(number int, title, body, state, token string) {
if number <= 0 {
log.Fatal("invalid issue number")
}
// get repo
repo := fetchRepo()
editor := os.Getenv("EDITOR")
var data map[string]string
if editor != "" {
result, err := Retrieve(number, repo)
if err != nil {
log.Fatal("Error in retrieving: ", err)
}
fields := map[string]string{
"title": result.Title,
"body": result.Body,
"state": result.State,
}
data = getFromEditor(editor, fields)
} else {
data = map[string]string{}
if title != "" { data["title"] = title }
if body != "" { data["body"] = body }
if state != "" { data["state"] = state }
}
result, err := Update(number, repo, data, token)
if err != nil {
log.Fatal("Error in updating: ", err)
}
fmt.Println("Issue updated successfully")
displayIssue(result)
}