Browse Source

Fix comment API paths (#2813)

Ethan Koenig 1 year ago
parent
commit
c3b6383b3a
4 changed files with 278 additions and 94 deletions
  1. 4 4
      integrations/api_comment_test.go
  2. 186 85
      public/swagger.v1.json
  3. 4 3
      routers/api/v1/api.go
  4. 84 2
      routers/api/v1/repo/issue_comment.go

+ 4 - 4
integrations/api_comment_test.go

@@ -93,8 +93,8 @@ func TestAPIEditComment(t *testing.T) {
93 93
 	repoOwner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
94 94
 
95 95
 	session := loginUser(t, repoOwner.Name)
96
-	urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/comments/%d",
97
-		repoOwner.Name, repo.Name, issue.Index, comment.ID)
96
+	urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/comments/%d",
97
+		repoOwner.Name, repo.Name, comment.ID)
98 98
 	req := NewRequestWithValues(t, "PATCH", urlStr, map[string]string{
99 99
 		"body": newCommentBody,
100 100
 	})
@@ -117,8 +117,8 @@ func TestAPIDeleteComment(t *testing.T) {
117 117
 	repoOwner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
118 118
 
119 119
 	session := loginUser(t, repoOwner.Name)
120
-	req := NewRequestf(t, "DELETE", "/api/v1/repos/%s/%s/issues/%d/comments/%d",
121
-		repoOwner.Name, repo.Name, issue.Index, comment.ID)
120
+	req := NewRequestf(t, "DELETE", "/api/v1/repos/%s/%s/issues/comments/%d",
121
+		repoOwner.Name, repo.Name, comment.ID)
122 122
 	session.MakeRequest(t, req, http.StatusNoContent)
123 123
 
124 124
 	models.AssertNotExistsBean(t, &models.Comment{ID: comment.ID})

+ 186 - 85
public/swagger.v1.json

@@ -1225,91 +1225,6 @@
1225 1225
         }
1226 1226
       }
1227 1227
     },
1228
-    "/repos/{owner}/{repo}/comments/{id}": {
1229
-      "delete": {
1230
-        "tags": [
1231
-          "issue"
1232
-        ],
1233
-        "summary": "Delete a comment",
1234
-        "operationId": "issueDeleteComment",
1235
-        "parameters": [
1236
-          {
1237
-            "type": "string",
1238
-            "description": "owner of the repo",
1239
-            "name": "owner",
1240
-            "in": "path",
1241
-            "required": true
1242
-          },
1243
-          {
1244
-            "type": "string",
1245
-            "description": "name of the repo",
1246
-            "name": "repo",
1247
-            "in": "path",
1248
-            "required": true
1249
-          },
1250
-          {
1251
-            "type": "integer",
1252
-            "description": "id of comment to delete",
1253
-            "name": "id",
1254
-            "in": "path",
1255
-            "required": true
1256
-          }
1257
-        ],
1258
-        "responses": {
1259
-          "204": {
1260
-            "$ref": "#/responses/empty"
1261
-          }
1262
-        }
1263
-      },
1264
-      "patch": {
1265
-        "consumes": [
1266
-          "application/json"
1267
-        ],
1268
-        "produces": [
1269
-          "application/json"
1270
-        ],
1271
-        "tags": [
1272
-          "issue"
1273
-        ],
1274
-        "summary": "Edit a comment",
1275
-        "operationId": "issueEditComment",
1276
-        "parameters": [
1277
-          {
1278
-            "type": "string",
1279
-            "description": "owner of the repo",
1280
-            "name": "owner",
1281
-            "in": "path",
1282
-            "required": true
1283
-          },
1284
-          {
1285
-            "type": "string",
1286
-            "description": "name of the repo",
1287
-            "name": "repo",
1288
-            "in": "path",
1289
-            "required": true
1290
-          },
1291
-          {
1292
-            "type": "integer",
1293
-            "description": "id of the comment to edit",
1294
-            "name": "id",
1295
-            "in": "path",
1296
-            "required": true
1297
-          },
1298
-          {
1299
-            "name": "body",
1300
-            "in": "body",
1301
-            "schema": {
1302
-              "$ref": "#/definitions/EditIssueCommentOption"
1303
-            }
1304
-          }
1305
-        ],
1306
-        "responses": {
1307
-          "200": {
1308
-            "$ref": "#/responses/Comment"
1309
-          }
1310
-        }
1311
-      }
1312
-    },
1313 1228
     "/repos/{owner}/{repo}/commits/{ref}/statuses": {
1314 1229
       "get": {
1315 1230
         "produces": [
@@ -1965,6 +1880,91 @@
1965 1880
         }
1966 1881
       }
1967 1882
     },
