Some checks failed
cache-seeder / prune (push) Has been skipped
cache-seeder / frontend (push) Failing after 3s
cache-seeder / python (push) Failing after 3s
cache-seeder / gobuild (push) Failing after 4s
cache-seeder / lint (bindata, lint-backend) (push) Failing after 3s
giteabot backport / giteabot (push) Has been skipped
giteabot / giteabot (push) Has been skipped
cache-prune / prune (push) Has been skipped
release-nightly-snapcraft / build-and-publish (ubuntu-24.04) (push) Has been cancelled
release-nightly-snapcraft / build-and-publish (ubuntu-24.04-arm) (push) Has been cancelled
release-nightly / nightly-binary (push) Has been cancelled
release-nightly / nightly-container (push) Has been cancelled
cron-renovate / cron-renovate (push) Has been skipped
60 lines
1.7 KiB
Go
60 lines
1.7 KiB
Go
// Copyright 2019 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package issue
|
|
|
|
import (
|
|
"context"
|
|
|
|
"gitea.dev/models/db"
|
|
issues_model "gitea.dev/models/issues"
|
|
user_model "gitea.dev/models/user"
|
|
"gitea.dev/modules/log"
|
|
notify_service "gitea.dev/services/notify"
|
|
)
|
|
|
|
// CloseIssue close an issue.
|
|
func CloseIssue(ctx context.Context, issue *issues_model.Issue, doer *user_model.User, commitID string) error {
|
|
var comment *issues_model.Comment
|
|
var stopwatchFinished bool
|
|
if err := db.WithTx(ctx, func(ctx context.Context) error {
|
|
var err error
|
|
comment, err = issues_model.CloseIssue(ctx, issue, doer)
|
|
if err != nil {
|
|
if issues_model.IsErrDependenciesLeft(err) {
|
|
if _, err := issues_model.FinishIssueStopwatch(ctx, doer, issue); err != nil {
|
|
log.Error("Unable to stop stopwatch for issue[%d]#%d: %v", issue.ID, issue.Index, err)
|
|
}
|
|
}
|
|
return err
|
|
}
|
|
|
|
stopwatchFinished, err = issues_model.FinishIssueStopwatch(ctx, doer, issue)
|
|
return err
|
|
}); err != nil {
|
|
return err
|
|
}
|
|
|
|
// after the tx: publishing inside it would announce a change a rollback undoes
|
|
if stopwatchFinished {
|
|
notify_service.StopwatchChanged(ctx, doer)
|
|
}
|
|
|
|
notify_service.IssueChangeStatus(ctx, doer, commitID, issue, comment, true)
|
|
|
|
return nil
|
|
}
|
|
|
|
// ReopenIssue reopen an issue.
|
|
// FIXME: If some issues dependent this one are closed, should we also reopen them?
|
|
func ReopenIssue(ctx context.Context, issue *issues_model.Issue, doer *user_model.User, commitID string) error {
|
|
comment, err := issues_model.ReopenIssue(ctx, issue, doer)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
notify_service.IssueChangeStatus(ctx, doer, commitID, issue, comment, false)
|
|
|
|
return nil
|
|
}
|