code.gitea.io/gitea@v1.22.3/routers/api/v1/shared/runners.go (about) 1 // Copyright 2023 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package shared 5 6 import ( 7 "errors" 8 "net/http" 9 10 actions_model "code.gitea.io/gitea/models/actions" 11 "code.gitea.io/gitea/modules/util" 12 "code.gitea.io/gitea/services/context" 13 ) 14 15 // RegistrationToken is response related to registration token 16 // swagger:response RegistrationToken 17 type RegistrationToken struct { 18 Token string `json:"token"` 19 } 20 21 func GetRegistrationToken(ctx *context.APIContext, ownerID, repoID int64) { 22 token, err := actions_model.GetLatestRunnerToken(ctx, ownerID, repoID) 23 if errors.Is(err, util.ErrNotExist) || (token != nil && !token.IsActive) { 24 token, err = actions_model.NewRunnerToken(ctx, ownerID, repoID) 25 } 26 if err != nil { 27 ctx.InternalServerError(err) 28 return 29 } 30 31 ctx.JSON(http.StatusOK, RegistrationToken{Token: token.Token}) 32 }