1883
+    "/repos/{owner}/{repo}/issues/comments/{id}": {
1884
+      "delete": {
1885
+        "tags": [
1886
+          "issue"
1887
+        ],
1888
+        "summary": "Delete a comment",
1889
+        "operationId": "issueDeleteComment",
1890
+        "parameters": [
1891
+          {
1892
+            "type": "string",
1893
+            "description": "owner of the repo",
1894
+            "name": "owner",
1895
+            "in": "path",
1896
+            "required": true
1897
+          },
1898
+          {
1899
+            "type": "string",
1900
+            "description": "name of the repo",
1901
+            "name": "repo",
1902
+            "in": "path",
1903
+            "required": true
1904
+          },
1905
+          {
1906
+            "type": "integer",
1907
+            "description": "id of comment to delete",
1908
+            "name": "id",
1909
+            "in": "path",
1910
+            "required": true
1911
+          }
1912
+        ],
1913
+        "responses": {
1914
+          "204": {
1915
+            "$ref": "#/responses/empty"
1916
+          }
1917
+        }
1918
+      },
1919
+      "patch": {
1920
+        "consumes": [
1921
+          "application/json"
1922
+        ],
1923
+        "produces": [
1924
+          "application/json"
1925
+        ],
1926
+        "tags": [
1927
+          "issue"
1928
+        ],
1929
+        "summary": "Edit a comment",
1930
+        "operationId": "issueEditComment",
1931
+        "parameters": [
1932
+          {
1933
+            "type": "string",
1934
+            "description": "owner of the repo",
1935
+            "name": "owner",
1936
+            "in": "path",
1937
+            "required": true
1938
+          },
1939
+          {
1940
+            "type": "string",
1941
+            "description": "name of the repo",
1942
+            "name": "repo",
1943
+            "in": "path",
1944
+            "required": true
1945
+          },
1946
+          {
1947
+            "type": "integer",
1948
+            "description": "id of the comment to edit",
1949
+            "name": "id",
1950
+            "in": "path",
1951
+            "required": true
1952
+          },
1953
+          {
1954
+            "name": "body",
1955
+            "in": "body",
1956
+            "schema": {
1957
+              "$ref": "#/definitions/EditIssueCommentOption"
1958
+            }
1959
+          }
1960
+        ],
1961
+        "responses": {
1962
+          "200": {
1963
+            "$ref": "#/responses/Comment"
1964
+          }
1965
+        }
1966
+      }
1967
+    },
1968 1968
     "/repos/{owner}/{repo}/issues/{id}": {
1969 1969
       "get": {
1970 1970
         "produces": [
@@ -2103,6 +2103,107 @@
2103 2103
         }
2104 2104
       }
2105 2105
     },
