Skip to content

[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

Merged
merged 12 commits into from
Apr 1, 2017
Merged

[Notifications Step 6] Per issue/PR watch/unwatch #1410

merged 12 commits into from
Apr 1, 2017

Conversation

andreynering
Copy link
Contributor

  • Users that don't watch the repo can choose watch a single issue
  • Users that watch the repo can choose unwatch a single issue

watch

unwatch

@andreynering andreynering added the type/feature Completely new functionality. Can only be merged if feature freeze is not active. label Mar 30, 2017
@andreynering andreynering added this to the 1.2.0 milestone Mar 30, 2017
Copy link
Contributor

@pgaskin pgaskin left a 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.

iw.UpdatedUnix = time.Now().Unix()
}

func (iw *IssueWatch) BeforeUpdate() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a documentation comment

Copy link
Contributor

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

return
}

func GetIssueWatchers(issueID int64) ([]*IssueWatch, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a documentation comment

Copy link
Contributor

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

iw.CreatedUnix = time.Now().Unix()
iw.Updated = time.Now()
iw.UpdatedUnix = time.Now().Unix()
}
Copy link
Contributor

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.

@@ -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
Copy link
Contributor

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)?

Copy link
Member

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>
Copy link
Contributor

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.

Copy link
Member

@strk strk left a 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copyright header please

// 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()
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copyright header please

@andreynering
Copy link
Contributor Author

@geek1011 and @strk

Updated with your suggestions + added unit tests.

@tboerger tboerger added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Mar 30, 2017

// 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)
Copy link
Member

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)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otherwise LGTM

iw, exists, err = getIssueWatch(x, userID, issueID)
return
}
func getIssueWatch(e Engine, userID, issueID int64) (iw *IssueWatch, exists bool, err error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need a blank line.

func GetIssueWatchers(issueID int64) ([]*IssueWatch, error) {
return getIssueWatchers(x, issueID)
}
func getIssueWatchers(e Engine, issueID int64) (watches []*IssueWatch, err error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^

Copy link
Member

@strk strk left a 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 :)

assert.NoError(t, err)
_, exists, err = GetIssueWatch(2, 2)
assert.Equal(t, true, exists)
assert.NoError(t, err)
Copy link
Member

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))
Copy link
Member

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

@lunny
Copy link
Member

lunny commented Mar 31, 2017

otherwise LGTM

@tboerger tboerger added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Mar 31, 2017
@andreynering
Copy link
Contributor Author

Updated

@strk
Copy link
Member

strk commented Apr 1, 2017 via email

@andreynering
Copy link
Contributor Author

@strk The test as is is enough to show that it works as expected.

@strk
Copy link
Member

strk commented Apr 1, 2017

@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.

@tboerger tboerger added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Apr 1, 2017
@andreynering andreynering merged commit 37a34c1 into go-gitea:master Apr 1, 2017
@andreynering andreynering deleted the notification/issue-watch branch April 1, 2017 18:12
@andreynering
Copy link
Contributor Author

@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.

@go-gitea go-gitea locked and limited conversation to collaborators Nov 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/feature Completely new functionality. Can only be merged if feature freeze is not active.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants