feat: beschrijf de API-objecten en geef ze een web_url
OpenAPI krijgt request- en response-schema's voor merge requests, issues, pipelines, jobs, branches en webhooks. MR-, issue- en pipeline-antwoorden bevatten een volledige web_url. Co-authored-by: tim <tim@timfalken.com>
@@ -490,7 +490,12 @@ func (s *Server) apiHooks(w http.ResponseWriter, r *http.Request, kind string, i
490
490
if !s.apiOK(w, r, err) {
491
491
return
492
492
}
493
writeJSON(w, http.StatusCreated, map[string]any{"id": wid})
493
hook, err := s.Store.Webhook(r.Context(), kind, id, wid)
494
if err != nil {
495
writeJSON(w, http.StatusCreated, map[string]any{"id": wid})
496
return
497
}
498
writeJSON(w, http.StatusCreated, hookJSON(hook))
494
499
}
495
500
496
501
func (s *Server) apiGroupHooks(w http.ResponseWriter, r *http.Request) {
@@ -490,7 +490,12 @@ func (s *Server) apiHooks(w http.ResponseWriter, r *http.Request, kind string, i490
if !s.apiOK(w, r, err) {490
if !s.apiOK(w, r, err) {491
return491
return492
}492
}493
writeJSON(w, http.StatusCreated, map[string]any{"id": wid})493
hook, err := s.Store.Webhook(r.Context(), kind, id, wid)494
if err != nil {495
writeJSON(w, http.StatusCreated, map[string]any{"id": wid})496
return497
}498
writeJSON(w, http.StatusCreated, hookJSON(hook))494
}499
}495
500
496
func (s *Server) apiGroupHooks(w http.ResponseWriter, r *http.Request) {501
func (s *Server) apiGroupHooks(w http.ResponseWriter, r *http.Request) {@@ -11,13 +11,21 @@ import (
11
11
"gitlab.com/Timfa/bluegit/internal/store"
12
12
)
13
13
14
func mrJSON(mr store.MergeRequest) map[string]any {
14
func (s *Server) pageURL(repo store.Repo, suffix string) string {
15
if !strings.HasPrefix(suffix, "/") {
16
suffix = "/" + suffix
17
}
18
return strings.TrimRight(s.Cfg.BaseURL, "/") + "/" + repo.FullPath() + suffix
19
}
20
21
func (s *Server) mrJSON(repo store.Repo, mr store.MergeRequest) map[string]any {
15
22
return map[string]any{
16
23
"id": mr.ID, "iid": mr.Number, "title": mr.Title, "description": mr.Description,
17
24
"source_branch": mr.SourceBranch, "target_branch": mr.TargetBranch,
18
25
"author": mr.Author, "state": mr.Status, "draft": mr.Draft, "labels": mr.Labels,
19
26
"remove_source_branch": mr.RemoveSourceBranch, "squash": mr.Squash,
20
27
"squash_commit_message": mr.SquashMessage,
28
"web_url": s.pageURL(repo, "/-/merge-requests/"+strconv.FormatInt(mr.Number, 10)),
21
29
"created_at": rfcTime(mr.CreatedAt), "updated_at": rfcTime(mr.UpdatedAt),
22
30
}
23
31
}
@@ -63,7 +71,7 @@ func (s *Server) apiMRs(w http.ResponseWriter, r *http.Request) {
63
71
if !s.apiOK(w, r, err) {
64
72
return
65
73
}
66
writeJSON(w, http.StatusCreated, mrJSON(mr))
74
writeJSON(w, http.StatusCreated, s.mrJSON(repo, mr))
67
75
return
68
76
}
69
77
list, err := s.Store.ListMergeRequests(r.Context(), repo.ID)
@@ -73,7 +81,7 @@ func (s *Server) apiMRs(w http.ResponseWriter, r *http.Request) {
73
81
page, per := pageQuery(r)
74
82
rows := make([]map[string]any, 0, len(list))
75
83
for _, mr := range list {
76
rows = append(rows, mrJSON(mr))
84
rows = append(rows, s.mrJSON(repo, mr))
77
85
}
78
86
writePage(w, r, slicePage(rows, page, per), len(rows), page, per)
79
87
}
@@ -124,7 +132,7 @@ func (s *Server) apiMR(w http.ResponseWriter, r *http.Request) {
124
132
return
125
133
}
126
134
}
127
writeJSON(w, http.StatusOK, mrJSON(mr))
135
writeJSON(w, http.StatusOK, s.mrJSON(repo, mr))
128
136
return
129
137
}
130
138
mr, err := s.Store.MergeRequestByNumber(r.Context(), repo.ID, n)
@@ -132,7 +140,7 @@ func (s *Server) apiMR(w http.ResponseWriter, r *http.Request) {
132
140
s.writeAPIErr(w, r, notFound(err))
133
141
return
134
142
}
135
writeJSON(w, http.StatusOK, mrJSON(mr))
143
writeJSON(w, http.StatusOK, s.mrJSON(repo, mr))
136
144
}
137
145
138
146
func (s *Server) apiMRNotes(w http.ResponseWriter, r *http.Request) {
@@ -281,6 +289,7 @@ func (s *Server) apiMerge(w http.ResponseWriter, r *http.Request) {
281
289
}
282
290
writeJSON(w, http.StatusOK, map[string]any{
283
291
"state": "merged", "source_branch_removed": out.Removed, "source_branch_skip": out.Skip,
292
"web_url": s.pageURL(repo, "/-/merge-requests/"+strconv.FormatInt(n, 10)),
284
293
})
285
294
}
286
295
@@ -309,13 +318,16 @@ func (s *Server) apiSetMR(w http.ResponseWriter, r *http.Request, reopen bool) {
309
318
if reopen {
310
319
state = "open"
311
320
}
312
writeJSON(w, http.StatusOK, map[string]any{"state": state})
321
writeJSON(w, http.StatusOK, map[string]any{
322
"state": state, "web_url": s.pageURL(repo, "/-/merge-requests/"+strconv.FormatInt(n, 10)),
323
})
313
324
}
314
325
315
func pipeJSON(p store.Pipeline) map[string]any {
326
func (s *Server) pipeJSON(repo store.Repo, p store.Pipeline) map[string]any {
316
327
return map[string]any{
317
328
"id": p.ID, "sha": p.CommitSHA, "ref": p.Ref, "status": p.Status, "source": p.Source,
318
329
"actor": p.Actor, "created_at": rfcTime(p.CreatedAt), "started_at": rfcTime(p.StartedAt), "finished_at": rfcTime(p.FinishedAt),
330
"web_url": s.pageURL(repo, "/-/pipelines/"+strconv.FormatInt(p.ID, 10)),
319
331
}
320
332
}
321
333
@@ -343,7 +355,13 @@ func (s *Server) apiPipelines(w http.ResponseWriter, r *http.Request) {
343
355
if !s.apiOK(w, r, err) {
344
356
return
345
357
}
346
writeJSON(w, http.StatusCreated, map[string]any{"id": id})
358
if p, err := s.Store.PipelineByID(r.Context(), repo.ID, id); err == nil {
359
writeJSON(w, http.StatusCreated, s.pipeJSON(repo, p))
360
return
361
}
362
writeJSON(w, http.StatusCreated, map[string]any{
363
"id": id, "web_url": s.pageURL(repo, "/-/pipelines/"+strconv.FormatInt(id, 10)),
364
})
347
365
return
348
366
}
349
367
list, err := s.Store.ListPipelines(r.Context(), repo.ID)
@@ -353,7 +371,7 @@ func (s *Server) apiPipelines(w http.ResponseWriter, r *http.Request) {
353
371
page, per := pageQuery(r)
354
372
rows := make([]map[string]any, 0, len(list))
355
373
for _, p := range list {
356
rows = append(rows, pipeJSON(p))
374
rows = append(rows, s.pipeJSON(repo, p))
357
375
}
358
376
writePage(w, r, slicePage(rows, page, per), len(rows), page, per)
359
377
}
@@ -373,7 +391,7 @@ func (s *Server) apiPipeline(w http.ResponseWriter, r *http.Request) {
373
391
s.writeAPIErr(w, r, notFound(err))
374
392
return
375
393
}
376
writeJSON(w, http.StatusOK, pipeJSON(p))
394
writeJSON(w, http.StatusOK, s.pipeJSON(repo, p))
377
395
}
378
396
379
397
func (s *Server) apiCancelPipeline(w http.ResponseWriter, r *http.Request) {
@@ -389,7 +407,13 @@ func (s *Server) apiCancelPipeline(w http.ResponseWriter, r *http.Request) {
389
407
if !s.apiOK(w, r, s.opCancelPipeline(r.Context(), apiUser(r), repo, id)) {
390
408
return
391
409
}
392
writeJSON(w, http.StatusOK, map[string]any{"id": id, "status": "canceled"})
410
if p, err := s.Store.PipelineByID(r.Context(), repo.ID, id); err == nil {
411
writeJSON(w, http.StatusOK, s.pipeJSON(repo, p))
412
return
413
}
414
writeJSON(w, http.StatusOK, map[string]any{
415
"id": id, "status": "canceled", "web_url": s.pageURL(repo, "/-/pipelines/"+strconv.FormatInt(id, 10)),
416
})
393
417
}
394
418
395
419
func (s *Server) apiJobs(w http.ResponseWriter, r *http.Request) {
@@ -11,13 +11,21 @@ import (11
"gitlab.com/Timfa/bluegit/internal/store"11
"gitlab.com/Timfa/bluegit/internal/store"12
)12
)13
13
14
func mrJSON(mr store.MergeRequest) map[string]any {14
func (s *Server) pageURL(repo store.Repo, suffix string) string {15
if !strings.HasPrefix(suffix, "/") {16
suffix = "/" + suffix17
}18
return strings.TrimRight(s.Cfg.BaseURL, "/") + "/" + repo.FullPath() + suffix19
}20
21
func (s *Server) mrJSON(repo store.Repo, mr store.MergeRequest) map[string]any {15
return map[string]any{22
return map[string]any{16
"id": mr.ID, "iid": mr.Number, "title": mr.Title, "description": mr.Description,23
"id": mr.ID, "iid": mr.Number, "title": mr.Title, "description": mr.Description,17
"source_branch": mr.SourceBranch, "target_branch": mr.TargetBranch,24
"source_branch": mr.SourceBranch, "target_branch": mr.TargetBranch,18
"author": mr.Author, "state": mr.Status, "draft": mr.Draft, "labels": mr.Labels,25
"author": mr.Author, "state": mr.Status, "draft": mr.Draft, "labels": mr.Labels,19
"remove_source_branch": mr.RemoveSourceBranch, "squash": mr.Squash,26
"remove_source_branch": mr.RemoveSourceBranch, "squash": mr.Squash,20
"squash_commit_message": mr.SquashMessage,27
"squash_commit_message": mr.SquashMessage,28
"web_url": s.pageURL(repo, "/-/merge-requests/"+strconv.FormatInt(mr.Number, 10)),21
"created_at": rfcTime(mr.CreatedAt), "updated_at": rfcTime(mr.UpdatedAt),29
"created_at": rfcTime(mr.CreatedAt), "updated_at": rfcTime(mr.UpdatedAt),22
}30
}23
}31
}@@ -63,7 +71,7 @@ func (s *Server) apiMRs(w http.ResponseWriter, r *http.Request) {63
if !s.apiOK(w, r, err) {71
if !s.apiOK(w, r, err) {64
return72
return65
}73
}66
writeJSON(w, http.StatusCreated, mrJSON(mr))74
writeJSON(w, http.StatusCreated, s.mrJSON(repo, mr))67
return75
return68
}76
}69
list, err := s.Store.ListMergeRequests(r.Context(), repo.ID)77
list, err := s.Store.ListMergeRequests(r.Context(), repo.ID)@@ -73,7 +81,7 @@ func (s *Server) apiMRs(w http.ResponseWriter, r *http.Request) {73
page, per := pageQuery(r)81
page, per := pageQuery(r)74
rows := make([]map[string]any, 0, len(list))82
rows := make([]map[string]any, 0, len(list))75
for _, mr := range list {83
for _, mr := range list {76
rows = append(rows, mrJSON(mr))84
rows = append(rows, s.mrJSON(repo, mr))77
}85
}78
writePage(w, r, slicePage(rows, page, per), len(rows), page, per)86
writePage(w, r, slicePage(rows, page, per), len(rows), page, per)79
}87
}@@ -124,7 +132,7 @@ func (s *Server) apiMR(w http.ResponseWriter, r *http.Request) {124
return132
return125
}133
}126
}134
}127
writeJSON(w, http.StatusOK, mrJSON(mr))135
writeJSON(w, http.StatusOK, s.mrJSON(repo, mr))128
return136
return129
}137
}130
mr, err := s.Store.MergeRequestByNumber(r.Context(), repo.ID, n)138
mr, err := s.Store.MergeRequestByNumber(r.Context(), repo.ID, n)@@ -132,7 +140,7 @@ func (s *Server) apiMR(w http.ResponseWriter, r *http.Request) {132
s.writeAPIErr(w, r, notFound(err))140
s.writeAPIErr(w, r, notFound(err))133
return141
return134
}142
}135
writeJSON(w, http.StatusOK, mrJSON(mr))143
writeJSON(w, http.StatusOK, s.mrJSON(repo, mr))136
}144
}137
145
138
func (s *Server) apiMRNotes(w http.ResponseWriter, r *http.Request) {146
func (s *Server) apiMRNotes(w http.ResponseWriter, r *http.Request) {@@ -281,6 +289,7 @@ func (s *Server) apiMerge(w http.ResponseWriter, r *http.Request) {281
}289
}282
writeJSON(w, http.StatusOK, map[string]any{290
writeJSON(w, http.StatusOK, map[string]any{283
"state": "merged", "source_branch_removed": out.Removed, "source_branch_skip": out.Skip,291
"state": "merged", "source_branch_removed": out.Removed, "source_branch_skip": out.Skip,292
"web_url": s.pageURL(repo, "/-/merge-requests/"+strconv.FormatInt(n, 10)),284
})293
})285
}294
}286
295
@@ -309,13 +318,16 @@ func (s *Server) apiSetMR(w http.ResponseWriter, r *http.Request, reopen bool) {309
if reopen {318
if reopen {310
state = "open"319
state = "open"311
}320
}312
writeJSON(w, http.StatusOK, map[string]any{"state": state})321
writeJSON(w, http.StatusOK, map[string]any{322
"state": state, "web_url": s.pageURL(repo, "/-/merge-requests/"+strconv.FormatInt(n, 10)),323
})313
}324
}314
325
315
func pipeJSON(p store.Pipeline) map[string]any {326
func (s *Server) pipeJSON(repo store.Repo, p store.Pipeline) map[string]any {316
return map[string]any{327
return map[string]any{317
"id": p.ID, "sha": p.CommitSHA, "ref": p.Ref, "status": p.Status, "source": p.Source,328
"id": p.ID, "sha": p.CommitSHA, "ref": p.Ref, "status": p.Status, "source": p.Source,318
"actor": p.Actor, "created_at": rfcTime(p.CreatedAt), "started_at": rfcTime(p.StartedAt), "finished_at": rfcTime(p.FinishedAt),329
"actor": p.Actor, "created_at": rfcTime(p.CreatedAt), "started_at": rfcTime(p.StartedAt), "finished_at": rfcTime(p.FinishedAt),330
"web_url": s.pageURL(repo, "/-/pipelines/"+strconv.FormatInt(p.ID, 10)),319
}331
}320
}332
}321
333
@@ -343,7 +355,13 @@ func (s *Server) apiPipelines(w http.ResponseWriter, r *http.Request) {343
if !s.apiOK(w, r, err) {355
if !s.apiOK(w, r, err) {344
return356
return345
}357
}346
writeJSON(w, http.StatusCreated, map[string]any{"id": id})358
if p, err := s.Store.PipelineByID(r.Context(), repo.ID, id); err == nil {359
writeJSON(w, http.StatusCreated, s.pipeJSON(repo, p))360
return361
}362
writeJSON(w, http.StatusCreated, map[string]any{363
"id": id, "web_url": s.pageURL(repo, "/-/pipelines/"+strconv.FormatInt(id, 10)),364
})347
return365
return348
}366
}349
list, err := s.Store.ListPipelines(r.Context(), repo.ID)367
list, err := s.Store.ListPipelines(r.Context(), repo.ID)@@ -353,7 +371,7 @@ func (s *Server) apiPipelines(w http.ResponseWriter, r *http.Request) {353
page, per := pageQuery(r)371
page, per := pageQuery(r)354
rows := make([]map[string]any, 0, len(list))372
rows := make([]map[string]any, 0, len(list))355
for _, p := range list {373
for _, p := range list {356
rows = append(rows, pipeJSON(p))374
rows = append(rows, s.pipeJSON(repo, p))357
}375
}358
writePage(w, r, slicePage(rows, page, per), len(rows), page, per)376
writePage(w, r, slicePage(rows, page, per), len(rows), page, per)359
}377
}@@ -373,7 +391,7 @@ func (s *Server) apiPipeline(w http.ResponseWriter, r *http.Request) {373
s.writeAPIErr(w, r, notFound(err))391
s.writeAPIErr(w, r, notFound(err))374
return392
return375
}393
}376
writeJSON(w, http.StatusOK, pipeJSON(p))394
writeJSON(w, http.StatusOK, s.pipeJSON(repo, p))377
}395
}378
396
379
func (s *Server) apiCancelPipeline(w http.ResponseWriter, r *http.Request) {397
func (s *Server) apiCancelPipeline(w http.ResponseWriter, r *http.Request) {@@ -389,7 +407,13 @@ func (s *Server) apiCancelPipeline(w http.ResponseWriter, r *http.Request) {389
if !s.apiOK(w, r, s.opCancelPipeline(r.Context(), apiUser(r), repo, id)) {407
if !s.apiOK(w, r, s.opCancelPipeline(r.Context(), apiUser(r), repo, id)) {390
return408
return391
}409
}392
writeJSON(w, http.StatusOK, map[string]any{"id": id, "status": "canceled"})410
if p, err := s.Store.PipelineByID(r.Context(), repo.ID, id); err == nil {411
writeJSON(w, http.StatusOK, s.pipeJSON(repo, p))412
return413
}414
writeJSON(w, http.StatusOK, map[string]any{415
"id": id, "status": "canceled", "web_url": s.pageURL(repo, "/-/pipelines/"+strconv.FormatInt(id, 10)),416
})393
}417
}394
418
395
func (s *Server) apiJobs(w http.ResponseWriter, r *http.Request) {419
func (s *Server) apiJobs(w http.ResponseWriter, r *http.Request) {@@ -50,7 +50,13 @@ func apiRouteTaken(method, path string) bool {
50
50
case "POST /api/v1/repos/{owner}/{repo}/releases",
51
51
"GET /api/v1/groups/{path}/secrets",
52
52
"POST /api/v1/groups/{path}/secrets",
53
"DELETE /api/v1/groups/{path}/secrets/{name}":
53
"DELETE /api/v1/groups/{path}/secrets/{name}",
54
"GET /api/v1/repos/{owner}/{repo}/issues",
55
"POST /api/v1/repos/{owner}/{repo}/issues",
56
"GET /api/v1/repos/{owner}/{repo}/issues/{number}",
57
"PUT /api/v1/repos/{owner}/{repo}/issues/{number}",
58
"DELETE /api/v1/repos/{owner}/{repo}/issues/{number}",
59
"POST /api/v1/repos/{owner}/{repo}/issues/{number}/notes":
54
60
return true
55
61
default:
56
62
return false
@@ -257,7 +263,10 @@ func openAPIDoc() map[string]any {
257
263
}
258
264
item[strings.ToLower(rt.Method)] = op
259
265
}
260
attachMergeOptionDocs(paths)
266
schemas := map[string]any{
267
"Error": map[string]any{"type": "object", "properties": map[string]any{"message": map[string]any{"type": "string"}}},
268
}
269
decorateAPI(paths, schemas)
261
270
paths["/openapi.json"] = map[string]any{
262
271
"get": map[string]any{"summary": "OpenAPI document", "responses": map[string]any{"200": map[string]any{"description": "OK"}}},
263
272
}
@@ -276,73 +285,9 @@ func openAPIDoc() map[string]any {
276
285
"privateToken": map[string]any{"type": "apiKey", "in": "header", "name": "PRIVATE-TOKEN"},
277
286
"basic": map[string]any{"type": "http", "scheme": "basic"},
278
287
},
279
"schemas": map[string]any{
280
"Error": map[string]any{"type": "object", "properties": map[string]any{"message": map[string]any{"type": "string"}}},
281
},
282
},
283
}
284
}
285
286
func attachMergeOptionDocs(paths map[string]map[string]any) {
287
opts := map[string]any{
288
"remove_source_branch": map[string]any{
289
"type": "boolean",
290
"description": "Delete the source branch after a successful merge. Omitted on create means true. Omitted on merge keeps the stored value.",
291
},
292
"squash": map[string]any{
293
"type": "boolean",
294
"description": "Combine the commits into one. Omitted on create means false. Omitted on merge keeps the stored value.",
295
},
296
"squash_commit_message": map[string]any{
297
"type": "string",
298
"description": "Message of the squash commit. An empty message uses the merge request title.",
288
"schemas": schemas,
299
289
},
300
290
}
301
body := func(extra map[string]any) map[string]any {
302
props := map[string]any{}
303
for k, v := range opts {
304
props[k] = v
305
}
306
for k, v := range extra {
307
props[k] = v
308
}
309
return map[string]any{
310
"content": map[string]any{
311
"application/json": map[string]any{"schema": map[string]any{"type": "object", "properties": props}},
312
},
313
}
314
}
315
str := func(desc string) map[string]any { return map[string]any{"type": "string", "description": desc} }
316
boolean := map[string]any{"type": "boolean"}
317
if item := paths["/projects/{owner}/{repo}/merge_requests"]; item != nil {
318
if op, ok := item["post"].(map[string]any); ok {
319
op["requestBody"] = body(map[string]any{
320
"title": str("Title"),
321
"description": str("Description"),
322
"source_branch": str("Source branch"),
323
"target_branch": str("Target branch"),
324
"draft": boolean,
325
})
326
}
327
}
328
if item := paths["/projects/{owner}/{repo}/merge_requests/{number}"]; item != nil {
329
if op, ok := item["put"].(map[string]any); ok {
330
op["requestBody"] = body(map[string]any{
331
"title": str("Title"),
332
"description": str("Description"),
333
"labels": str("Labels"),
334
})
335
}
336
}
337
if item := paths["/projects/{owner}/{repo}/merge_requests/{number}/merge"]; item != nil {
338
if op, ok := item["post"].(map[string]any); ok {
339
op["requestBody"] = body(nil)
340
responses, _ := op["responses"].(map[string]any)
341
if responses != nil {
342
responses["200"] = map[string]any{"description": "Merged. source_branch_removed says whether the source branch was deleted. source_branch_skip is empty, disabled, protected, default, forbidden, missing or error."}
343
}
344
}
345
}
346
291
}
347
292
348
293
func openAPIPath(p string) string {
@@ -50,7 +50,13 @@ func apiRouteTaken(method, path string) bool {50
case "POST /api/v1/repos/{owner}/{repo}/releases",50
case "POST /api/v1/repos/{owner}/{repo}/releases",51
"GET /api/v1/groups/{path}/secrets",51
"GET /api/v1/groups/{path}/secrets",52
"POST /api/v1/groups/{path}/secrets",52
"POST /api/v1/groups/{path}/secrets",53
"DELETE /api/v1/groups/{path}/secrets/{name}":53
"DELETE /api/v1/groups/{path}/secrets/{name}",54
"GET /api/v1/repos/{owner}/{repo}/issues",55
"POST /api/v1/repos/{owner}/{repo}/issues",56
"GET /api/v1/repos/{owner}/{repo}/issues/{number}",57
"PUT /api/v1/repos/{owner}/{repo}/issues/{number}",58
"DELETE /api/v1/repos/{owner}/{repo}/issues/{number}",59
"POST /api/v1/repos/{owner}/{repo}/issues/{number}/notes":54
return true60
return true55
default:61
default:56
return false62
return false@@ -257,7 +263,10 @@ func openAPIDoc() map[string]any {257
}263
}258
item[strings.ToLower(rt.Method)] = op264
item[strings.ToLower(rt.Method)] = op259
}265
}260
attachMergeOptionDocs(paths)266
schemas := map[string]any{267
"Error": map[string]any{"type": "object", "properties": map[string]any{"message": map[string]any{"type": "string"}}},268
}269
decorateAPI(paths, schemas)261
paths["/openapi.json"] = map[string]any{270
paths["/openapi.json"] = map[string]any{262
"get": map[string]any{"summary": "OpenAPI document", "responses": map[string]any{"200": map[string]any{"description": "OK"}}},271
"get": map[string]any{"summary": "OpenAPI document", "responses": map[string]any{"200": map[string]any{"description": "OK"}}},263
}272
}@@ -276,73 +285,9 @@ func openAPIDoc() map[string]any {276
"privateToken": map[string]any{"type": "apiKey", "in": "header", "name": "PRIVATE-TOKEN"},285
"privateToken": map[string]any{"type": "apiKey", "in": "header", "name": "PRIVATE-TOKEN"},277
"basic": map[string]any{"type": "http", "scheme": "basic"},286
"basic": map[string]any{"type": "http", "scheme": "basic"},278
},287
},279
"schemas": map[string]any{288
"schemas": schemas,280
"Error": map[string]any{"type": "object", "properties": map[string]any{"message": map[string]any{"type": "string"}}},281
},282
},283
}284
}285
286
func attachMergeOptionDocs(paths map[string]map[string]any) {287
opts := map[string]any{288
"remove_source_branch": map[string]any{289
"type": "boolean",290
"description": "Delete the source branch after a successful merge. Omitted on create means true. Omitted on merge keeps the stored value.",291
},292
"squash": map[string]any{293
"type": "boolean",294
"description": "Combine the commits into one. Omitted on create means false. Omitted on merge keeps the stored value.",295
},296
"squash_commit_message": map[string]any{297
"type": "string",298
"description": "Message of the squash commit. An empty message uses the merge request title.",299
},289
},300
}290
}301
body := func(extra map[string]any) map[string]any {302
props := map[string]any{}303
for k, v := range opts {304
props[k] = v305
}306
for k, v := range extra {307
props[k] = v308
}309
return map[string]any{310
"content": map[string]any{311
"application/json": map[string]any{"schema": map[string]any{"type": "object", "properties": props}},312
},313
}314
}315
str := func(desc string) map[string]any { return map[string]any{"type": "string", "description": desc} }316
boolean := map[string]any{"type": "boolean"}317
if item := paths["/projects/{owner}/{repo}/merge_requests"]; item != nil {318
if op, ok := item["post"].(map[string]any); ok {319
op["requestBody"] = body(map[string]any{320
"title": str("Title"),321
"description": str("Description"),322
"source_branch": str("Source branch"),323
"target_branch": str("Target branch"),324
"draft": boolean,325
})326
}327
}328
if item := paths["/projects/{owner}/{repo}/merge_requests/{number}"]; item != nil {329
if op, ok := item["put"].(map[string]any); ok {330
op["requestBody"] = body(map[string]any{331
"title": str("Title"),332
"description": str("Description"),333
"labels": str("Labels"),334
})335
}336
}337
if item := paths["/projects/{owner}/{repo}/merge_requests/{number}/merge"]; item != nil {338
if op, ok := item["post"].(map[string]any); ok {339
op["requestBody"] = body(nil)340
responses, _ := op["responses"].(map[string]any)341
if responses != nil {342
responses["200"] = map[string]any{"description": "Merged. source_branch_removed says whether the source branch was deleted. source_branch_skip is empty, disabled, protected, default, forbidden, missing or error."}343
}344
}345
}346
}291
}347
292
348
func openAPIPath(p string) string {293
func openAPIPath(p string) string {@@ -0,0 +1,312 @@
1
package server
2
3
import "strings"
4
5
// decorateAPI vult request- en response-schema's in voor de kernobjecten.
6
func decorateAPI(paths map[string]map[string]any, schemas map[string]any) {
7
for name, schema := range apiSchemas() {
8
schemas[name] = schema
9
}
10
for _, b := range apiBinds() {
11
op := apiOp(paths, b.path, b.method)
12
if op == nil {
13
continue
14
}
15
if b.body != "" {
16
op["requestBody"] = map[string]any{
17
"required": true,
18
"content": jsonSchema(schemaRef(b.body)),
19
}
20
}
21
responses, _ := op["responses"].(map[string]any)
22
if responses == nil {
23
responses = map[string]any{}
24
op["responses"] = responses
25
}
26
if b.empty {
27
responses[b.code] = map[string]any{"description": "No content"}
28
delete(responses, "200")
29
continue
30
}
31
schema := schemaRef(b.resp)
32
if b.array {
33
schema = map[string]any{"type": "array", "items": schema}
34
}
35
responses[b.code] = map[string]any{
36
"description": "OK",
37
"content": jsonSchema(schema),
38
}
39
}
40
if op := apiOp(paths, "/repos/{owner}/{repo}/issues/{number}/notes", "POST"); op != nil {
41
responses, _ := op["responses"].(map[string]any)
42
if responses == nil {
43
return
44
}
45
responses["200"] = map[string]any{
46
"description": "Issue, when the note contains only quick actions.",
47
"content": jsonSchema(schemaRef("Issue")),
48
}
49
}
50
}
51
52
func apiOp(paths map[string]map[string]any, path, method string) map[string]any {
53
item := paths[path]
54
if item == nil {
55
return nil
56
}
57
op, _ := item[strings.ToLower(method)].(map[string]any)
58
return op
59
}
60
61
func schemaRef(name string) map[string]any {
62
return map[string]any{"$ref": "#/components/schemas/" + name}
63
}
64
65
func jsonSchema(schema map[string]any) map[string]any {
66
return map[string]any{"application/json": map[string]any{"schema": schema}}
67
}
68
69
type apiBind struct {
70
path, method, body, resp, code string
71
array, empty bool
72
}
73
74
func apiBinds() []apiBind {
75
const (
76
mrs = "/projects/{owner}/{repo}/merge_requests"
77
mr = mrs + "/{number}"
78
pipes = "/projects/{owner}/{repo}/pipelines"
79
pipe = pipes + "/{id}"
80
job = pipe + "/jobs/{job}"
81
issues = "/repos/{owner}/{repo}/issues"
82
issue = issues + "/{number}"
83
branches = "/projects/{owner}/{repo}/repository/branches"
84
branch = branches + "/{branch}"
85
)
86
return []apiBind{
87
{path: mrs, method: "GET", code: "200", resp: "MergeRequest", array: true},
88
{path: mrs, method: "POST", code: "201", body: "MergeRequestCreate", resp: "MergeRequest"},
89
{path: mr, method: "GET", code: "200", resp: "MergeRequest"},
90
{path: mr, method: "PUT", code: "200", body: "MergeRequestUpdate", resp: "MergeRequest"},
91
{path: mr + "/merge", method: "POST", code: "200", body: "MergeRequestMerge", resp: "MergeResult"},
92
{path: mr + "/close", method: "POST", code: "200", resp: "MergeState"},
93
{path: mr + "/reopen", method: "POST", code: "200", resp: "MergeState"},
94
95
{path: issues, method: "GET", code: "200", resp: "IssueList"},
96
{path: issues, method: "POST", code: "201", body: "IssueWrite", resp: "Issue"},
97
{path: issue, method: "GET", code: "200", resp: "Issue"},
98
{path: issue, method: "PUT", code: "200", body: "IssueWrite", resp: "Issue"},
99
{path: issue, method: "DELETE", code: "204", empty: true},
100
{path: issue + "/notes", method: "POST", code: "201", body: "IssueNoteCreate", resp: "IssueNote"},
101
102
{path: pipes, method: "GET", code: "200", resp: "Pipeline", array: true},
103
{path: pipes, method: "POST", code: "201", body: "PipelineCreate", resp: "Pipeline"},
104
{path: pipe, method: "GET", code: "200", resp: "Pipeline"},
105
{path: pipe + "/cancel", method: "POST", code: "200", resp: "Pipeline"},
106
{path: pipe + "/jobs", method: "GET", code: "200", resp: "Job", array: true},
107
{path: job, method: "GET", code: "200", resp: "Job"},
108
{path: job + "/play", method: "POST", code: "200", resp: "Job"},
109
{path: job + "/retry", method: "POST", code: "200", resp: "Job"},
110
{path: job + "/cancel", method: "POST", code: "200", resp: "Job"},
111
112
{path: branches, method: "GET", code: "200", resp: "Branch", array: true},
113
{path: branches, method: "POST", code: "201", body: "BranchCreate", resp: "Branch"},
114
{path: branch, method: "PUT", code: "200", body: "BranchUpdate", resp: "Branch"},
115
{path: branch, method: "DELETE", code: "204", body: "BranchDelete", empty: true},
116
117
{path: "/groups/{path}/webhooks", method: "GET", code: "200", resp: "Webhook", array: true},
118
{path: "/groups/{path}/webhooks", method: "POST", code: "201", body: "WebhookCreate", resp: "Webhook"},
119
{path: "/projects/{owner}/{repo}/webhooks", method: "GET", code: "200", resp: "Webhook", array: true},
120
{path: "/projects/{owner}/{repo}/webhooks", method: "POST", code: "201", body: "WebhookCreate", resp: "Webhook"},
121
}
122
}
123
124
func apiSchemas() map[string]any {
125
when := str("RFC3339 timestamp. Null when the moment has not happened yet.")
126
return map[string]any{
127
"MergeRequest": obj("Merge request.", map[string]any{
128
"id": integer("Internal id."),
129
"iid": integer("Merge request number in the project."),
130
"title": str("Title."),
131
"description": str("Description."),
132
"source_branch": str("Source branch."),
133
"target_branch": str("Target branch."),
134
"author": str("Author username."),
135
"state": str("open, closed or merged."),
136
"draft": boolean("Draft merge request."),
137
"labels": str("Comma-separated label names."),
138
"remove_source_branch": boolean("Delete the source branch after a successful merge."),
139
"squash": boolean("Squash commits when merging."),
140
"squash_commit_message": str("Commit message used when squash is enabled. Empty uses the title."),
141
"web_url": str("Full page URL. An empty base URL yields a path."),
142
"created_at": when,
143
"updated_at": when,
144
}),
145
"MergeRequestCreate": obj("Fields for a new merge request. Omitted remove_source_branch means true. Omitted squash means false.", map[string]any{
146
"title": str("Title."),
147
"description": str("Description."),
148
"source_branch": str("Source branch."),
149
"target_branch": str("Target branch."),
150
"draft": boolean("Create as draft."),
151
"remove_source_branch": boolean("Delete the source branch after merge. Omitted means true."),
152
"squash": boolean("Squash commits. Omitted means false."),
153
"squash_commit_message": str("Squash commit message. Empty uses the merge request title."),
154
}),
155
"MergeRequestUpdate": obj("Fields to change on a merge request. Omitted merge options keep the stored value.", map[string]any{
156
"title": str("Title."),
157
"description": str("Description."),
158
"labels": str("Comma-separated label names."),
159
"remove_source_branch": boolean("Delete the source branch after merge."),
160
"squash": boolean("Squash commits."),
161
"squash_commit_message": str("Squash commit message."),
162
}),
163
"MergeRequestMerge": obj("Merge options for this attempt. Omitted fields keep the stored value.", map[string]any{
164
"remove_source_branch": boolean("Delete the source branch after merge."),
165
"squash": boolean("Squash commits."),
166
"squash_commit_message": str("Squash commit message."),
167
}),
168
"MergeResult": obj("Result of a merge.", map[string]any{
169
"state": str("merged."),
170
"source_branch_removed": boolean("True when the source branch was deleted."),
171
"source_branch_skip": str("Empty when the branch was removed. Otherwise disabled, protected, default, forbidden, missing or error."),
172
"web_url": str("Full page URL of the merge request."),
173
}),
174
"MergeState": obj("State after close or reopen.", map[string]any{
175
"state": str("open or closed."),
176
"web_url": str("Full page URL of the merge request."),
177
}),
178
"Issue": obj("Issue. The list omits notes.", map[string]any{
179
"id": integer("Issue number in the project."),
180
"title": str("Title."),
181
"description": str("Description."),
182
"status": str("open or closed."),
183
"confidential": boolean("Hidden from users who cannot triage."),
184
"author": str("Author username."),
185
"assignees": strArr("Assignee usernames."),
186
"labels": strArr("Label names."),
187
"milestone": str("Milestone title."),
188
"due_date": str("Due date, YYYY-MM-DD, or empty."),
189
"created_at": when,
190
"updated_at": when,
191
"closed_at": when,
192
"web_url": str("Full page URL. An empty base URL yields a path."),
193
"notes": map[string]any{"type": "array", "items": schemaRef("IssueNote"), "description": "Notes. Omitted on the list."},
194
}),
195
"IssueNote": obj("Issue note.", map[string]any{
196
"id": integer("Note id."),
197
"author": str("Author username."),
198
"body": str("Note text."),
199
"created_at": when,
200
}),
201
"IssueList": obj("Issue list.", map[string]any{
202
"issues": map[string]any{"type": "array", "items": schemaRef("Issue")},
203
}),
204
"IssueWrite": obj("Fields to create or update an issue. Omitted fields stay unchanged on update.", map[string]any{
205
"title": str("Title. Required when creating."),
206
"description": str("Description."),
207
"state": str("open or closed."),
208
"confidential": boolean("Confidential issue."),
209
"labels": strArr("Label names."),
210
"assignees": strArr("Assignee usernames."),
211
"milestone": str("Milestone title."),
212
"due_date": str("Due date, YYYY-MM-DD, or empty."),
213
}),
214
"IssueNoteCreate": obj("New issue note. A body that is only quick actions returns the issue instead of a note.", map[string]any{
215
"body": str("Note text, including optional quick actions."),
216
}),
217
"Pipeline": obj("Pipeline.", map[string]any{
218
"id": integer("Pipeline id."),
219
"sha": str("Commit SHA."),
220
"ref": str("Git ref, for example refs/heads/master."),
221
"status": str("Pipeline status."),
222
"source": str("Trigger source."),
223
"actor": str("Username that started the pipeline."),
224
"created_at": when,
225
"started_at": when,
226
"finished_at": when,
227
"web_url": str("Full page URL. An empty base URL yields a path."),
228
}),
229
"PipelineCreate": obj("Start a pipeline.", map[string]any{
230
"ref": str("Branch, tag or full ref to run."),
231
}),
232
"Job": obj("CI job.", map[string]any{
233
"id": integer("Job id."),
234
"name": str("Job name."),
235
"stage": str("Stage name."),
236
"status": str("Job status."),
237
"when": str("When the job runs."),
238
"allow_failure": boolean("A failed job does not fail the pipeline."),
239
"started_at": when,
240
"finished_at": when,
241
}),
242
"Branch": obj("Branch tip. Create and rename responses only include name.", map[string]any{
243
"name": str("Branch name."),
244
"commit": str("Tip commit SHA."),
245
"subject": str("Tip commit subject."),
246
"date": str("Tip commit date."),
247
"default": boolean("True for the default branch."),
248
}),
249
"BranchCreate": obj("Create a branch.", map[string]any{
250
"name": str("New branch name."),
251
"from": str("Existing branch or commit to start from."),
252
}),
253
"BranchUpdate": obj("Rename a branch.", map[string]any{
254
"name": str("New branch name."),
255
"confirm": str("Current branch name, repeated as confirmation."),
256
}),
257
"BranchDelete": obj("Delete a branch.", map[string]any{
258
"confirm": str("Branch name, repeated as confirmation."),
259
}),
260
"Webhook": obj("Webhook.", map[string]any{
261
"id": integer("Webhook id."),
262
"name": str("Display name."),
263
"preset": str("Preset name, or empty for a custom hook."),
264
"url": str("URL template."),
265
"method": str("HTTP method."),
266
"events": strArr("Events that trigger the hook."),
267
"branch_filter": str("Branch filter. Empty matches every branch."),
268
"active": boolean("Hook is enabled."),
269
}),
270
"WebhookCreate": obj("Create a webhook. Preset fields depend on the chosen preset.", map[string]any{
271
"name": str("Display name."),
272
"preset": str("Preset name."),
273
"branch_filter": str("Branch filter."),
274
"events": strArr("Events."),
275
"url": str("URL template."),
276
"username": str("Username for the preset."),
277
"avatar": str("Avatar URL."),
278
"icon": str("Icon URL or emoji."),
279
"alias": str("Alias."),
280
"token": str("Token. Stored as a secret and not returned."),
281
"chat": str("Chat id."),
282
"server": str("Server URL."),
283
"topic": str("Topic."),
284
"homeserver": str("Matrix homeserver."),
285
"room": str("Matrix room."),
286
"method": str("HTTP method."),
287
"content_type": str("Content type."),
288
"headers": str("Extra headers."),
289
"body": str("Body template."),
290
}),
291
}
292
}
293
294
func obj(desc string, props map[string]any) map[string]any {
295
return map[string]any{"type": "object", "description": desc, "properties": props}
296
}
297
298
func str(desc string) map[string]any {
299
return map[string]any{"type": "string", "description": desc}
300
}
301
302
func strArr(desc string) map[string]any {
303
return map[string]any{"type": "array", "description": desc, "items": map[string]any{"type": "string"}}
304
}
305
306
func boolean(desc string) map[string]any {
307
return map[string]any{"type": "boolean", "description": desc}
308
}
309
310
func integer(desc string) map[string]any {
311
return map[string]any{"type": "integer", "format": "int64", "description": desc}
312
}
@@ -0,0 +1,312 @@1
package server2
3
import "strings"4
5
// decorateAPI vult request- en response-schema's in voor de kernobjecten.6
func decorateAPI(paths map[string]map[string]any, schemas map[string]any) {7
for name, schema := range apiSchemas() {8
schemas[name] = schema9
}10
for _, b := range apiBinds() {11
op := apiOp(paths, b.path, b.method)12
if op == nil {13
continue14
}15
if b.body != "" {16
op["requestBody"] = map[string]any{17
"required": true,18
"content": jsonSchema(schemaRef(b.body)),19
}20
}21
responses, _ := op["responses"].(map[string]any)22
if responses == nil {23
responses = map[string]any{}24
op["responses"] = responses25
}26
if b.empty {27
responses[b.code] = map[string]any{"description": "No content"}28
delete(responses, "200")29
continue30
}31
schema := schemaRef(b.resp)32
if b.array {33
schema = map[string]any{"type": "array", "items": schema}34
}35
responses[b.code] = map[string]any{36
"description": "OK",37
"content": jsonSchema(schema),38
}39
}40
if op := apiOp(paths, "/repos/{owner}/{repo}/issues/{number}/notes", "POST"); op != nil {41
responses, _ := op["responses"].(map[string]any)42
if responses == nil {43
return44
}45
responses["200"] = map[string]any{46
"description": "Issue, when the note contains only quick actions.",47
"content": jsonSchema(schemaRef("Issue")),48
}49
}50
}51
52
func apiOp(paths map[string]map[string]any, path, method string) map[string]any {53
item := paths[path]54
if item == nil {55
return nil56
}57
op, _ := item[strings.ToLower(method)].(map[string]any)58
return op59
}60
61
func schemaRef(name string) map[string]any {62
return map[string]any{"$ref": "#/components/schemas/" + name}63
}64
65
func jsonSchema(schema map[string]any) map[string]any {66
return map[string]any{"application/json": map[string]any{"schema": schema}}67
}68
69
type apiBind struct {70
path, method, body, resp, code string71
array, empty bool72
}73
74
func apiBinds() []apiBind {75
const (76
mrs = "/projects/{owner}/{repo}/merge_requests"77
mr = mrs + "/{number}"78
pipes = "/projects/{owner}/{repo}/pipelines"79
pipe = pipes + "/{id}"80
job = pipe + "/jobs/{job}"81
issues = "/repos/{owner}/{repo}/issues"82
issue = issues + "/{number}"83
branches = "/projects/{owner}/{repo}/repository/branches"84
branch = branches + "/{branch}"85
)86
return []apiBind{87
{path: mrs, method: "GET", code: "200", resp: "MergeRequest", array: true},88
{path: mrs, method: "POST", code: "201", body: "MergeRequestCreate", resp: "MergeRequest"},89
{path: mr, method: "GET", code: "200", resp: "MergeRequest"},90
{path: mr, method: "PUT", code: "200", body: "MergeRequestUpdate", resp: "MergeRequest"},91
{path: mr + "/merge", method: "POST", code: "200", body: "MergeRequestMerge", resp: "MergeResult"},92
{path: mr + "/close", method: "POST", code: "200", resp: "MergeState"},93
{path: mr + "/reopen", method: "POST", code: "200", resp: "MergeState"},94
95
{path: issues, method: "GET", code: "200", resp: "IssueList"},96
{path: issues, method: "POST", code: "201", body: "IssueWrite", resp: "Issue"},97
{path: issue, method: "GET", code: "200", resp: "Issue"},98
{path: issue, method: "PUT", code: "200", body: "IssueWrite", resp: "Issue"},99
{path: issue, method: "DELETE", code: "204", empty: true},100
{path: issue + "/notes", method: "POST", code: "201", body: "IssueNoteCreate", resp: "IssueNote"},101
102
{path: pipes, method: "GET", code: "200", resp: "Pipeline", array: true},103
{path: pipes, method: "POST", code: "201", body: "PipelineCreate", resp: "Pipeline"},104
{path: pipe, method: "GET", code: "200", resp: "Pipeline"},105
{path: pipe + "/cancel", method: "POST", code: "200", resp: "Pipeline"},106
{path: pipe + "/jobs", method: "GET", code: "200", resp: "Job", array: true},107
{path: job, method: "GET", code: "200", resp: "Job"},108
{path: job + "/play", method: "POST", code: "200", resp: "Job"},109
{path: job + "/retry", method: "POST", code: "200", resp: "Job"},110
{path: job + "/cancel", method: "POST", code: "200", resp: "Job"},111
112
{path: branches, method: "GET", code: "200", resp: "Branch", array: true},113
{path: branches, method: "POST", code: "201", body: "BranchCreate", resp: "Branch"},114
{path: branch, method: "PUT", code: "200", body: "BranchUpdate", resp: "Branch"},115
{path: branch, method: "DELETE", code: "204", body: "BranchDelete", empty: true},116
117
{path: "/groups/{path}/webhooks", method: "GET", code: "200", resp: "Webhook", array: true},118
{path: "/groups/{path}/webhooks", method: "POST", code: "201", body: "WebhookCreate", resp: "Webhook"},119
{path: "/projects/{owner}/{repo}/webhooks", method: "GET", code: "200", resp: "Webhook", array: true},120
{path: "/projects/{owner}/{repo}/webhooks", method: "POST", code: "201", body: "WebhookCreate", resp: "Webhook"},121
}122
}123
124
func apiSchemas() map[string]any {125
when := str("RFC3339 timestamp. Null when the moment has not happened yet.")126
return map[string]any{127
"MergeRequest": obj("Merge request.", map[string]any{128
"id": integer("Internal id."),129
"iid": integer("Merge request number in the project."),130
"title": str("Title."),131
"description": str("Description."),132
"source_branch": str("Source branch."),133
"target_branch": str("Target branch."),134
"author": str("Author username."),135
"state": str("open, closed or merged."),136
"draft": boolean("Draft merge request."),137
"labels": str("Comma-separated label names."),138
"remove_source_branch": boolean("Delete the source branch after a successful merge."),139
"squash": boolean("Squash commits when merging."),140
"squash_commit_message": str("Commit message used when squash is enabled. Empty uses the title."),141
"web_url": str("Full page URL. An empty base URL yields a path."),142
"created_at": when,143
"updated_at": when,144
}),145
"MergeRequestCreate": obj("Fields for a new merge request. Omitted remove_source_branch means true. Omitted squash means false.", map[string]any{146
"title": str("Title."),147
"description": str("Description."),148
"source_branch": str("Source branch."),149
"target_branch": str("Target branch."),150
"draft": boolean("Create as draft."),151
"remove_source_branch": boolean("Delete the source branch after merge. Omitted means true."),152
"squash": boolean("Squash commits. Omitted means false."),153
"squash_commit_message": str("Squash commit message. Empty uses the merge request title."),154
}),155
"MergeRequestUpdate": obj("Fields to change on a merge request. Omitted merge options keep the stored value.", map[string]any{156
"title": str("Title."),157
"description": str("Description."),158
"labels": str("Comma-separated label names."),159
"remove_source_branch": boolean("Delete the source branch after merge."),160
"squash": boolean("Squash commits."),161
"squash_commit_message": str("Squash commit message."),162
}),163
"MergeRequestMerge": obj("Merge options for this attempt. Omitted fields keep the stored value.", map[string]any{164
"remove_source_branch": boolean("Delete the source branch after merge."),165
"squash": boolean("Squash commits."),166
"squash_commit_message": str("Squash commit message."),167
}),168
"MergeResult": obj("Result of a merge.", map[string]any{169
"state": str("merged."),170
"source_branch_removed": boolean("True when the source branch was deleted."),171
"source_branch_skip": str("Empty when the branch was removed. Otherwise disabled, protected, default, forbidden, missing or error."),172
"web_url": str("Full page URL of the merge request."),173
}),174
"MergeState": obj("State after close or reopen.", map[string]any{175
"state": str("open or closed."),176
"web_url": str("Full page URL of the merge request."),177
}),178
"Issue": obj("Issue. The list omits notes.", map[string]any{179
"id": integer("Issue number in the project."),180
"title": str("Title."),181
"description": str("Description."),182
"status": str("open or closed."),183
"confidential": boolean("Hidden from users who cannot triage."),184
"author": str("Author username."),185
"assignees": strArr("Assignee usernames."),186
"labels": strArr("Label names."),187
"milestone": str("Milestone title."),188
"due_date": str("Due date, YYYY-MM-DD, or empty."),189
"created_at": when,190
"updated_at": when,191
"closed_at": when,192
"web_url": str("Full page URL. An empty base URL yields a path."),193
"notes": map[string]any{"type": "array", "items": schemaRef("IssueNote"), "description": "Notes. Omitted on the list."},194
}),195
"IssueNote": obj("Issue note.", map[string]any{196
"id": integer("Note id."),197
"author": str("Author username."),198
"body": str("Note text."),199
"created_at": when,200
}),201
"IssueList": obj("Issue list.", map[string]any{202
"issues": map[string]any{"type": "array", "items": schemaRef("Issue")},203
}),204
"IssueWrite": obj("Fields to create or update an issue. Omitted fields stay unchanged on update.", map[string]any{205
"title": str("Title. Required when creating."),206
"description": str("Description."),207
"state": str("open or closed."),208
"confidential": boolean("Confidential issue."),209
"labels": strArr("Label names."),210
"assignees": strArr("Assignee usernames."),211
"milestone": str("Milestone title."),212
"due_date": str("Due date, YYYY-MM-DD, or empty."),213
}),214
"IssueNoteCreate": obj("New issue note. A body that is only quick actions returns the issue instead of a note.", map[string]any{215
"body": str("Note text, including optional quick actions."),216
}),217
"Pipeline": obj("Pipeline.", map[string]any{218
"id": integer("Pipeline id."),219
"sha": str("Commit SHA."),220
"ref": str("Git ref, for example refs/heads/master."),221
"status": str("Pipeline status."),222
"source": str("Trigger source."),223
"actor": str("Username that started the pipeline."),224
"created_at": when,225
"started_at": when,226
"finished_at": when,227
"web_url": str("Full page URL. An empty base URL yields a path."),228
}),229
"PipelineCreate": obj("Start a pipeline.", map[string]any{230
"ref": str("Branch, tag or full ref to run."),231
}),232
"Job": obj("CI job.", map[string]any{233
"id": integer("Job id."),234
"name": str("Job name."),235
"stage": str("Stage name."),236
"status": str("Job status."),237
"when": str("When the job runs."),238
"allow_failure": boolean("A failed job does not fail the pipeline."),239
"started_at": when,240
"finished_at": when,241
}),242
"Branch": obj("Branch tip. Create and rename responses only include name.", map[string]any{243
"name": str("Branch name."),244
"commit": str("Tip commit SHA."),245
"subject": str("Tip commit subject."),246
"date": str("Tip commit date."),247
"default": boolean("True for the default branch."),248
}),249
"BranchCreate": obj("Create a branch.", map[string]any{250
"name": str("New branch name."),251
"from": str("Existing branch or commit to start from."),252
}),253
"BranchUpdate": obj("Rename a branch.", map[string]any{254
"name": str("New branch name."),255
"confirm": str("Current branch name, repeated as confirmation."),256
}),257
"BranchDelete": obj("Delete a branch.", map[string]any{258
"confirm": str("Branch name, repeated as confirmation."),259
}),260
"Webhook": obj("Webhook.", map[string]any{261
"id": integer("Webhook id."),262
"name": str("Display name."),263
"preset": str("Preset name, or empty for a custom hook."),264
"url": str("URL template."),265
"method": str("HTTP method."),266
"events": strArr("Events that trigger the hook."),267
"branch_filter": str("Branch filter. Empty matches every branch."),268
"active": boolean("Hook is enabled."),269
}),270
"WebhookCreate": obj("Create a webhook. Preset fields depend on the chosen preset.", map[string]any{271
"name": str("Display name."),272
"preset": str("Preset name."),273
"branch_filter": str("Branch filter."),274
"events": strArr("Events."),275
"url": str("URL template."),276
"username": str("Username for the preset."),277
"avatar": str("Avatar URL."),278
"icon": str("Icon URL or emoji."),279
"alias": str("Alias."),280
"token": str("Token. Stored as a secret and not returned."),281
"chat": str("Chat id."),282
"server": str("Server URL."),283
"topic": str("Topic."),284
"homeserver": str("Matrix homeserver."),285
"room": str("Matrix room."),286
"method": str("HTTP method."),287
"content_type": str("Content type."),288
"headers": str("Extra headers."),289
"body": str("Body template."),290
}),291
}292
}293
294
func obj(desc string, props map[string]any) map[string]any {295
return map[string]any{"type": "object", "description": desc, "properties": props}296
}297
298
func str(desc string) map[string]any {299
return map[string]any{"type": "string", "description": desc}300
}301
302
func strArr(desc string) map[string]any {303
return map[string]any{"type": "array", "description": desc, "items": map[string]any{"type": "string"}}304
}305
306
func boolean(desc string) map[string]any {307
return map[string]any{"type": "boolean", "description": desc}308
}309
310
func integer(desc string) map[string]any {311
return map[string]any{"type": "integer", "format": "int64", "description": desc}312
}@@ -0,0 +1,161 @@
1
package server
2
3
import (
4
"context"
5
"path/filepath"
6
"strconv"
7
"strings"
8
"testing"
9
10
"gitlab.com/Timfa/bluegit/internal/config"
11
"gitlab.com/Timfa/bluegit/internal/store"
12
)
13
14
func TestOpenAPISchemas(t *testing.T) {
15
doc := openAPIDoc()
16
schemas := doc["components"].(map[string]any)["schemas"].(map[string]any)
17
for _, name := range []string{"Error", "MergeRequest", "Issue", "Pipeline", "Job", "Branch", "Webhook"} {
18
if _, ok := schemas[name]; !ok {
19
t.Errorf("schema %s ontbreekt", name)
20
}
21
}
22
props := schemas["MergeRequest"].(map[string]any)["properties"].(map[string]any)
23
if _, ok := props["web_url"]; !ok {
24
t.Fatal("MergeRequest mist web_url")
25
}
26
if _, ok := schemas["Issue"].(map[string]any)["properties"].(map[string]any)["web_url"]; !ok {
27
t.Fatal("Issue mist web_url")
28
}
29
if _, ok := schemas["Pipeline"].(map[string]any)["properties"].(map[string]any)["web_url"]; !ok {
30
t.Fatal("Pipeline mist web_url")
31
}
32
33
paths := doc["paths"].(map[string]any)
34
assertBody(t, paths, "/projects/{owner}/{repo}/merge_requests", "post", "MergeRequestCreate")
35
assertResp(t, paths, "/projects/{owner}/{repo}/merge_requests", "post", "201", "#/components/schemas/MergeRequest")
36
assertItems(t, paths, "/projects/{owner}/{repo}/merge_requests", "get", "200", "#/components/schemas/MergeRequest")
37
assertBody(t, paths, "/projects/{owner}/{repo}/merge_requests/{number}", "put", "MergeRequestUpdate")
38
assertBody(t, paths, "/projects/{owner}/{repo}/merge_requests/{number}/merge", "post", "MergeRequestMerge")
39
assertResp(t, paths, "/projects/{owner}/{repo}/merge_requests/{number}/merge", "post", "200", "#/components/schemas/MergeResult")
40
41
if _, ok := paths["/repos/{owner}/{repo}/issues"]; !ok {
42
t.Fatal("issues ontbreken in openapi")
43
}
44
assertBody(t, paths, "/repos/{owner}/{repo}/issues", "post", "IssueWrite")
45
assertResp(t, paths, "/repos/{owner}/{repo}/issues", "post", "201", "#/components/schemas/Issue")
46
assertResp(t, paths, "/repos/{owner}/{repo}/issues", "get", "200", "#/components/schemas/IssueList")
47
assertBody(t, paths, "/repos/{owner}/{repo}/issues/{number}", "put", "IssueWrite")
48
assertBody(t, paths, "/repos/{owner}/{repo}/issues/{number}/notes", "post", "IssueNoteCreate")
49
50
assertBody(t, paths, "/projects/{owner}/{repo}/pipelines", "post", "PipelineCreate")
51
assertResp(t, paths, "/projects/{owner}/{repo}/pipelines", "post", "201", "#/components/schemas/Pipeline")
52
assertItems(t, paths, "/projects/{owner}/{repo}/pipelines/{id}/jobs", "get", "200", "#/components/schemas/Job")
53
assertResp(t, paths, "/projects/{owner}/{repo}/pipelines/{id}/jobs/{job}", "get", "200", "#/components/schemas/Job")
54
55
assertBody(t, paths, "/projects/{owner}/{repo}/repository/branches", "post", "BranchCreate")
56
assertResp(t, paths, "/projects/{owner}/{repo}/repository/branches", "post", "201", "#/components/schemas/Branch")
57
assertBody(t, paths, "/projects/{owner}/{repo}/repository/branches/{branch}", "put", "BranchUpdate")
58
assertBody(t, paths, "/projects/{owner}/{repo}/repository/branches/{branch}", "delete", "BranchDelete")
59
60
assertBody(t, paths, "/projects/{owner}/{repo}/webhooks", "post", "WebhookCreate")
61
assertResp(t, paths, "/projects/{owner}/{repo}/webhooks", "post", "201", "#/components/schemas/Webhook")
62
assertItems(t, paths, "/groups/{path}/webhooks", "get", "200", "#/components/schemas/Webhook")
63
assertBody(t, paths, "/groups/{path}/webhooks", "post", "WebhookCreate")
64
}
65
66
func TestResourceWebURL(t *testing.T) {
67
st, err := store.Open(filepath.Join(t.TempDir(), "bluegit.db"), bytes32())
68
if err != nil {
69
t.Fatal(err)
70
}
71
t.Cleanup(func() { _ = st.Close() })
72
ctx := context.Background()
73
user, err := st.UpsertUser(ctx, 1, "timfa", "", false)
74
if err != nil {
75
t.Fatal(err)
76
}
77
repo, err := st.CreateRepo(ctx, "user", user.ID, "bluegit", "", "master", "public")
78
if err != nil {
79
t.Fatal(err)
80
}
81
mr, err := st.CreateMergeRequest(ctx, repo.ID, user.ID, "Titel", "", "topic", "master")
82
if err != nil {
83
t.Fatal(err)
84
}
85
iss, err := st.CreateIssue(ctx, repo.ID, user.ID, store.NewIssue{Title: "Bug"})
86
if err != nil {
87
t.Fatal(err)
88
}
89
pid, err := st.CreatePipeline(ctx, repo.ID, strings.Repeat("a", 40), "refs/heads/master", "push", "timfa", "titel", nil)
90
if err != nil {
91
t.Fatal(err)
92
}
93
pipe, err := st.PipelineByID(ctx, repo.ID, pid)
94
if err != nil {
95
t.Fatal(err)
96
}
97
98
srv := &Server{Cfg: config.Config{BaseURL: "https://git.timfalken.com/"}, Store: st}
99
base := "https://git.timfalken.com/timfa/bluegit"
100
if got := srv.mrJSON(repo, mr)["web_url"]; got != base+"/-/merge-requests/1" {
101
t.Fatalf("mr web_url %v", got)
102
}
103
if got := srv.issueJSON(repo, iss, nil)["web_url"]; got != base+"/-/issues/1" {
104
t.Fatalf("issue web_url %v", got)
105
}
106
wantPipe := base + "/-/pipelines/" + strconv.FormatInt(pid, 10)
107
if got := srv.pipeJSON(repo, pipe)["web_url"]; got != wantPipe {
108
t.Fatalf("pipeline web_url %v, wil %s", got, wantPipe)
109
}
110
srv.Cfg.BaseURL = ""
111
if got := srv.mrJSON(repo, mr)["web_url"]; got != "/timfa/bluegit/-/merge-requests/1" {
112
t.Fatalf("lege base mr web_url %v", got)
113
}
114
}
115
116
func assertBody(t *testing.T, paths map[string]any, path, method, schema string) {
117
t.Helper()
118
op := operation(t, paths, path, method)
119
ref := op["requestBody"].(map[string]any)["content"].(map[string]any)["application/json"].(map[string]any)["schema"].(map[string]any)["$ref"]
120
want := "#/components/schemas/" + schema
121
if ref != want {
122
t.Fatalf("%s %s body %v, wil %s", method, path, ref, want)
123
}
124
}
125
126
func assertResp(t *testing.T, paths map[string]any, path, method, code, ref string) {
127
t.Helper()
128
schema := responseSchema(t, paths, path, method, code)
129
if schema["$ref"] != ref {
130
t.Fatalf("%s %s %s schema %v, wil %s", method, path, code, schema["$ref"], ref)
131
}
132
}
133
134
func assertItems(t *testing.T, paths map[string]any, path, method, code, ref string) {
135
t.Helper()
136
schema := responseSchema(t, paths, path, method, code)
137
items, _ := schema["items"].(map[string]any)
138
if schema["type"] != "array" || items["$ref"] != ref {
139
t.Fatalf("%s %s %s is geen array van %s: %v", method, path, code, ref, schema)
140
}
141
}
142
143
func responseSchema(t *testing.T, paths map[string]any, path, method, code string) map[string]any {
144
t.Helper()
145
op := operation(t, paths, path, method)
146
resp := op["responses"].(map[string]any)[code].(map[string]any)
147
return resp["content"].(map[string]any)["application/json"].(map[string]any)["schema"].(map[string]any)
148
}
149
150
func operation(t *testing.T, paths map[string]any, path, method string) map[string]any {
151
t.Helper()
152
item, ok := paths[path].(map[string]any)
153
if !ok {
154
t.Fatalf("pad ontbreekt: %s", path)
155
}
156
op, ok := item[method].(map[string]any)
157
if !ok {
158
t.Fatalf("operatie ontbreekt: %s %s", method, path)
159
}
160
return op
161
}
@@ -0,0 +1,161 @@1
package server2
3
import (4
"context"5
"path/filepath"6
"strconv"7
"strings"8
"testing"9
10
"gitlab.com/Timfa/bluegit/internal/config"11
"gitlab.com/Timfa/bluegit/internal/store"12
)13
14
func TestOpenAPISchemas(t *testing.T) {15
doc := openAPIDoc()16
schemas := doc["components"].(map[string]any)["schemas"].(map[string]any)17
for _, name := range []string{"Error", "MergeRequest", "Issue", "Pipeline", "Job", "Branch", "Webhook"} {18
if _, ok := schemas[name]; !ok {19
t.Errorf("schema %s ontbreekt", name)20
}21
}22
props := schemas["MergeRequest"].(map[string]any)["properties"].(map[string]any)23
if _, ok := props["web_url"]; !ok {24
t.Fatal("MergeRequest mist web_url")25
}26
if _, ok := schemas["Issue"].(map[string]any)["properties"].(map[string]any)["web_url"]; !ok {27
t.Fatal("Issue mist web_url")28
}29
if _, ok := schemas["Pipeline"].(map[string]any)["properties"].(map[string]any)["web_url"]; !ok {30
t.Fatal("Pipeline mist web_url")31
}32
33
paths := doc["paths"].(map[string]any)34
assertBody(t, paths, "/projects/{owner}/{repo}/merge_requests", "post", "MergeRequestCreate")35
assertResp(t, paths, "/projects/{owner}/{repo}/merge_requests", "post", "201", "#/components/schemas/MergeRequest")36
assertItems(t, paths, "/projects/{owner}/{repo}/merge_requests", "get", "200", "#/components/schemas/MergeRequest")37
assertBody(t, paths, "/projects/{owner}/{repo}/merge_requests/{number}", "put", "MergeRequestUpdate")38
assertBody(t, paths, "/projects/{owner}/{repo}/merge_requests/{number}/merge", "post", "MergeRequestMerge")39
assertResp(t, paths, "/projects/{owner}/{repo}/merge_requests/{number}/merge", "post", "200", "#/components/schemas/MergeResult")40
41
if _, ok := paths["/repos/{owner}/{repo}/issues"]; !ok {42
t.Fatal("issues ontbreken in openapi")43
}44
assertBody(t, paths, "/repos/{owner}/{repo}/issues", "post", "IssueWrite")45
assertResp(t, paths, "/repos/{owner}/{repo}/issues", "post", "201", "#/components/schemas/Issue")46
assertResp(t, paths, "/repos/{owner}/{repo}/issues", "get", "200", "#/components/schemas/IssueList")47
assertBody(t, paths, "/repos/{owner}/{repo}/issues/{number}", "put", "IssueWrite")48
assertBody(t, paths, "/repos/{owner}/{repo}/issues/{number}/notes", "post", "IssueNoteCreate")49
50
assertBody(t, paths, "/projects/{owner}/{repo}/pipelines", "post", "PipelineCreate")51
assertResp(t, paths, "/projects/{owner}/{repo}/pipelines", "post", "201", "#/components/schemas/Pipeline")52
assertItems(t, paths, "/projects/{owner}/{repo}/pipelines/{id}/jobs", "get", "200", "#/components/schemas/Job")53
assertResp(t, paths, "/projects/{owner}/{repo}/pipelines/{id}/jobs/{job}", "get", "200", "#/components/schemas/Job")54
55
assertBody(t, paths, "/projects/{owner}/{repo}/repository/branches", "post", "BranchCreate")56
assertResp(t, paths, "/projects/{owner}/{repo}/repository/branches", "post", "201", "#/components/schemas/Branch")57
assertBody(t, paths, "/projects/{owner}/{repo}/repository/branches/{branch}", "put", "BranchUpdate")58
assertBody(t, paths, "/projects/{owner}/{repo}/repository/branches/{branch}", "delete", "BranchDelete")59
60
assertBody(t, paths, "/projects/{owner}/{repo}/webhooks", "post", "WebhookCreate")61
assertResp(t, paths, "/projects/{owner}/{repo}/webhooks", "post", "201", "#/components/schemas/Webhook")62
assertItems(t, paths, "/groups/{path}/webhooks", "get", "200", "#/components/schemas/Webhook")63
assertBody(t, paths, "/groups/{path}/webhooks", "post", "WebhookCreate")64
}65
66
func TestResourceWebURL(t *testing.T) {67
st, err := store.Open(filepath.Join(t.TempDir(), "bluegit.db"), bytes32())68
if err != nil {69
t.Fatal(err)70
}71
t.Cleanup(func() { _ = st.Close() })72
ctx := context.Background()73
user, err := st.UpsertUser(ctx, 1, "timfa", "", false)74
if err != nil {75
t.Fatal(err)76
}77
repo, err := st.CreateRepo(ctx, "user", user.ID, "bluegit", "", "master", "public")78
if err != nil {79
t.Fatal(err)80
}81
mr, err := st.CreateMergeRequest(ctx, repo.ID, user.ID, "Titel", "", "topic", "master")82
if err != nil {83
t.Fatal(err)84
}85
iss, err := st.CreateIssue(ctx, repo.ID, user.ID, store.NewIssue{Title: "Bug"})86
if err != nil {87
t.Fatal(err)88
}89
pid, err := st.CreatePipeline(ctx, repo.ID, strings.Repeat("a", 40), "refs/heads/master", "push", "timfa", "titel", nil)90
if err != nil {91
t.Fatal(err)92
}93
pipe, err := st.PipelineByID(ctx, repo.ID, pid)94
if err != nil {95
t.Fatal(err)96
}97
98
srv := &Server{Cfg: config.Config{BaseURL: "https://git.timfalken.com/"}, Store: st}99
base := "https://git.timfalken.com/timfa/bluegit"100
if got := srv.mrJSON(repo, mr)["web_url"]; got != base+"/-/merge-requests/1" {101
t.Fatalf("mr web_url %v", got)102
}103
if got := srv.issueJSON(repo, iss, nil)["web_url"]; got != base+"/-/issues/1" {104
t.Fatalf("issue web_url %v", got)105
}106
wantPipe := base + "/-/pipelines/" + strconv.FormatInt(pid, 10)107
if got := srv.pipeJSON(repo, pipe)["web_url"]; got != wantPipe {108
t.Fatalf("pipeline web_url %v, wil %s", got, wantPipe)109
}110
srv.Cfg.BaseURL = ""111
if got := srv.mrJSON(repo, mr)["web_url"]; got != "/timfa/bluegit/-/merge-requests/1" {112
t.Fatalf("lege base mr web_url %v", got)113
}114
}115
116
func assertBody(t *testing.T, paths map[string]any, path, method, schema string) {117
t.Helper()118
op := operation(t, paths, path, method)119
ref := op["requestBody"].(map[string]any)["content"].(map[string]any)["application/json"].(map[string]any)["schema"].(map[string]any)["$ref"]120
want := "#/components/schemas/" + schema121
if ref != want {122
t.Fatalf("%s %s body %v, wil %s", method, path, ref, want)123
}124
}125
126
func assertResp(t *testing.T, paths map[string]any, path, method, code, ref string) {127
t.Helper()128
schema := responseSchema(t, paths, path, method, code)129
if schema["$ref"] != ref {130
t.Fatalf("%s %s %s schema %v, wil %s", method, path, code, schema["$ref"], ref)131
}132
}133
134
func assertItems(t *testing.T, paths map[string]any, path, method, code, ref string) {135
t.Helper()136
schema := responseSchema(t, paths, path, method, code)137
items, _ := schema["items"].(map[string]any)138
if schema["type"] != "array" || items["$ref"] != ref {139
t.Fatalf("%s %s %s is geen array van %s: %v", method, path, code, ref, schema)140
}141
}142
143
func responseSchema(t *testing.T, paths map[string]any, path, method, code string) map[string]any {144
t.Helper()145
op := operation(t, paths, path, method)146
resp := op["responses"].(map[string]any)[code].(map[string]any)147
return resp["content"].(map[string]any)["application/json"].(map[string]any)["schema"].(map[string]any)148
}149
150
func operation(t *testing.T, paths map[string]any, path, method string) map[string]any {151
t.Helper()152
item, ok := paths[path].(map[string]any)153
if !ok {154
t.Fatalf("pad ontbreekt: %s", path)155
}156
op, ok := item[method].(map[string]any)157
if !ok {158
t.Fatalf("operatie ontbreekt: %s %s", method, path)159
}160
return op161
}@@ -82,6 +82,13 @@ var apiCatalog = []apiRoute{
82
82
{http.MethodGet, "/api/v1/projects/{owner}/{repo}/repository/commits/{sha}", access.ScopeRepoRead, authUser, "Get commit", (*Server).apiCommit},
83
83
{http.MethodGet, "/api/v1/projects/{owner}/{repo}/repository/commits/{sha}/diff", access.ScopeRepoRead, authUser, "Commit diff", (*Server).apiCommitDiff},
84
84
85
{http.MethodGet, "/api/v1/repos/{owner}/{repo}/issues", access.ScopeRead, authUser, "List issues", (*Server).issuesAPI},
86
{http.MethodPost, "/api/v1/repos/{owner}/{repo}/issues", access.ScopeWrite, authUser, "Create issue", (*Server).issuesAPI},
87
{http.MethodGet, "/api/v1/repos/{owner}/{repo}/issues/{number}", access.ScopeRead, authUser, "Get issue", (*Server).issueAPI},
88
{http.MethodPut, "/api/v1/repos/{owner}/{repo}/issues/{number}", access.ScopeWrite, authUser, "Update issue", (*Server).issueAPI},
89
{http.MethodDelete, "/api/v1/repos/{owner}/{repo}/issues/{number}", access.ScopeWrite, authUser, "Delete issue", (*Server).issueAPI},
90
{http.MethodPost, "/api/v1/repos/{owner}/{repo}/issues/{number}/notes", access.ScopeWrite, authUser, "Create issue note", (*Server).issueNoteAPI},
91
85
92
{http.MethodGet, "/api/v1/projects/{owner}/{repo}/merge_requests", access.ScopeRead, authUser, "List merge requests", (*Server).apiMRs},
86
93
{http.MethodPost, "/api/v1/projects/{owner}/{repo}/merge_requests", access.ScopeWrite, authUser, "Create merge request", (*Server).apiMRs},
87
94
{http.MethodGet, "/api/v1/projects/{owner}/{repo}/merge_requests/{number}", access.ScopeRead, authUser, "Get merge request", (*Server).apiMR},
@@ -82,6 +82,13 @@ var apiCatalog = []apiRoute{82
{http.MethodGet, "/api/v1/projects/{owner}/{repo}/repository/commits/{sha}", access.ScopeRepoRead, authUser, "Get commit", (*Server).apiCommit},82
{http.MethodGet, "/api/v1/projects/{owner}/{repo}/repository/commits/{sha}", access.ScopeRepoRead, authUser, "Get commit", (*Server).apiCommit},83
{http.MethodGet, "/api/v1/projects/{owner}/{repo}/repository/commits/{sha}/diff", access.ScopeRepoRead, authUser, "Commit diff", (*Server).apiCommitDiff},83
{http.MethodGet, "/api/v1/projects/{owner}/{repo}/repository/commits/{sha}/diff", access.ScopeRepoRead, authUser, "Commit diff", (*Server).apiCommitDiff},84
84
85
{http.MethodGet, "/api/v1/repos/{owner}/{repo}/issues", access.ScopeRead, authUser, "List issues", (*Server).issuesAPI},86
{http.MethodPost, "/api/v1/repos/{owner}/{repo}/issues", access.ScopeWrite, authUser, "Create issue", (*Server).issuesAPI},87
{http.MethodGet, "/api/v1/repos/{owner}/{repo}/issues/{number}", access.ScopeRead, authUser, "Get issue", (*Server).issueAPI},88
{http.MethodPut, "/api/v1/repos/{owner}/{repo}/issues/{number}", access.ScopeWrite, authUser, "Update issue", (*Server).issueAPI},89
{http.MethodDelete, "/api/v1/repos/{owner}/{repo}/issues/{number}", access.ScopeWrite, authUser, "Delete issue", (*Server).issueAPI},90
{http.MethodPost, "/api/v1/repos/{owner}/{repo}/issues/{number}/notes", access.ScopeWrite, authUser, "Create issue note", (*Server).issueNoteAPI},91
85
{http.MethodGet, "/api/v1/projects/{owner}/{repo}/merge_requests", access.ScopeRead, authUser, "List merge requests", (*Server).apiMRs},92
{http.MethodGet, "/api/v1/projects/{owner}/{repo}/merge_requests", access.ScopeRead, authUser, "List merge requests", (*Server).apiMRs},86
{http.MethodPost, "/api/v1/projects/{owner}/{repo}/merge_requests", access.ScopeWrite, authUser, "Create merge request", (*Server).apiMRs},93
{http.MethodPost, "/api/v1/projects/{owner}/{repo}/merge_requests", access.ScopeWrite, authUser, "Create merge request", (*Server).apiMRs},87
{http.MethodGet, "/api/v1/projects/{owner}/{repo}/merge_requests/{number}", access.ScopeRead, authUser, "Get merge request", (*Server).apiMR},94
{http.MethodGet, "/api/v1/projects/{owner}/{repo}/merge_requests/{number}", access.ScopeRead, authUser, "Get merge request", (*Server).apiMR},@@ -51,6 +51,10 @@ func TestAPICatalogCoversResources(t *testing.T) {
51
51
"GET /api/v1/projects/{owner}/{repo}/repository/files/{path...}\n",
52
52
"POST /api/v1/projects/{owner}/{repo}/repository/commits\n",
53
53
"GET /api/v1/projects/{owner}/{repo}/repository/commits/{sha}/diff\n",
54
"GET /api/v1/repos/{owner}/{repo}/issues\n",
55
"POST /api/v1/repos/{owner}/{repo}/issues\n",
56
"PUT /api/v1/repos/{owner}/{repo}/issues/{number}\n",
57
"POST /api/v1/repos/{owner}/{repo}/issues/{number}/notes\n",
54
58
"POST /api/v1/projects/{owner}/{repo}/merge_requests\n",
55
59
"POST /api/v1/projects/{owner}/{repo}/merge_requests/{number}/notes\n",
56
60
"POST /api/v1/projects/{owner}/{repo}/merge_requests/{number}/reviews\n",
@@ -51,6 +51,10 @@ func TestAPICatalogCoversResources(t *testing.T) {51
"GET /api/v1/projects/{owner}/{repo}/repository/files/{path...}\n",51
"GET /api/v1/projects/{owner}/{repo}/repository/files/{path...}\n",52
"POST /api/v1/projects/{owner}/{repo}/repository/commits\n",52
"POST /api/v1/projects/{owner}/{repo}/repository/commits\n",53
"GET /api/v1/projects/{owner}/{repo}/repository/commits/{sha}/diff\n",53
"GET /api/v1/projects/{owner}/{repo}/repository/commits/{sha}/diff\n",54
"GET /api/v1/repos/{owner}/{repo}/issues\n",55
"POST /api/v1/repos/{owner}/{repo}/issues\n",56
"PUT /api/v1/repos/{owner}/{repo}/issues/{number}\n",57
"POST /api/v1/repos/{owner}/{repo}/issues/{number}/notes\n",54
"POST /api/v1/projects/{owner}/{repo}/merge_requests\n",58
"POST /api/v1/projects/{owner}/{repo}/merge_requests\n",55
"POST /api/v1/projects/{owner}/{repo}/merge_requests/{number}/notes\n",59
"POST /api/v1/projects/{owner}/{repo}/merge_requests/{number}/notes\n",56
"POST /api/v1/projects/{owner}/{repo}/merge_requests/{number}/reviews\n",60
"POST /api/v1/projects/{owner}/{repo}/merge_requests/{number}/reviews\n",