-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Add issue subscription check to API #10967
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
zeripath
merged 32 commits into
go-gitea:master
from
6543-forks:api-IssueSubscription-check_10962
Apr 21, 2020
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
7ca8cbb
move Check-Logic where it belongs
6543 c7ad54c
imprufe code [noise]
6543 ff590a6
add CheckIssueSubscription
6543 7939985
fix nill exeption
6543 83aedc2
fix
6543 e418b89
add TEST for Issue-Subscribe; Issue-Unsubscribe; CheckIssueSubscribtion
6543 7c4f75d
privacy extention
6543 02f3de5
Merge branch 'master' into api-IssueSubscription-check_10962
6543 7cf5ebf
Merge branch 'master' into api-IssueSubscription-check_10962
6543 322344e
Merge branch 'master' into api-IssueSubscription-check_10962
6543 c3d34db
Merge branch 'master' into api-IssueSubscription-check_10962
6543 e36866c
Merge branch 'master' into api-IssueSubscription-check_10962
6543 f366191
Merge branch 'master' into api-IssueSubscription-check_10962
6543 01a2cf9
Merge branch 'master' into api-IssueSubscription-check_10962
6543 0144089
Merge branch 'master' into api-IssueSubscription-check_10962
6543 ac19d91
Merge branch 'master' into api-IssueSubscription-check_10962
6543 919152b
Merge branch 'master' into api-IssueSubscription-check_10962
6543 308d8b8
Merge branch 'master' into api-IssueSubscription-check_10962
6543 92c61ec
Merge branch 'master' into api-IssueSubscription-check_10962
6543 aec512f
Merge branch 'master' into api-IssueSubscription-check_10962
6543 dc70f73
Merge branch 'master' into api-IssueSubscription-check_10962
6543 0867fbd
Merge branch 'master' into api-IssueSubscription-check_10962
6543 843f52c
Merge branch 'master' into api-IssueSubscription-check_10962
6543 5c24f78
Merge branch 'master' into api-IssueSubscription-check_10962
6543 d4f5df8
Merge branch 'master' into api-IssueSubscription-check_10962
6543 aab1f55
Merge branch 'master' into api-IssueSubscription-check_10962
6543 c5e53e5
CI.restart()
6543 6b44a24
Merge branch 'master' into api-IssueSubscription-check_10962
6543 059ae71
Merge branch 'master' into api-IssueSubscription-check_10962
6543 e540228
Merge branch 'master' into api-IssueSubscription-check_10962
zeripath 858ce8e
Merge branch 'master' into api-IssueSubscription-check_10962
6543 d7d62ac
Merge branch 'master' into api-IssueSubscription-check_10962
6543 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright 2020 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package integrations | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"testing" | ||
|
||
"code.gitea.io/gitea/models" | ||
api "code.gitea.io/gitea/modules/structs" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestAPIIssueSubscriptions(t *testing.T) { | ||
defer prepareTestEnv(t)() | ||
|
||
issue1 := models.AssertExistsAndLoadBean(t, &models.Issue{ID: 1}).(*models.Issue) | ||
issue2 := models.AssertExistsAndLoadBean(t, &models.Issue{ID: 2}).(*models.Issue) | ||
issue3 := models.AssertExistsAndLoadBean(t, &models.Issue{ID: 3}).(*models.Issue) | ||
issue4 := models.AssertExistsAndLoadBean(t, &models.Issue{ID: 4}).(*models.Issue) | ||
issue5 := models.AssertExistsAndLoadBean(t, &models.Issue{ID: 8}).(*models.Issue) | ||
|
||
owner := models.AssertExistsAndLoadBean(t, &models.User{ID: issue1.PosterID}).(*models.User) | ||
|
||
session := loginUser(t, owner.Name) | ||
token := getTokenForLoggedInUser(t, session) | ||
|
||
testSubscription := func(issue *models.Issue, isWatching bool) { | ||
|
||
issueRepo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: issue.RepoID}).(*models.Repository) | ||
|
||
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/subscriptions/check?token=%s", issueRepo.OwnerName, issueRepo.Name, issue.Index, token) | ||
req := NewRequest(t, "GET", urlStr) | ||
resp := session.MakeRequest(t, req, http.StatusOK) | ||
wi := new(api.WatchInfo) | ||
DecodeJSON(t, resp, wi) | ||
|
||
assert.EqualValues(t, isWatching, wi.Subscribed) | ||
assert.EqualValues(t, !isWatching, wi.Ignored) | ||
assert.EqualValues(t, issue.APIURL()+"/subscriptions", wi.URL) | ||
assert.EqualValues(t, issue.CreatedUnix, wi.CreatedAt.Unix()) | ||
assert.EqualValues(t, issueRepo.APIURL(), wi.RepositoryURL) | ||
} | ||
|
||
testSubscription(issue1, true) | ||
testSubscription(issue2, true) | ||
testSubscription(issue3, true) | ||
testSubscription(issue4, false) | ||
testSubscription(issue5, false) | ||
|
||
issue1Repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: issue1.RepoID}).(*models.Repository) | ||
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/subscriptions/%s?token=%s", issue1Repo.OwnerName, issue1Repo.Name, issue1.Index, owner.Name, token) | ||
req := NewRequest(t, "DELETE", urlStr) | ||
session.MakeRequest(t, req, http.StatusCreated) | ||
testSubscription(issue1, false) | ||
|
||
issue5Repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: issue5.RepoID}).(*models.Repository) | ||
urlStr = fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/subscriptions/%s?token=%s", issue5Repo.OwnerName, issue5Repo.Name, issue5.Index, owner.Name, token) | ||
req = NewRequest(t, "PUT", urlStr) | ||
session.MakeRequest(t, req, http.StatusCreated) | ||
testSubscription(issue5, true) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.