Some checks failed
Build and Release / Create Release (push) Successful in 0s
Trigger Vault Plugin Rebuild / Trigger Vault Rebuild (push) Successful in 0s
Build and Release / Integration Tests (PostgreSQL) (push) Successful in 2m48s
Build and Release / Lint (push) Failing after 5m2s
Build and Release / Build Binaries (amd64, windows, windows-latest) (push) Has been skipped
Build and Release / Build Binaries (amd64, darwin, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (amd64, linux, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (arm64, darwin, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (arm64, linux, linux-latest) (push) Has been skipped
Build and Release / Unit Tests (push) Successful in 5m37s
Go's semantic import versioning requires v2+ modules to include the major version in the module path. This enables using proper version tags (v3.x.x) instead of pseudo-versions. Updated module path: code.gitcaddy.com/server/v3
81 lines
2.1 KiB
Go
81 lines
2.1 KiB
Go
// Copyright 2019 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package issue
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"code.gitcaddy.com/server/v3/models/db"
|
|
issues_model "code.gitcaddy.com/server/v3/models/issues"
|
|
user_model "code.gitcaddy.com/server/v3/models/user"
|
|
notify_service "code.gitcaddy.com/server/v3/services/notify"
|
|
)
|
|
|
|
func changeMilestoneAssign(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldMilestoneID int64) error {
|
|
// Only check if milestone exists if we don't remove it.
|
|
if issue.MilestoneID > 0 {
|
|
has, err := issues_model.HasMilestoneByRepoID(ctx, issue.RepoID, issue.MilestoneID)
|
|
if err != nil {
|
|
return fmt.Errorf("HasMilestoneByRepoID: %w", err)
|
|
}
|
|
if !has {
|
|
return errors.New("HasMilestoneByRepoID: issue doesn't exist")
|
|
}
|
|
}
|
|
|
|
if err := issues_model.UpdateIssueCols(ctx, issue, "milestone_id"); err != nil {
|
|
return err
|
|
}
|
|
|
|
if oldMilestoneID > 0 {
|
|
if err := issues_model.UpdateMilestoneCounters(ctx, oldMilestoneID); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
if issue.MilestoneID > 0 {
|
|
if err := issues_model.UpdateMilestoneCounters(ctx, issue.MilestoneID); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
if oldMilestoneID > 0 || issue.MilestoneID > 0 {
|
|
if err := issue.LoadRepo(ctx); err != nil {
|
|
return err
|
|
}
|
|
|
|
opts := &issues_model.CreateCommentOptions{
|
|
Type: issues_model.CommentTypeMilestone,
|
|
Doer: doer,
|
|
Repo: issue.Repo,
|
|
Issue: issue,
|
|
OldMilestoneID: oldMilestoneID,
|
|
MilestoneID: issue.MilestoneID,
|
|
}
|
|
if _, err := issues_model.CreateComment(ctx, opts); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
if issue.MilestoneID == 0 {
|
|
issue.Milestone = nil
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// ChangeMilestoneAssign changes assignment of milestone for issue.
|
|
func ChangeMilestoneAssign(ctx context.Context, issue *issues_model.Issue, doer *user_model.User, oldMilestoneID int64) (err error) {
|
|
if err := db.WithTx(ctx, func(dbCtx context.Context) error {
|
|
return changeMilestoneAssign(dbCtx, doer, issue, oldMilestoneID)
|
|
}); err != nil {
|
|
return err
|
|
}
|
|
|
|
notify_service.IssueChangeMilestone(ctx, doer, issue, oldMilestoneID)
|
|
return nil
|
|
}
|