loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add API route to list org secrets (#26485)

- Add a new function `CountOrgSecrets` in the file
`models/secret/secret.go`
- Add a new file `modules/structs/secret.go`
- Add a new function `ListActionsSecrets` in the file
`routers/api/v1/api.go`
- Add a new file `routers/api/v1/org/action.go`
- Add a new function `listActionsSecrets` in the file
`routers/api/v1/org/action.go`

go-sdk: https://gitea.com/gitea/go-sdk/pulls/629

---------

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: techknowlogick <matti@mdranta.net>
Co-authored-by: Giteabot <teabot@gitea.io>

authored by

Bo-Yi Wu
Lunny Xiao
techknowlogick
Giteabot
and committed by
GitHub
79d74d20 d317c983

+172
+5
models/secret/secret.go
··· 88 88 Where(opts.toConds()). 89 89 Find(&secrets) 90 90 } 91 + 92 + // CountSecrets counts the secrets 93 + func CountSecrets(ctx context.Context, opts *FindSecretsOptions) (int64, error) { 94 + return db.GetEngine(ctx).Where(opts.toConds()).Count(new(Secret)) 95 + }
+15
modules/structs/secret.go
··· 1 + // Copyright 2023 The Gitea Authors. All rights reserved. 2 + // SPDX-License-Identifier: MIT 3 + 4 + package structs 5 + 6 + import "time" 7 + 8 + // User represents a secret 9 + // swagger:model 10 + type Secret struct { 11 + // the secret's name 12 + Name string `json:"name"` 13 + // swagger:strfmt date-time 14 + Created time.Time `json:"created_at"` 15 + }
+3
routers/api/v1/api.go
··· 1298 1298 m.Combo("/{username}").Get(reqToken(), org.IsMember). 1299 1299 Delete(reqToken(), reqOrgOwnership(), org.DeleteMember) 1300 1300 }) 1301 + m.Group("/actions/secrets", func() { 1302 + m.Get("", reqToken(), reqOrgOwnership(), org.ListActionsSecrets) 1303 + }) 1301 1304 m.Group("/public_members", func() { 1302 1305 m.Get("", org.ListPublicMembers) 1303 1306 m.Combo("/{username}").Get(org.IsPublicMember).
+72
routers/api/v1/org/action.go
··· 1 + // Copyright 2023 The Gitea Authors. All rights reserved. 2 + // SPDX-License-Identifier: MIT 3 + 4 + package org 5 + 6 + import ( 7 + "net/http" 8 + 9 + "code.gitea.io/gitea/models/secret" 10 + "code.gitea.io/gitea/modules/context" 11 + api "code.gitea.io/gitea/modules/structs" 12 + "code.gitea.io/gitea/routers/api/v1/utils" 13 + ) 14 + 15 + // ListActionsSecrets list an organization's actions secrets 16 + func ListActionsSecrets(ctx *context.APIContext) { 17 + // swagger:operation GET /orgs/{org}/actions/secrets organization orgListActionsSecrets 18 + // --- 19 + // summary: List an organization's actions secrets 20 + // produces: 21 + // - application/json 22 + // parameters: 23 + // - name: org 24 + // in: path 25 + // description: name of the organization 26 + // type: string 27 + // required: true 28 + // - name: page 29 + // in: query 30 + // description: page number of results to return (1-based) 31 + // type: integer 32 + // - name: limit 33 + // in: query 34 + // description: page size of results 35 + // type: integer 36 + // responses: 37 + // "200": 38 + // "$ref": "#/responses/SecretList" 39 + 40 + listActionsSecrets(ctx) 41 + } 42 + 43 + // listActionsSecrets list an organization's actions secrets 44 + func listActionsSecrets(ctx *context.APIContext) { 45 + opts := &secret.FindSecretsOptions{ 46 + OwnerID: ctx.Org.Organization.ID, 47 + ListOptions: utils.GetListOptions(ctx), 48 + } 49 + 50 + count, err := secret.CountSecrets(ctx, opts) 51 + if err != nil { 52 + ctx.InternalServerError(err) 53 + return 54 + } 55 + 56 + secrets, err := secret.FindSecrets(ctx, *opts) 57 + if err != nil { 58 + ctx.InternalServerError(err) 59 + return 60 + } 61 + 62 + apiSecrets := make([]*api.Secret, len(secrets)) 63 + for k, v := range secrets { 64 + apiSecrets[k] = &api.Secret{ 65 + Name: v.Name, 66 + Created: v.CreatedUnix.AsTime(), 67 + } 68 + } 69 + 70 + ctx.SetTotalCountHeader(count) 71 + ctx.JSON(http.StatusOK, apiSecrets) 72 + }
+13
routers/api/v1/swagger/action.go
··· 1 + // Copyright 2023 The Gitea Authors. All rights reserved. 2 + // SPDX-License-Identifier: MIT 3 + 4 + package swagger 5 + 6 + import api "code.gitea.io/gitea/modules/structs" 7 + 8 + // SecretList 9 + // swagger:response SecretList 10 + type swaggerResponseSecretList struct { 11 + // in:body 12 + Body []api.Secret `json:"body"` 13 + }
+64
templates/swagger/v1_json.tmpl
··· 1550 1550 } 1551 1551 } 1552 1552 }, 1553 + "/orgs/{org}/actions/secrets": { 1554 + "get": { 1555 + "produces": [ 1556 + "application/json" 1557 + ], 1558 + "tags": [ 1559 + "organization" 1560 + ], 1561 + "summary": "List an organization's actions secrets", 1562 + "operationId": "orgListActionsSecrets", 1563 + "parameters": [ 1564 + { 1565 + "type": "string", 1566 + "description": "name of the organization", 1567 + "name": "org", 1568 + "in": "path", 1569 + "required": true 1570 + }, 1571 + { 1572 + "type": "integer", 1573 + "description": "page number of results to return (1-based)", 1574 + "name": "page", 1575 + "in": "query" 1576 + }, 1577 + { 1578 + "type": "integer", 1579 + "description": "page size of results", 1580 + "name": "limit", 1581 + "in": "query" 1582 + } 1583 + ], 1584 + "responses": { 1585 + "200": { 1586 + "$ref": "#/responses/SecretList" 1587 + } 1588 + } 1589 + } 1590 + }, 1553 1591 "/orgs/{org}/activities/feeds": { 1554 1592 "get": { 1555 1593 "produces": [ ··· 21291 21329 }, 21292 21330 "x-go-package": "code.gitea.io/gitea/modules/structs" 21293 21331 }, 21332 + "Secret": { 21333 + "description": "User represents a secret", 21334 + "type": "object", 21335 + "properties": { 21336 + "created_at": { 21337 + "type": "string", 21338 + "format": "date-time", 21339 + "x-go-name": "Created" 21340 + }, 21341 + "name": { 21342 + "description": "the secret's name", 21343 + "type": "string", 21344 + "x-go-name": "Name" 21345 + } 21346 + }, 21347 + "x-go-package": "code.gitea.io/gitea/modules/structs" 21348 + }, 21294 21349 "ServerVersion": { 21295 21350 "description": "ServerVersion wraps the version of the server", 21296 21351 "type": "object", ··· 22860 22915 "description": "SearchResults", 22861 22916 "schema": { 22862 22917 "$ref": "#/definitions/SearchResults" 22918 + } 22919 + }, 22920 + "SecretList": { 22921 + "description": "SecretList", 22922 + "schema": { 22923 + "type": "array", 22924 + "items": { 22925 + "$ref": "#/definitions/Secret" 22926 + } 22863 22927 } 22864 22928 }, 22865 22929 "ServerVersion": {