-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
[Notifications Step 6] Per issue/PR watch/unwatch #1410
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
[Notifications Step 6] Per issue/PR watch/unwatch #1410
Conversation
andreynering
commented
Mar 30, 2017
- Users that don't watch the repo can choose watch a single issue
- Users that watch the repo can choose unwatch a single issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good other than some minor fixes, still need to try testing it.
models/issue_watch.go
Outdated
iw.UpdatedUnix = time.Now().Unix() | ||
} | ||
|
||
func (iw *IssueWatch) BeforeUpdate() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a documentation comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind, you just fixed it
models/issue_watch.go
Outdated
return | ||
} | ||
|
||
func GetIssueWatchers(issueID int64) ([]*IssueWatch, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a documentation comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind, you just fixed it
models/issue_watch.go
Outdated
iw.CreatedUnix = time.Now().Unix() | ||
iw.Updated = time.Now() | ||
iw.UpdatedUnix = time.Now().Unix() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, this should store the time in a variable and use that, to improve the accuracy of the times, and to optimize the code a bit.
options/locale/locale_en-US.ini
Outdated
@@ -652,6 +652,9 @@ issues.label.filter_sort.reverse_alphabetically = Reverse alphabetically | |||
issues.num_participants = %d Participants | |||
issues.attachment.open_tab = `Click to see "%s" in a new tab` | |||
issues.attachment.download = `Click to download "%s"` | |||
issues.watch = Watch | |||
issues.watch_issue = Watch issue | |||
issues.unwatch_issue = Unwatch issue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe subscribe and unsubscribe like github (because it is slightly shorter and more clear)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
subscribe/unsubscribe also matches the icon better (which should otherwise be an eye)
<i class="octicon octicon-mute"></i> | ||
{{.i18n.Tr "repo.issues.unwatch_issue"}} | ||
{{else}} | ||
<i class="octicon octicon-megaphone"></i> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use octicon-unmute
for consistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's great to see this coming. I guess it needs a migration, and would be great to see a unit test for it.
@@ -0,0 +1,83 @@ | |||
package models |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copyright header please
models/issue_watch.go
Outdated
// BeforeUpdate is invoked from XORM before updating an object of this type. | ||
func (iw *IssueWatch) BeforeUpdate() { | ||
iw.Updated = time.Now() | ||
iw.UpdatedUnix = time.Now().Unix() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, call time.Now() a single time please
@@ -0,0 +1,34 @@ | |||
package repo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copyright header please
models/issue_watch.go
Outdated
|
||
// GetIssueWatch returns an issue watch by user and issue | ||
func GetIssueWatch(userID, issueID int64) (iw *IssueWatch, exists bool, err error) { | ||
iw, exists, err = getIssueWatch(x, userID, issueID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return getIssueWatch(x, userID, issueID)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
otherwise LGTM
models/issue_watch.go
Outdated
iw, exists, err = getIssueWatch(x, userID, issueID) | ||
return | ||
} | ||
func getIssueWatch(e Engine, userID, issueID int64) (iw *IssueWatch, exists bool, err error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need a blank line.
models/issue_watch.go
Outdated
func GetIssueWatchers(issueID int64) ([]*IssueWatch, error) { | ||
return getIssueWatchers(x, issueID) | ||
} | ||
func getIssueWatchers(e Engine, issueID int64) (watches []*IssueWatch, err error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great progress, I hope you can fill the final gaps :)
models/issue_watch_test.go
Outdated
assert.NoError(t, err) | ||
_, exists, err = GetIssueWatch(2, 2) | ||
assert.Equal(t, true, exists) | ||
assert.NoError(t, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also check a user having no entry in issue_watch table here ?
Also, ideally both a user who's watching and one who's not watching the repository containing the issue.
|
||
iws, err := GetIssueWatchers(1) | ||
assert.NoError(t, err) | ||
assert.Equal(t, 1, len(iws)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also check an issue with multiple watchers and check the actual content of the returned slice
otherwise LGTM |
Updated |
I would still like to see a test with multiple watchers
and something showing how repository watchers affect (or not)
the issue-watch-list retriving function
|
@strk The test as is is enough to show that it works as expected. |
@andreynering is it not expected that the GetIssueWatchers function return the information about who are the watchers ? The test is not checking that. Why don't you want to check that ? Also, is it expected that an issue can have more than a single watcher ? I find those to be legit cases to test. I've no problem with this being merged as is (LGTM) but as you are on it it would be nice to get a better test coverage. |
@strk Testing the data would makes sense for data we are saving in the database. But in this case, we would be testing data present on test fixtures. This don't makes sense, we know the data on fixtures is right. |