|
|
|
@ -10,6 +10,7 @@ import ( |
|
|
|
|
"fmt" |
|
|
|
|
"io" |
|
|
|
|
"io/ioutil" |
|
|
|
|
"strconv" |
|
|
|
|
"strings" |
|
|
|
|
"time" |
|
|
|
|
|
|
|
|
@ -644,6 +645,28 @@ func getActionIssue(ctx *context.Context) *models.Issue { |
|
|
|
|
return issue |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func getActionIssues(ctx *context.Context) []*models.Issue { |
|
|
|
|
commaSeparatedIssueIDs := ctx.Query("issue_ids") |
|
|
|
|
if len(commaSeparatedIssueIDs) == 0 { |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
issueIDs := make([]int64, 0, 10) |
|
|
|
|
for _, stringIssueID := range strings.Split(commaSeparatedIssueIDs, ",") { |
|
|
|
|
issueID, err := strconv.ParseInt(stringIssueID, 10, 64) |
|
|
|
|
if err != nil { |
|
|
|
|
ctx.Handle(500, "ParseInt", err) |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
issueIDs = append(issueIDs, issueID) |
|
|
|
|
} |
|
|
|
|
issues, err := models.GetIssuesByIDs(issueIDs) |
|
|
|
|
if err != nil { |
|
|
|
|
ctx.Handle(500, "GetIssuesByIDs", err) |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
return issues |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// UpdateIssueTitle change issue's title
|
|
|
|
|
func UpdateIssueTitle(ctx *context.Context) { |
|
|
|
|
issue := getActionIssue(ctx) |
|
|
|
@ -697,26 +720,23 @@ func UpdateIssueContent(ctx *context.Context) { |
|
|
|
|
|
|
|
|
|
// UpdateIssueMilestone change issue's milestone
|
|
|
|
|
func UpdateIssueMilestone(ctx *context.Context) { |
|
|
|
|
issue := getActionIssue(ctx) |
|
|
|
|
issues := getActionIssues(ctx) |
|
|
|
|
if ctx.Written() { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
oldMilestoneID := issue.MilestoneID |
|
|
|
|
milestoneID := ctx.QueryInt64("id") |
|
|
|
|
for _, issue := range issues { |
|
|
|
|
oldMilestoneID := issue.MilestoneID |
|
|
|
|
if oldMilestoneID == milestoneID { |
|
|
|
|
ctx.JSON(200, map[string]interface{}{ |
|
|
|
|
"ok": true, |
|
|
|
|
}) |
|
|
|
|
return |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Not check for invalid milestone id and give responsibility to owners.
|
|
|
|
|
issue.MilestoneID = milestoneID |
|
|
|
|
if err := models.ChangeMilestoneAssign(issue, ctx.User, oldMilestoneID); err != nil { |
|
|
|
|
ctx.Handle(500, "ChangeMilestoneAssign", err) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ctx.JSON(200, map[string]interface{}{ |
|
|
|
|
"ok": true, |
|
|
|
@ -725,24 +745,53 @@ func UpdateIssueMilestone(ctx *context.Context) { |
|
|
|
|
|
|
|
|
|
// UpdateIssueAssignee change issue's assignee
|
|
|
|
|
func UpdateIssueAssignee(ctx *context.Context) { |
|
|
|
|
issue := getActionIssue(ctx) |
|
|
|
|
issues := getActionIssues(ctx) |
|
|
|
|
if ctx.Written() { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
assigneeID := ctx.QueryInt64("id") |
|
|
|
|
for _, issue := range issues { |
|
|
|
|
if issue.AssigneeID == assigneeID { |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
if err := issue.ChangeAssignee(ctx.User, assigneeID); err != nil { |
|
|
|
|
ctx.Handle(500, "ChangeAssignee", err) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
ctx.JSON(200, map[string]interface{}{ |
|
|
|
|
"ok": true, |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// UpdateIssueStatus change issue's status
|
|
|
|
|
func UpdateIssueStatus(ctx *context.Context) { |
|
|
|
|
issues := getActionIssues(ctx) |
|
|
|
|
if ctx.Written() { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if err := issue.ChangeAssignee(ctx.User, assigneeID); err != nil { |
|
|
|
|
ctx.Handle(500, "ChangeAssignee", err) |
|
|
|
|
return |
|
|
|
|
var isClosed bool |
|
|
|
|
switch action := ctx.Query("action"); action { |
|
|
|
|
case "open": |
|
|
|
|
isClosed = false |
|
|
|
|
case "close": |
|
|
|
|
isClosed = true |
|
|
|
|
default: |
|
|
|
|
log.Warn("Unrecognized action: %s", action) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if _, err := models.IssueList(issues).LoadRepositories(); err != nil { |
|
|
|
|
ctx.Handle(500, "LoadRepositories", err) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
for _, issue := range issues { |
|
|
|
|
if err := issue.ChangeStatus(ctx.User, issue.Repo, isClosed); err != nil { |
|
|
|
|
ctx.Handle(500, "ChangeStatus", err) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
ctx.JSON(200, map[string]interface{}{ |
|
|
|
|
"ok": true, |
|
|
|
|
}) |
|
|
|
|