From 88beb1cef8f259adadc03cb21bc27af58ece4550 Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Sat, 14 Jul 2018 18:01:40 +0100 Subject: [PATCH] stop timer on closing issues/PRs too --- routers/repo/issue.go | 6 ++++++ routers/repo/pull.go | 19 ++++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 18ab1691c..12d83af86 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -1035,6 +1035,12 @@ func NewComment(ctx *context.Context, form auth.CreateCommentForm) { if err := issue.ChangeStatus(ctx.User, ctx.Repo.Repository, form.Status == "close"); err != nil { log.Error(4, "ChangeStatus: %v", err) } else { + + if err := stopTimerIfAvailable(ctx.User, issue); err != nil { + ctx.ServerError("CreateOrStopIssueStopwatch", err) + return + } + log.Trace("Issue [%d] status changed to closed: %v", issue.ID, issue.IsClosed) notification.Service.NotifyIssue(issue, ctx.User.ID) diff --git a/routers/repo/pull.go b/routers/repo/pull.go index d836b4371..9fe1331f5 100644 --- a/routers/repo/pull.go +++ b/routers/repo/pull.go @@ -534,11 +534,9 @@ func MergePullRequest(ctx *context.Context, form auth.MergePullRequestForm) { return } - if models.StopwatchExists(ctx.User.ID, issue.ID) { - if err := models.CreateOrStopIssueStopwatch(ctx.User, issue); err != nil { - ctx.ServerError("CreateOrStopIssueStopwatch", err) - return - } + if err := stopTimerIfAvailable(ctx.User, issue); err != nil { + ctx.ServerError("CreateOrStopIssueStopwatch", err) + return } notification.Service.NotifyIssue(pr.Issue, ctx.User.ID) @@ -547,6 +545,17 @@ func MergePullRequest(ctx *context.Context, form auth.MergePullRequestForm) { ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index)) } +func stopTimerIfAvailable(user *models.User, issue *models.Issue) error { + + if models.StopwatchExists(user.ID, issue.ID) { + if err := models.CreateOrStopIssueStopwatch(user, issue); err != nil { + return err + } + } + + return nil +} + // ParseCompareInfo parse compare info between two commit for preparing pull request func ParseCompareInfo(ctx *context.Context) (*models.User, *models.Repository, *git.Repository, *git.PullRequestInfo, string, string) { baseRepo := ctx.Repo.Repository