-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_issue.go
More file actions
67 lines (57 loc) · 1.45 KB
/
update_issue.go
File metadata and controls
67 lines (57 loc) · 1.45 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"encoding/json"
"net/http"
"strconv"
"strings"
"github.com/go-martini/martini"
"github.com/supu-io/messages"
)
// UpdateAttr json to update an issue
type UpdateAttr struct {
Status string `json:"status"`
}
// UpdateIssue is the PUT /issue/:issue and updates an Issue status
func UpdateIssue(r *http.Request, params martini.Params) string {
decoder := json.NewDecoder(r.Body)
var t UpdateAttr
decoder.Decode(&t)
status := t.Status
if valid, statuses := isValidStatus(status); valid == false {
st := strings.Join(statuses, ", ")
return GetErrorMessage("Invalid status, valid statuses: " + st)
}
fullID := params["issue"]
if params["owner"] != "" && params["repo"] != "" {
fullID = params["owner"] + "/" + params["repo"] + "/" + params["issue"]
}
number, _ := strconv.Atoi(params["issue"])
c := config()
msg := messages.UpdateIssue{
Issue: &messages.Issue{
ID: fullID,
Number: number,
Repo: params["repo"],
Org: params["owner"],
Status: issueCurrentStatus(params),
},
Status: status,
Config: messages.Config{
Github: &messages.Github{
Token: c.Github.Token,
},
},
Workflow: getWorkflow(),
}
return Request("workflow.move", msg)
}
// Get the issue current status
func issueCurrentStatus(params martini.Params) string {
data := GetIssue(params)
type tmp struct {
Status string `json:"status"`
}
details := tmp{}
json.Unmarshal([]byte(data), &details)
return details.Status
}