2106
+    "/repos/{owner}/{repo}/issues/{index}/comments/{id}": {
2107
+      "delete": {
2108
+        "tags": [
2109
+          "issue"
2110
+        ],
2111
+        "summary": "Delete a comment",
2112
+        "operationId": "issueDeleteCommentDeprecated",
2113
+        "deprecated": true,
2114
+        "parameters": [
2115
+          {
2116
+            "type": "string",
2117
+            "description": "owner of the repo",
2118
+            "name": "owner",
2119
+            "in": "path",
2120
+            "required": true
2121
+          },
2122
+          {
2123
+            "type": "string",
2124
+            "description": "name of the repo",
2125
+            "name": "repo",
2126
+            "in": "path",
2127
+            "required": true
2128
+          },
2129
+          {
2130
+            "type": "integer",
2131
+            "description": "this parameter is ignored",
2132
+            "name": "index",
2133
+            "in": "path",
2134
+            "required": true
2135
+          },
2136
+          {
2137
+            "type": "integer",
2138
+            "description": "id of comment to delete",
2139
+            "name": "id",
2140
+            "in": "path",
2141
+            "required": true
2142
+          }
2143
+        ],
2144
+        "responses": {
2145
+          "204": {
2146
+            "$ref": "#/responses/empty"
2147
+          }
2148
+        }
2149
+      },
2150
+      "patch": {
2151
+        "consumes": [
2152
+          "application/json"
2153
+        ],
2154
+        "produces": [
2155
+          "application/json"
2156
+        ],
2157
+        "tags": [
2158
+          "issue"
2159
+        ],
2160
+        "summary": "Edit a comment",
2161
+        "operationId": "issueEditCommentDeprecated",
2162
+        "deprecated": true,
2163
+        "parameters": [
2164
+          {
2165
+            "type": "string",
2166
+            "description": "owner of the repo",
2167
+            "name": "owner",
2168
+            "in": "path",
2169
+            "required": true
2170
+          },
2171
+          {
2172
+            "type": "string",
2173
+            "description": "name of the repo",
2174
+            "name": "repo",
2175
+            "in": "path",
2176
+            "required": true
2177
+          },
2178
+          {
2179
+            "type": "integer",
2180
+            "description": "this parameter is ignored",
2181
+            "name": "index",
2182
+            "in": "path",
2183
+            "required": true
2184
+          },
2185
+          {
2186
+            "type": "integer",
2187
+            "description": "id of the comment to edit",
2188
+            "name": "id",
2189
+            "in": "path",
2190
+            "required": true
2191
+          },
2192
+          {
2193
+            "name": "body",
2194
+            "in": "body",
2195
+            "schema": {
2196
+              "$ref": "#/definitions/EditIssueCommentOption"
2197
+            }
2198
+          }
2199
+        ],
2200
+        "responses": {
2201
+          "200": {
2202
+            "$ref": "#/responses/Comment"
2203
+          }
2204
+        }
2205
+      }
2206
+    },
2106 2207
     "/repos/{owner}/{repo}/issues/{index}/labels": {
2107 2208
       "get": {
2108 2209
         "produces": [

+ 4 - 3
routers/api/v1/api.go

@@ -406,7 +406,8 @@ func RegisterRoutes(m *macaron.Macaron) {
406 406
 					m.Group("/comments", func() {
407 407
 						m.Get("", repo.ListRepoIssueComments)
408 408
 						m.Combo("/:id", reqToken()).
409
-							Patch(bind(api.EditIssueCommentOption{}), repo.EditIssueComment)
409
+							Patch(bind(api.EditIssueCommentOption{}), repo.EditIssueComment).
410
+							Delete(repo.DeleteIssueComment)
410 411
 					})
411 412
 					m.Group("/:index", func() {
412 413
 						m.Combo("").Get(repo.GetIssue).
@@ -415,8 +416,8 @@ func RegisterRoutes(m *macaron.Macaron) {
415 416
 						m.Group("/comments", func() {
416 417
 							m.Combo("").Get(repo.ListIssueComments).
417 418
 								Post(reqToken(), bind(api.CreateIssueCommentOption{}), repo.CreateIssueComment)
418
-							m.Combo("/:id", reqToken()).Patch(bind(api.EditIssueCommentOption{}), repo.EditIssueComment).
419
-								Delete(repo.DeleteIssueComment)
419
+							m.Combo("/:id", reqToken()).Patch(bind(api.EditIssueCommentOption{}), repo.EditIssueCommentDeprecated).
420
+								Delete(repo.DeleteIssueCommentDeprecated)
420 421
 						})
421 422
 
422 423
 						m.Group("/labels", func() {

+ 84 - 2
routers/api/v1/repo/issue_comment.go

@@ -168,7 +168,7 @@ func CreateIssueComment(ctx *context.APIContext, form api.CreateIssueCommentOpti
168 168
 
169 169
 // EditIssueComment modify a comment of an issue
170 170
 func EditIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption) {
171
-	// swagger:operation PATCH /repos/{owner}/{repo}/comments/{id} issue issueEditComment
171
+	// swagger:operation PATCH /repos/{owner}/{repo}/issues/comments/{id} issue issueEditComment
172 172
 	// ---
173 173
 	// summary: Edit a comment
174 174
 	// consumes:
@@ -198,6 +198,51 @@ func EditIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption)
198 198
 	// responses:
199 199
 	//   "200":
200 200
 	//     "$ref": "#/responses/Comment"
201
+	editIssueComment(ctx, form)
202
+}
203
+
204
+// EditIssueCommentDeprecated modify a comment of an issue
205
+func EditIssueCommentDeprecated(ctx *context.APIContext, form api.EditIssueCommentOption) {
206
+	// swagger:operation PATCH /repos/{owner}/{repo}/issues/{index}/comments/{id} issue issueEditCommentDeprecated
207
+	// ---
208
+	// summary: Edit a comment
209
+	// deprecated: true
210
+	// consumes:
211
+	// - application/json
212
+	// produces:
213
+	// - application/json
214
+	// parameters:
215
+	// - name: owner
216
+	//   in: path
217
+	//   description: owner of the repo
218
+	//   type: string
219
+	//   required: true
220
+	// - name: repo
221
+	//   in: path
222
+	//   description: name of the repo
223
+	//   type: string
224
+	//   required: true
225
+	// - name: index
226
+	//   in: path
227
+	//   description: this parameter is ignored
228
+	//   type: integer
229
+	//   required: true
230
+	// - name: id
231
+	//   in: path
232
+	//   description: id of the comment to edit
233
+	//   type: integer
234
+	//   required: true
235
+	// - name: body
236
+	//   in: body
237
+	//   schema:
238
+	//     "$ref": "#/definitions/EditIssueCommentOption"
239
+	// responses:
240
+	//   "200":
241
+	//     "$ref": "#/responses/Comment"
242
+	editIssueComment(ctx, form)
243
+}
244
+
245
+func editIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption) {
201 246
 	comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
202 247
 	if err != nil {
203 248
 		if models.IsErrCommentNotExist(err) {
@@ -226,9 +271,37 @@ func EditIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption)
226 271
 
227 272
 // DeleteIssueComment delete a comment from an issue
228 273
 func DeleteIssueComment(ctx *context.APIContext) {
229
-	// swagger:operation DELETE /repos/{owner}/{repo}/comments/{id} issue issueDeleteComment
274
+	// swagger:operation DELETE /repos/{owner}/{repo}/issues/comments/{id} issue issueDeleteComment
275
+	// ---
276
+	// summary: Delete a comment
277
+	// parameters:
278
+	// - name: owner
279
+	//   in: path
280
+	//   description: owner of the repo
281
+	//   type: string
282
+	//   required: true
283
+	// - name: repo
284
+	//   in: path
285
+	//   description: name of the repo
286
+	//   type: string
287
+	//   required: true
288
+	// - name: id
289
+	//   in: path
290
+	//   description: id of comment to delete
291
+	//   type: integer
292
+	//   required: true
293
+	// responses:
294
+	//   "204":
295
+	//     "$ref": "#/responses/empty"
296
+	deleteIssueComment(ctx)
297
+}
298
+
299
+// DeleteIssueCommentDeprecated delete a comment from an issue
300
+func DeleteIssueCommentDeprecated(ctx *context.APIContext) {
301
+	// swagger:operation DELETE /repos/{owner}/{repo}/issues/{index}/comments/{id} issue issueDeleteCommentDeprecated
230 302
 	// ---
231 303
 	// summary: Delete a comment
304
+	// deprecated: true
232 305
 	// parameters:
233 306
 	// - name: owner
234 307
 	//   in: path
@@ -240,6 +313,11 @@ func DeleteIssueComment(ctx *context.APIContext) {
240 313
 	//   description: name of the repo
241 314
 	//   type: string
242 315
 	//   required: true
316
+	// - name: index
317
+	//   in: path
318
+	//   description: this parameter is ignored
319
+	//   type: integer
320
+	//   required: true
243 321
 	// - name: id
244 322
 	//   in: path
245 323
 	//   description: id of comment to delete
@@ -248,6 +326,10 @@ func DeleteIssueComment(ctx *context.APIContext) {
248 326
 	// responses:
249 327
 	//   "204":
250 328
 	//     "$ref": "#/responses/empty"
329
+	deleteIssueComment(ctx)
330
+}
331
+
332
+func deleteIssueComment(ctx *context.APIContext) {
251 333
 	comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
252 334
 	if err != nil {
253 335
 		if models.IsErrCommentNotExist(err) {