Skip to content

Commit e9e8638

Browse files
authored
Return issue subscription status from API subscribe (#10966)
* [API] issue subscription indicate by http status * CI.restart()
1 parent 4974b7c commit e9e8638

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

integrations/api_issue_subscription_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,17 @@ func TestAPIIssueSubscriptions(t *testing.T) {
5858
session.MakeRequest(t, req, http.StatusCreated)
5959
testSubscription(issue1, false)
6060

61+
req = NewRequest(t, "DELETE", urlStr)
62+
session.MakeRequest(t, req, http.StatusOK)
63+
testSubscription(issue1, false)
64+
6165
issue5Repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: issue5.RepoID}).(*models.Repository)
6266
urlStr = fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/subscriptions/%s?token=%s", issue5Repo.OwnerName, issue5Repo.Name, issue5.Index, owner.Name, token)
6367
req = NewRequest(t, "PUT", urlStr)
6468
session.MakeRequest(t, req, http.StatusCreated)
6569
testSubscription(issue5, true)
70+
71+
req = NewRequest(t, "PUT", urlStr)
72+
session.MakeRequest(t, req, http.StatusOK)
73+
testSubscription(issue5, true)
6674
}

routers/api/v1/repo/issue_subscription.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ func AddIssueSubscription(ctx *context.APIContext) {
4545
// type: string
4646
// required: true
4747
// responses:
48+
// "200":
49+
// description: Already subscribed
4850
// "201":
49-
// "$ref": "#/responses/empty"
51+
// description: Successfully Subscribed
5052
// "304":
5153
// description: User can only subscribe itself if he is no admin
5254
// "404":
@@ -87,8 +89,10 @@ func DelIssueSubscription(ctx *context.APIContext) {
8789
// type: string
8890
// required: true
8991
// responses:
92+
// "200":
93+
// description: Already unsubscribed
9094
// "201":
91-
// "$ref": "#/responses/empty"
95+
// description: Successfully Unsubscribed
9296
// "304":
9397
// description: User can only subscribe itself if he is no admin
9498
// "404":
@@ -126,6 +130,19 @@ func setIssueSubscription(ctx *context.APIContext, watch bool) {
126130
return
127131
}
128132

133+
current, err := models.CheckIssueWatch(user, issue)
134+
if err != nil {
135+
ctx.Error(http.StatusInternalServerError, "CheckIssueWatch", err)
136+
return
137+
}
138+
139+
// If watch state wont change
140+
if current == watch {
141+
ctx.Status(http.StatusOK)
142+
return
143+
}
144+
145+
// Update watch state
129146
if err := models.CreateOrUpdateIssueWatch(user.ID, issue.ID, watch); err != nil {
130147
ctx.Error(http.StatusInternalServerError, "CreateOrUpdateIssueWatch", err)
131148
return

templates/swagger/v1_json.tmpl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5315,8 +5315,11 @@
53155315
}
53165316
],
53175317
"responses": {
5318+
"200": {
5319+
"description": "Already subscribed"
5320+
},
53185321
"201": {
5319-
"$ref": "#/responses/empty"
5322+
"description": "Successfully Subscribed"
53205323
},
53215324
"304": {
53225325
"description": "User can only subscribe itself if he is no admin"
@@ -5370,8 +5373,11 @@
53705373
}
53715374
],
53725375
"responses": {
5376+
"200": {
5377+
"description": "Already unsubscribed"
5378+
},
53735379
"201": {
5374-
"$ref": "#/responses/empty"
5380+
"description": "Successfully Unsubscribed"
53755381
},
53765382
"304": {
53775383
"description": "User can only subscribe itself if he is no admin"

0 commit comments

Comments
 (0)