aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLanre Adelowo <adelowomailbox@gmail.com>2019-02-05 12:38:11 +0100
committerLauris BH <lauris@nix.lv>2019-02-05 13:38:11 +0200
commit539079122418c485347506110bef232c99a75d37 (patch)
treea00aa1ae7a7bb0e82dcae461b7c53c3921731cb2
parent5bd594c85883d713f9d94f6e93cd8f08b253b369 (diff)
downloadgitea-539079122418c485347506110bef232c99a75d37.tar.gz
gitea-539079122418c485347506110bef232c99a75d37.zip
Automatically clear stopwatch on merging a PR (#4327)
* Don't display buttons if there are no notices * clear stopwatch on merging a PR * remove redundant gt check * use ctx.Flash as per @bkcsoft comment * stop timer on closing issues/PRs too * updated translation as per review * redirect to login page after successfully activating account * remove unrelated changes * stop timer for issues that are closed via commits too..Not just the 'close' UI button
-rw-r--r--models/action.go16
-rw-r--r--options/locale/locale_en-US.ini1
-rw-r--r--routers/repo/issue.go6
-rw-r--r--routers/repo/issue_stopwatch.go11
-rw-r--r--routers/repo/pull.go16
-rw-r--r--templates/repo/issue/view_content/comments.tmpl1
6 files changed, 49 insertions, 2 deletions
diff --git a/models/action.go b/models/action.go
index 5dc0eb18e6..c886408b2f 100644
--- a/models/action.go
+++ b/models/action.go
@@ -491,15 +491,27 @@ func changeIssueStatus(repo *Repository, doer *User, ref string, refMarked map[i
return nil
}
+ stopTimerIfAvailable := func(doer *User, issue *Issue) error {
+
+ if StopwatchExists(doer.ID, issue.ID) {
+ if err := CreateOrStopIssueStopwatch(doer, issue); err != nil {
+ return err
+ }
+ }
+
+ return nil
+ }
+
issue.Repo = repo
if err = issue.ChangeStatus(doer, status); err != nil {
// Don't return an error when dependencies are open as this would let the push fail
if IsErrDependenciesLeft(err) {
- return nil
+ return stopTimerIfAvailable(doer, issue)
}
return err
}
- return nil
+
+ return stopTimerIfAvailable(doer, issue)
}
// UpdateIssuesCommit checks if issues are manipulated by commit message.
diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini
index 2d32fac9c7..502b980c43 100644
--- a/options/locale/locale_en-US.ini
+++ b/options/locale/locale_en-US.ini
@@ -781,6 +781,7 @@ issues.tracker = Time Tracker
issues.start_tracking_short = Start
issues.start_tracking = Start Time Tracking
issues.start_tracking_history = `started working %s`
+issues.tracker_auto_close = Timer will be stopped automatically when this issue gets closed
issues.tracking_already_started = `You have already started time tracking on this <a href="%s">issue</a>!`
issues.stop_tracking = Stop
issues.stop_tracking_history = `stopped working %s`
diff --git a/routers/repo/issue.go b/routers/repo/issue.go
index bcc648900a..9767d11136 100644
--- a/routers/repo/issue.go
+++ b/routers/repo/issue.go
@@ -1181,6 +1181,12 @@ func NewComment(ctx *context.Context, form auth.CreateCommentForm) {
return
}
} 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.NotifyIssueChangeStatus(ctx.User, issue, isClosed)
diff --git a/routers/repo/issue_stopwatch.go b/routers/repo/issue_stopwatch.go
index a7d6ed39cc..28105dfe03 100644
--- a/routers/repo/issue_stopwatch.go
+++ b/routers/repo/issue_stopwatch.go
@@ -17,6 +17,13 @@ func IssueStopwatch(c *context.Context) {
if c.Written() {
return
}
+
+ var showSuccessMessage bool
+
+ if !models.StopwatchExists(c.User.ID, issue.ID) {
+ showSuccessMessage = true
+ }
+
if !c.Repo.CanUseTimetracker(issue, c.User) {
c.NotFound("CanUseTimetracker", nil)
return
@@ -27,6 +34,10 @@ func IssueStopwatch(c *context.Context) {
return
}
+ if showSuccessMessage {
+ c.Flash.Success(c.Tr("repo.issues.tracker_auto_close"))
+ }
+
url := issue.HTMLURL()
c.Redirect(url, http.StatusSeeOther)
}
diff --git a/routers/repo/pull.go b/routers/repo/pull.go
index 0f1136abe7..c060aeb4b5 100644
--- a/routers/repo/pull.go
+++ b/routers/repo/pull.go
@@ -590,12 +590,28 @@ func MergePullRequest(ctx *context.Context, form auth.MergePullRequestForm) {
return
}
+ if err := stopTimerIfAvailable(ctx.User, issue); err != nil {
+ ctx.ServerError("CreateOrStopIssueStopwatch", err)
+ return
+ }
+
notification.NotifyMergePullRequest(pr, ctx.User, ctx.Repo.GitRepo)
log.Trace("Pull request merged: %d", pr.ID)
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
diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl
index 673fe6db08..6fe09221c3 100644
--- a/templates/repo/issue/view_content/comments.tmpl
+++ b/templates/repo/issue/view_content/comments.tmpl
@@ -1,3 +1,4 @@
+{{ template "base/alert" }}
{{range .Issue.Comments}}
{{ $createdStr:= TimeSinceUnix .CreatedUnix $.Lang }}