Skip to content
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

Return issue subscription status from API subscribe #10966

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions integrations/api_issue_subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,17 @@ func TestAPIIssueSubscriptions(t *testing.T) {
session.MakeRequest(t, req, http.StatusCreated)
testSubscription(issue1, false)

req = NewRequest(t, "DELETE", urlStr)
session.MakeRequest(t, req, http.StatusOK)
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)

req = NewRequest(t, "PUT", urlStr)
session.MakeRequest(t, req, http.StatusOK)
testSubscription(issue5, true)
}
21 changes: 19 additions & 2 deletions routers/api/v1/repo/issue_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ func AddIssueSubscription(ctx *context.APIContext) {
// type: string
// required: true
// responses:
// "200":
// description: Already subscribed
// "201":
// "$ref": "#/responses/empty"
// description: Successfully Subscribed
// "304":
// description: User can only subscribe itself if he is no admin
// "404":
Expand Down Expand Up @@ -87,8 +89,10 @@ func DelIssueSubscription(ctx *context.APIContext) {
// type: string
// required: true
// responses:
// "200":
// description: Already unsubscribed
// "201":
// "$ref": "#/responses/empty"
// description: Successfully Unsubscribed
// "304":
// description: User can only subscribe itself if he is no admin
// "404":
Expand Down Expand Up @@ -126,6 +130,19 @@ func setIssueSubscription(ctx *context.APIContext, watch bool) {
return
}

current, err := models.CheckIssueWatch(user, issue)
if err != nil {
ctx.Error(http.StatusInternalServerError, "CheckIssueWatch", err)
return
}

// If watch state wont change
if current == watch {
ctx.Status(http.StatusOK)
return
}

// Update watch state
if err := models.CreateOrUpdateIssueWatch(user.ID, issue.ID, watch); err != nil {
ctx.Error(http.StatusInternalServerError, "CreateOrUpdateIssueWatch", err)
return
Expand Down
10 changes: 8 additions & 2 deletions templates/swagger/v1_json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5315,8 +5315,11 @@
}
],
"responses": {
"200": {
"description": "Already subscribed"
},
"201": {
"$ref": "#/responses/empty"
"description": "Successfully Subscribed"
},
"304": {
"description": "User can only subscribe itself if he is no admin"
Expand Down Expand Up @@ -5370,8 +5373,11 @@
}
],
"responses": {
"200": {
"description": "Already unsubscribed"
},
"201": {
"$ref": "#/responses/empty"
"description": "Successfully Unsubscribed"
},
"304": {
"description": "User can only subscribe itself if he is no admin"
Expand Down