Browse Source

#1821

update
pull/2019/head
chenyifan01 3 years ago
parent
commit
20eb12740f
5 changed files with 68 additions and 1 deletions
  1. +32
    -0
      models/issue.go
  2. +2
    -0
      models/issue_comment.go
  3. +24
    -1
      routers/repo/issue.go
  4. +1
    -0
      routers/routes/routes.go
  5. +9
    -0
      services/issue/content.go

+ 32
- 0
models/issue.go View File

@@ -775,6 +775,38 @@ func (issue *Issue) ChangeContent(doer *User, content string) (err error) {
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
func (issue *Issue) GetTasks() int {
return len(issueTasksPat.FindAllStringIndex(issue.Content, -1))


+ 2
- 0
models/issue_comment.go View File

@@ -48,6 +48,8 @@ const (
CommentTypePullRef
// Labels changed
CommentTypeLabel
// Ref changed
CommentTypeRef
// Milestone changed
CommentTypeMilestone
// Assignees changed


+ 24
- 1
routers/repo/issue.go View File

@@ -432,7 +432,7 @@ func RetrieveRepoMetas(ctx *context.Context, repo *models.Repository, isPull boo
return nil
}

brs, _, err := ctx.Repo.GitRepo.GetBranches(0,0)
brs, _, err := ctx.Repo.GitRepo.GetBranches(0, 0)
if err != nil {
ctx.ServerError("GetBranches", err)
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
func UpdateIssueMilestone(ctx *context.Context) {
issues := getActionIssues(ctx)


+ 1
- 0
routers/routes/routes.go View File

@@ -868,6 +868,7 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Group("/:index", func() {
m.Post("/title", repo.UpdateIssueTitle)
m.Post("/content", repo.UpdateIssueContent)
m.Post("/ref", repo.UpdateIssueRef)
m.Post("/watch", repo.IssueWatch)
m.Group("/dependency", func() {
m.Post("/add", repo.AddDependency)


+ 9
- 0
services/issue/content.go View File

@@ -21,3 +21,12 @@ func ChangeContent(issue *models.Issue, doer *models.User, content string) (err

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
}

Loading…
Cancel
Save