Skip to content

Automatically clear stopwatch on merging a PR #4327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 41 commits into from
Feb 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
d8f2043
Don't display buttons if there are no notices
adelowo Jun 19, 2018
fd55ef4
clear stopwatch on merging a PR
adelowo Jun 27, 2018
d5752d4
remove redundant gt check
adelowo Jul 5, 2018
93b187a
Merge remote-tracking branch 'origin'
adelowo Jul 5, 2018
3fa1e4f
Merge branch 'master' into stop_watch_on_merging_pr
adelowo Jul 6, 2018
852514f
Merge remote-tracking branch 'origin' into stop_watch_on_merging_pr
adelowo Jul 6, 2018
dff2c69
Merge branch 'master' of https://github.com/go-gitea/gitea into stop_…
adelowo Jul 10, 2018
bb7b73e
use ctx.Flash as per @bkcsoft comment
adelowo Jul 14, 2018
58edfc9
Merge branch 'master' of https://github.com/go-gitea/gitea into stop_…
adelowo Jul 14, 2018
88beb1c
stop timer on closing issues/PRs too
adelowo Jul 14, 2018
96f677a
updated translation as per review
adelowo Jul 14, 2018
0bef325
redirect to login page after successfully activating account
adelowo Jul 15, 2018
8105df9
Merge branch 'master' of https://github.com/go-gitea/gitea into stop_…
adelowo Jul 17, 2018
0d4b0cc
Merge branch 'master' of https://github.com/go-gitea/gitea into stop_…
adelowo Jul 20, 2018
6e7c222
Merge branch 'master' of https://github.com/go-gitea/gitea into stop_…
adelowo Jul 21, 2018
af2b1c3
Merge branch 'master' of https://github.com/go-gitea/gitea
adelowo Jul 22, 2018
0f9cd8a
Merge branch 'master' into stop_watch_on_merging_pr
adelowo Jul 22, 2018
4f6ae0f
remove unrelated changes
adelowo Jul 22, 2018
3413c0c
Merge branch 'master' into stop_watch_on_merging_pr
adelowo Aug 6, 2018
ba1860b
Merge branch 'master' into stop_watch_on_merging_pr
adelowo Aug 10, 2018
d4be24b
Merge branch 'master' into stop_watch_on_merging_pr
adelowo Aug 14, 2018
db016c5
Merge branch 'master' into stop_watch_on_merging_pr
adelowo Aug 16, 2018
0565c8c
Merge branch 'master' into stop_watch_on_merging_pr
adelowo Aug 21, 2018
25c09b7
Merge branch 'master' into stop_watch_on_merging_pr
adelowo Aug 23, 2018
42922bf
Merge branch 'master' into stop_watch_on_merging_pr
adelowo Aug 24, 2018
7f880fd
Merge branch 'master' into stop_watch_on_merging_pr
adelowo Aug 30, 2018
cc7c5ce
Merge branch 'master' into stop_watch_on_merging_pr
adelowo Sep 4, 2018
0245bd4
Merge branch 'master' into stop_watch_on_merging_pr
adelowo Sep 10, 2018
93f7bb2
Merge branch 'master' into stop_watch_on_merging_pr
adelowo Sep 18, 2018
95c1e4b
Merge branch 'master' into stop_watch_on_merging_pr
adelowo Oct 6, 2018
096e1b1
Merge branch 'master' into stop_watch_on_merging_pr
adelowo Oct 9, 2018
0601a80
Merge branch 'master' into stop_watch_on_merging_pr
adelowo Oct 20, 2018
6e05433
Merge branch 'master' into stop_watch_on_merging_pr
adelowo Oct 29, 2018
75b716c
Merge branch 'master' into stop_watch_on_merging_pr
adelowo Nov 27, 2018
feb1b6c
Merge branch 'master' into stop_watch_on_merging_pr
adelowo Jan 19, 2019
0abc2a7
Merge branch 'master' into stop_watch_on_merging_pr
techknowlogick Jan 23, 2019
d365c68
Merge branch 'master' into stop_watch_on_merging_pr
adelowo Jan 31, 2019
0f4dcb2
Merge branch 'master' into stop_watch_on_merging_pr
adelowo Feb 1, 2019
1a722ef
Merge branch 'master' into stop_watch_on_merging_pr
adelowo Feb 3, 2019
e1ae7d2
Merge remote-tracking branch 'origin/master' into stop_watch_on_mergi…
adelowo Feb 5, 2019
0ccd672
stop timer for issues that are closed via commits too..Not just the '…
adelowo Feb 5, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions models/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
6 changes: 6 additions & 0 deletions routers/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions routers/repo/issue_stopwatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
Expand Down
16 changes: 16 additions & 0 deletions routers/repo/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions templates/repo/issue/view_content/comments.tmpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{ template "base/alert" }}
{{range .Issue.Comments}}
{{ $createdStr:= TimeSinceUnix .CreatedUnix $.Lang }}

Expand Down