mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-27 12:53:57 +01:00
move some milestone functions to a standalone package (#8213)
This commit is contained in:
parent
99f3ee3bf3
commit
29454733b4
5 changed files with 65 additions and 44 deletions
|
@ -7,7 +7,6 @@ package models
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"code.gitea.io/gitea/modules/log"
|
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
api "code.gitea.io/gitea/modules/structs"
|
api "code.gitea.io/gitea/modules/structs"
|
||||||
"code.gitea.io/gitea/modules/timeutil"
|
"code.gitea.io/gitea/modules/timeutil"
|
||||||
|
@ -394,46 +393,6 @@ func ChangeMilestoneAssign(issue *Issue, doer *User, oldMilestoneID int64) (err
|
||||||
if err = sess.Commit(); err != nil {
|
if err = sess.Commit(); err != nil {
|
||||||
return fmt.Errorf("Commit: %v", err)
|
return fmt.Errorf("Commit: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var hookAction api.HookIssueAction
|
|
||||||
if issue.MilestoneID > 0 {
|
|
||||||
hookAction = api.HookIssueMilestoned
|
|
||||||
} else {
|
|
||||||
hookAction = api.HookIssueDemilestoned
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = issue.LoadAttributes(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
mode, _ := AccessLevel(doer, issue.Repo)
|
|
||||||
if issue.IsPull {
|
|
||||||
err = issue.PullRequest.LoadIssue()
|
|
||||||
if err != nil {
|
|
||||||
log.Error("LoadIssue: %v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
err = PrepareWebhooks(issue.Repo, HookEventPullRequest, &api.PullRequestPayload{
|
|
||||||
Action: hookAction,
|
|
||||||
Index: issue.Index,
|
|
||||||
PullRequest: issue.PullRequest.APIFormat(),
|
|
||||||
Repository: issue.Repo.APIFormat(mode),
|
|
||||||
Sender: doer.APIFormat(),
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
err = PrepareWebhooks(issue.Repo, HookEventIssues, &api.IssuePayload{
|
|
||||||
Action: hookAction,
|
|
||||||
Index: issue.Index,
|
|
||||||
Issue: issue.APIFormat(),
|
|
||||||
Repository: issue.Repo.APIFormat(mode),
|
|
||||||
Sender: doer.APIFormat(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
log.Error("PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err)
|
|
||||||
} else {
|
|
||||||
go HookQueue.Add(issue.RepoID)
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ import (
|
||||||
api "code.gitea.io/gitea/modules/structs"
|
api "code.gitea.io/gitea/modules/structs"
|
||||||
"code.gitea.io/gitea/modules/timeutil"
|
"code.gitea.io/gitea/modules/timeutil"
|
||||||
"code.gitea.io/gitea/modules/util"
|
"code.gitea.io/gitea/modules/util"
|
||||||
|
milestone_service "code.gitea.io/gitea/services/milestone"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ListIssues list the issues of a repository
|
// ListIssues list the issues of a repository
|
||||||
|
@ -345,7 +346,7 @@ func EditIssue(ctx *context.APIContext, form api.EditIssueOption) {
|
||||||
issue.MilestoneID != *form.Milestone {
|
issue.MilestoneID != *form.Milestone {
|
||||||
oldMilestoneID := issue.MilestoneID
|
oldMilestoneID := issue.MilestoneID
|
||||||
issue.MilestoneID = *form.Milestone
|
issue.MilestoneID = *form.Milestone
|
||||||
if err = models.ChangeMilestoneAssign(issue, ctx.User, oldMilestoneID); err != nil {
|
if err = milestone_service.ChangeMilestoneAssign(issue, ctx.User, oldMilestoneID); err != nil {
|
||||||
ctx.Error(500, "ChangeMilestoneAssign", err)
|
ctx.Error(500, "ChangeMilestoneAssign", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ import (
|
||||||
"code.gitea.io/gitea/modules/pull"
|
"code.gitea.io/gitea/modules/pull"
|
||||||
api "code.gitea.io/gitea/modules/structs"
|
api "code.gitea.io/gitea/modules/structs"
|
||||||
"code.gitea.io/gitea/modules/timeutil"
|
"code.gitea.io/gitea/modules/timeutil"
|
||||||
|
milestone_service "code.gitea.io/gitea/services/milestone"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ListPullRequests returns a list of all PRs
|
// ListPullRequests returns a list of all PRs
|
||||||
|
@ -402,7 +403,7 @@ func EditPullRequest(ctx *context.APIContext, form api.EditPullRequestOption) {
|
||||||
issue.MilestoneID != form.Milestone {
|
issue.MilestoneID != form.Milestone {
|
||||||
oldMilestoneID := issue.MilestoneID
|
oldMilestoneID := issue.MilestoneID
|
||||||
issue.MilestoneID = form.Milestone
|
issue.MilestoneID = form.Milestone
|
||||||
if err = models.ChangeMilestoneAssign(issue, ctx.User, oldMilestoneID); err != nil {
|
if err = milestone_service.ChangeMilestoneAssign(issue, ctx.User, oldMilestoneID); err != nil {
|
||||||
ctx.Error(500, "ChangeMilestoneAssign", err)
|
ctx.Error(500, "ChangeMilestoneAssign", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ import (
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
api "code.gitea.io/gitea/modules/structs"
|
api "code.gitea.io/gitea/modules/structs"
|
||||||
"code.gitea.io/gitea/modules/util"
|
"code.gitea.io/gitea/modules/util"
|
||||||
|
milestone_service "code.gitea.io/gitea/services/milestone"
|
||||||
|
|
||||||
"github.com/unknwon/com"
|
"github.com/unknwon/com"
|
||||||
)
|
)
|
||||||
|
@ -1086,7 +1087,7 @@ func UpdateIssueMilestone(ctx *context.Context) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
issue.MilestoneID = milestoneID
|
issue.MilestoneID = milestoneID
|
||||||
if err := models.ChangeMilestoneAssign(issue, ctx.User, oldMilestoneID); err != nil {
|
if err := milestone_service.ChangeMilestoneAssign(issue, ctx.User, oldMilestoneID); err != nil {
|
||||||
ctx.ServerError("ChangeMilestoneAssign", err)
|
ctx.ServerError("ChangeMilestoneAssign", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
59
services/milestone/milestone.go
Normal file
59
services/milestone/milestone.go
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"code.gitea.io/gitea/models"
|
||||||
|
"code.gitea.io/gitea/modules/log"
|
||||||
|
api "code.gitea.io/gitea/modules/structs"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ChangeMilestoneAssign changes assignment of milestone for issue.
|
||||||
|
func ChangeMilestoneAssign(issue *models.Issue, doer *models.User, oldMilestoneID int64) (err error) {
|
||||||
|
if err = models.ChangeMilestoneAssign(issue, doer, oldMilestoneID); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var hookAction api.HookIssueAction
|
||||||
|
if issue.MilestoneID > 0 {
|
||||||
|
hookAction = api.HookIssueMilestoned
|
||||||
|
} else {
|
||||||
|
hookAction = api.HookIssueDemilestoned
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = issue.LoadAttributes(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
mode, _ := models.AccessLevel(doer, issue.Repo)
|
||||||
|
if issue.IsPull {
|
||||||
|
err = issue.PullRequest.LoadIssue()
|
||||||
|
if err != nil {
|
||||||
|
log.Error("LoadIssue: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = models.PrepareWebhooks(issue.Repo, models.HookEventPullRequest, &api.PullRequestPayload{
|
||||||
|
Action: hookAction,
|
||||||
|
Index: issue.Index,
|
||||||
|
PullRequest: issue.PullRequest.APIFormat(),
|
||||||
|
Repository: issue.Repo.APIFormat(mode),
|
||||||
|
Sender: doer.APIFormat(),
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
err = models.PrepareWebhooks(issue.Repo, models.HookEventIssues, &api.IssuePayload{
|
||||||
|
Action: hookAction,
|
||||||
|
Index: issue.Index,
|
||||||
|
Issue: issue.APIFormat(),
|
||||||
|
Repository: issue.Repo.APIFormat(mode),
|
||||||
|
Sender: doer.APIFormat(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
log.Error("PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err)
|
||||||
|
} else {
|
||||||
|
go models.HookQueue.Add(issue.RepoID)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
Loading…
Reference in a new issue