feat(milestone_events): publish from milestone-counter choke points (service layer to avoid models->services import cycle)
This commit is contained in:
@@ -17,6 +17,7 @@ import (
|
||||
"code.gitea.io/gitea/routers/common"
|
||||
"code.gitea.io/gitea/services/context"
|
||||
"code.gitea.io/gitea/services/convert"
|
||||
milestone_events "code.gitea.io/gitea/services/milestone_events"
|
||||
)
|
||||
|
||||
// ListMilestones list milestones for a repository
|
||||
@@ -230,6 +231,7 @@ func EditMilestone(ctx *context.APIContext) {
|
||||
ctx.APIErrorInternal(err)
|
||||
return
|
||||
}
|
||||
milestone_events.PublishMilestoneProgress(ctx, milestone.ID)
|
||||
ctx.JSON(http.StatusOK, convert.ToAPIMilestone(milestone))
|
||||
}
|
||||
|
||||
@@ -269,6 +271,7 @@ func DeleteMilestone(ctx *context.APIContext) {
|
||||
ctx.APIErrorInternal(err)
|
||||
return
|
||||
}
|
||||
milestone_events.PublishMilestoneDeleted(ctx, ctx.Repo.Repository.ID, m.ID)
|
||||
ctx.Status(http.StatusNoContent)
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
"code.gitea.io/gitea/services/context"
|
||||
"code.gitea.io/gitea/services/forms"
|
||||
"code.gitea.io/gitea/services/issue"
|
||||
milestone_events "code.gitea.io/gitea/services/milestone_events"
|
||||
|
||||
"xorm.io/builder"
|
||||
)
|
||||
@@ -195,6 +196,8 @@ func EditMilestonePost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
milestone_events.PublishMilestoneProgress(ctx, m.ID)
|
||||
|
||||
ctx.Flash.Success(ctx.Tr("repo.milestones.edit_success", m.Name))
|
||||
ctx.Redirect(ctx.Repo.RepoLink + "/milestones")
|
||||
}
|
||||
@@ -221,14 +224,18 @@ func ChangeMilestoneStatus(ctx *context.Context) {
|
||||
}
|
||||
return
|
||||
}
|
||||
milestone_events.PublishMilestoneProgress(ctx, id)
|
||||
ctx.JSONRedirect(ctx.Repo.RepoLink + "/milestones?state=" + url.QueryEscape(ctx.PathParam("action")))
|
||||
}
|
||||
|
||||
// DeleteMilestone delete a milestone
|
||||
func DeleteMilestone(ctx *context.Context) {
|
||||
if err := issues_model.DeleteMilestoneByRepoID(ctx, ctx.Repo.Repository.ID, ctx.FormInt64("id")); err != nil {
|
||||
repoID := ctx.Repo.Repository.ID
|
||||
milestoneID := ctx.FormInt64("id")
|
||||
if err := issues_model.DeleteMilestoneByRepoID(ctx, repoID, milestoneID); err != nil {
|
||||
ctx.Flash.Error("DeleteMilestoneByRepoID: " + err.Error())
|
||||
} else {
|
||||
milestone_events.PublishMilestoneDeleted(ctx, repoID, milestoneID)
|
||||
ctx.Flash.Success(ctx.Tr("repo.milestones.deletion_success"))
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/gitrepo"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/storage"
|
||||
milestone_events "code.gitea.io/gitea/services/milestone_events"
|
||||
notify_service "code.gitea.io/gitea/services/notify"
|
||||
)
|
||||
|
||||
@@ -57,6 +58,10 @@ func NewIssue(ctx context.Context, repo *repo_model.Repository, issue *issues_mo
|
||||
return err
|
||||
}
|
||||
|
||||
if issue.MilestoneID > 0 {
|
||||
milestone_events.PublishMilestoneProgress(ctx, issue.MilestoneID)
|
||||
}
|
||||
|
||||
notify_service.NewIssue(ctx, issue, mentions)
|
||||
if len(issue.Labels) > 0 {
|
||||
notify_service.IssueChangeLabels(ctx, issue.Poster, issue, issue.Labels, nil)
|
||||
@@ -160,6 +165,10 @@ func DeleteIssue(ctx context.Context, doer *user_model.User, issue *issues_model
|
||||
}
|
||||
}
|
||||
|
||||
if issue.MilestoneID > 0 {
|
||||
milestone_events.PublishMilestoneProgress(ctx, issue.MilestoneID)
|
||||
}
|
||||
|
||||
notify_service.DeleteIssue(ctx, doer, issue)
|
||||
|
||||
return nil
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"code.gitea.io/gitea/models/db"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
milestone_events "code.gitea.io/gitea/services/milestone_events"
|
||||
notify_service "code.gitea.io/gitea/services/notify"
|
||||
)
|
||||
|
||||
@@ -75,6 +76,15 @@ func ChangeMilestoneAssign(ctx context.Context, issue *issues_model.Issue, doer
|
||||
return err
|
||||
}
|
||||
|
||||
// Both the previous and the new milestone may have had their issue
|
||||
// counters move; publish progress for each affected milestone.
|
||||
if oldMilestoneID > 0 {
|
||||
milestone_events.PublishMilestoneProgress(ctx, oldMilestoneID)
|
||||
}
|
||||
if issue.MilestoneID > 0 && issue.MilestoneID != oldMilestoneID {
|
||||
milestone_events.PublishMilestoneProgress(ctx, issue.MilestoneID)
|
||||
}
|
||||
|
||||
notify_service.IssueChangeMilestone(ctx, doer, issue, oldMilestoneID)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
milestone_events "code.gitea.io/gitea/services/milestone_events"
|
||||
notify_service "code.gitea.io/gitea/services/notify"
|
||||
)
|
||||
|
||||
@@ -34,6 +35,10 @@ func CloseIssue(ctx context.Context, issue *issues_model.Issue, doer *user_model
|
||||
return err
|
||||
}
|
||||
|
||||
if issue.MilestoneID > 0 {
|
||||
milestone_events.PublishMilestoneProgress(ctx, issue.MilestoneID)
|
||||
}
|
||||
|
||||
notify_service.IssueChangeStatus(ctx, doer, commitID, issue, comment, true)
|
||||
|
||||
return nil
|
||||
@@ -47,6 +52,10 @@ func ReopenIssue(ctx context.Context, issue *issues_model.Issue, doer *user_mode
|
||||
return err
|
||||
}
|
||||
|
||||
if issue.MilestoneID > 0 {
|
||||
milestone_events.PublishMilestoneProgress(ctx, issue.MilestoneID)
|
||||
}
|
||||
|
||||
notify_service.IssueChangeStatus(ctx, doer, commitID, issue, comment, false)
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user