@@ -775,6 +775,38 @@ func (issue *Issue) ChangeContent(doer *User, content string) (err error) { | |||||
return sess.Commit() | return sess.Commit() | ||||
} | } | ||||
// ChangeRef changes issue ref, as the given user. | |||||
func (issue *Issue) ChangeRef(doer *User, newRef string) (err error) { | |||||
oldRef := issue.Ref | |||||
issue.Ref = newRef | |||||
sess := x.NewSession() | |||||
defer sess.Close() | |||||
if err = sess.Begin(); err != nil { | |||||
return err | |||||
} | |||||
if err = updateIssueCols(sess, issue, "ref"); err != nil { | |||||
sess.Rollback() | |||||
return fmt.Errorf("UpdateIssueCols: %v", err) | |||||
} | |||||
var opts = &CreateCommentOptions{ | |||||
Type: CommentTypeRef, | |||||
Doer: doer, | |||||
Repo: issue.Repo, | |||||
Issue: issue, | |||||
OldRef: oldRef, | |||||
NewRef: newRef, | |||||
} | |||||
if _, err = createComment(sess, opts); err != nil { | |||||
sess.Rollback() | |||||
return err | |||||
} | |||||
return sess.Commit() | |||||
} | |||||
// GetTasks returns the amount of tasks in the issues content | // GetTasks returns the amount of tasks in the issues content | ||||
func (issue *Issue) GetTasks() int { | func (issue *Issue) GetTasks() int { | ||||
return len(issueTasksPat.FindAllStringIndex(issue.Content, -1)) | return len(issueTasksPat.FindAllStringIndex(issue.Content, -1)) | ||||
@@ -48,6 +48,8 @@ const ( | |||||
CommentTypePullRef | CommentTypePullRef | ||||
// Labels changed | // Labels changed | ||||
CommentTypeLabel | CommentTypeLabel | ||||
// Ref changed | |||||
CommentTypeRef | |||||
// Milestone changed | // Milestone changed | ||||
CommentTypeMilestone | CommentTypeMilestone | ||||
// Assignees changed | // Assignees changed | ||||
@@ -432,7 +432,7 @@ func RetrieveRepoMetas(ctx *context.Context, repo *models.Repository, isPull boo | |||||
return nil | return nil | ||||
} | } | ||||
brs, _, err := ctx.Repo.GitRepo.GetBranches(0,0) | |||||
brs, _, err := ctx.Repo.GitRepo.GetBranches(0, 0) | |||||
if err != nil { | if err != nil { | ||||
ctx.ServerError("GetBranches", err) | ctx.ServerError("GetBranches", err) | ||||
return nil | return nil | ||||
@@ -1302,6 +1302,29 @@ func UpdateIssueContent(ctx *context.Context) { | |||||
}) | }) | ||||
} | } | ||||
// UpdateIssueRef change issue's code reference | |||||
func UpdateIssueRef(ctx *context.Context) { | |||||
issue := GetActionIssue(ctx) | |||||
if ctx.Written() { | |||||
return | |||||
} | |||||
if !ctx.IsSigned || (ctx.User.ID != issue.PosterID && !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull)) { | |||||
ctx.Error(403) | |||||
return | |||||
} | |||||
ref := ctx.Query("ref") | |||||
if err := issue_service.ChangeRef(issue, ctx.User, ref); err != nil { | |||||
ctx.ServerError("ChangeRef", err) | |||||
return | |||||
} | |||||
ctx.JSON(200, map[string]interface{}{ | |||||
"ref": issue.Ref, | |||||
}) | |||||
} | |||||
// UpdateIssueMilestone change issue's milestone | // UpdateIssueMilestone change issue's milestone | ||||
func UpdateIssueMilestone(ctx *context.Context) { | func UpdateIssueMilestone(ctx *context.Context) { | ||||
issues := getActionIssues(ctx) | issues := getActionIssues(ctx) | ||||
@@ -868,6 +868,7 @@ func RegisterRoutes(m *macaron.Macaron) { | |||||
m.Group("/:index", func() { | m.Group("/:index", func() { | ||||
m.Post("/title", repo.UpdateIssueTitle) | m.Post("/title", repo.UpdateIssueTitle) | ||||
m.Post("/content", repo.UpdateIssueContent) | m.Post("/content", repo.UpdateIssueContent) | ||||
m.Post("/ref", repo.UpdateIssueRef) | |||||
m.Post("/watch", repo.IssueWatch) | m.Post("/watch", repo.IssueWatch) | ||||
m.Group("/dependency", func() { | m.Group("/dependency", func() { | ||||
m.Post("/add", repo.AddDependency) | m.Post("/add", repo.AddDependency) | ||||
@@ -21,3 +21,12 @@ func ChangeContent(issue *models.Issue, doer *models.User, content string) (err | |||||
return nil | return nil | ||||
} | } | ||||
// ChangeRef changes issue ref, as the given user. | |||||
func ChangeRef(issue *models.Issue, doer *models.User, ref string) (err error) { | |||||
if err := issue.ChangeRef(doer, ref); err != nil { | |||||
return err | |||||
} | |||||
return nil | |||||
} |