fix(issue): preserve metadata on update #81
|
|
@ -18,6 +18,8 @@ func v1RepoPath(ctx *common.RuntimeContext) string {
|
|||
type existingIssue struct {
|
||||
Subject string
|
||||
Description string
|
||||
StatusID interface{}
|
||||
PriorityID interface{}
|
||||
}
|
||||
|
||||
func Shortcuts() []*common.Shortcut {
|
||||
|
|
@ -174,6 +176,12 @@ func Shortcuts() []*common.Shortcut {
|
|||
"subject": current.Subject,
|
||||
"description": current.Description,
|
||||
}
|
||||
if current.StatusID != nil {
|
||||
body["status_id"] = current.StatusID
|
||||
}
|
||||
if current.PriorityID != nil {
|
||||
body["priority_id"] = current.PriorityID
|
||||
}
|
||||
if t := ctx.Arg("title"); t != "" {
|
||||
body["subject"] = t
|
||||
}
|
||||
|
|
@ -273,9 +281,23 @@ func fetchExistingIssue(ctx *common.RuntimeContext, number string) (*existingIss
|
|||
return &existingIssue{
|
||||
Subject: subject,
|
||||
Description: description,
|
||||
StatusID: issueIDValue(issueData, "status_id", "status"),
|
||||
PriorityID: issueIDValue(issueData, "priority_id", "priority"),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func issueIDValue(issueData map[string]interface{}, idKey, objectKey string) interface{} {
|
||||
if id, ok := issueData[idKey]; ok && id != nil {
|
||||
return id
|
||||
}
|
||||
if obj, ok := issueData[objectKey].(map[string]interface{}); ok {
|
||||
if id, ok := obj["id"]; ok && id != nil {
|
||||
return id
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func normalizeIssueStatus(state string) (interface{}, error) {
|
||||
switch strings.ToLower(strings.TrimSpace(state)) {
|
||||
case "open":
|
||||
|
|
|
|||
|
|
@ -18,6 +18,10 @@ func TestIssueClosePreservesCurrentDescription(t *testing.T) {
|
|||
writeJSON(t, w, map[string]interface{}{
|
||||
"subject": "Existing title",
|
||||
"description": "Existing description",
|
||||
"status_id": 1,
|
||||
"priority": map[string]interface{}{
|
||||
"id": 2,
|
||||
},
|
||||
})
|
||||
case r.Method == "PATCH" && r.URL.Path == "/v1/owner/repo/issues/42.json":
|
||||
updatePayload = decodeJSON(t, r)
|
||||
|
|
@ -46,6 +50,10 @@ func TestIssueUpdatePreservesCurrentDescriptionWhenChangingTitleAndState(t *test
|
|||
writeJSON(t, w, map[string]interface{}{
|
||||
"subject": "Existing title",
|
||||
"description": "Existing description",
|
||||
"status_id": 1,
|
||||
"priority": map[string]interface{}{
|
||||
"id": 2,
|
||||
},
|
||||
})
|
||||
case r.Method == "PATCH" && r.URL.Path == "/v1/owner/repo/issues/42.json":
|
||||
updatePayload = decodeJSON(t, r)
|
||||
|
|
@ -78,6 +86,10 @@ func TestIssueUpdatePreservesCurrentSubjectWhenChangingDescription(t *testing.T)
|
|||
writeJSON(t, w, map[string]interface{}{
|
||||
"subject": "Existing title",
|
||||
"description": "Existing description",
|
||||
"status_id": 1,
|
||||
"priority": map[string]interface{}{
|
||||
"id": 2,
|
||||
},
|
||||
})
|
||||
case r.Method == "PATCH" && r.URL.Path == "/v1/owner/repo/issues/42.json":
|
||||
updatePayload = decodeJSON(t, r)
|
||||
|
|
@ -98,6 +110,8 @@ func TestIssueUpdatePreservesCurrentSubjectWhenChangingDescription(t *testing.T)
|
|||
|
||||
assertEqual(t, updatePayload["subject"], "Existing title")
|
||||
assertEqual(t, updatePayload["description"], "New description")
|
||||
assertEqual(t, updatePayload["status_id"], float64(1))
|
||||
assertEqual(t, updatePayload["priority_id"], float64(2))
|
||||
}
|
||||
|
||||
func TestBatchClosePreservesCurrentDescription(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue