@@ -7,9 +7,14 @@ import (
77 "errors"
88 "net/http"
99
10+ runnerv1 "code.gitea.io/actions-proto-go/runner/v1"
1011 actions_model "code.gitea.io/gitea/models/actions"
12+ "code.gitea.io/gitea/models/db"
13+ api "code.gitea.io/gitea/modules/structs"
1114 "code.gitea.io/gitea/modules/util"
15+ "code.gitea.io/gitea/routers/api/v1/utils"
1216 "code.gitea.io/gitea/services/context"
17+ "code.gitea.io/gitea/services/convert"
1318)
1419
1520// RegistrationToken is response related to registration token
@@ -30,3 +35,67 @@ func GetRegistrationToken(ctx *context.APIContext, ownerID, repoID int64) {
3035
3136 ctx .JSON (http .StatusOK , RegistrationToken {Token : token .Token })
3237}
38+
39+ func GetRunners (ctx * context.APIContext , ownerID , repoID int64 ) {
40+ runners , total , err := db .FindAndCount [actions_model.ActionRunner ](ctx , & actions_model.FindRunnerOptions {
41+ OwnerID : ownerID ,
42+ RepoID : repoID ,
43+ ListOptions : utils .GetListOptions (ctx ),
44+ })
45+ if err != nil {
46+ ctx .APIErrorInternal (err )
47+ return
48+ }
49+
50+ res := new (api.ActionRunnersResponse )
51+ res .TotalCount = total
52+
53+ res .Entries = make ([]* api.ActionRunner , len (runners ))
54+ for i , runner := range runners {
55+ res .Entries [i ] = convert .ToActionRunner (ctx , runner )
56+ }
57+
58+ ctx .JSON (http .StatusOK , & res )
59+ }
60+
61+ func GetRunner (ctx * context.APIContext , ownerID , repoID , runnerID int64 ) {
62+ runner , exists , err := db .GetByID [actions_model.ActionRunner ](ctx , runnerID )
63+ if err != nil {
64+ ctx .APIErrorInternal (err )
65+ return
66+ }
67+ if ! exists {
68+ ctx .APIErrorNotFound ("Runner does not exist" )
69+ return
70+ }
71+ if ! runner .Editable (ownerID , repoID ) {
72+ ctx .APIErrorNotFound ("No permission to get this runner" )
73+ return
74+ }
75+ ctx .JSON (http .StatusOK , convert .ToActionRunner (ctx , runner ))
76+ }
77+
78+ func DeleteRunner (ctx * context.APIContext , ownerID , repoID , runnerID int64 ) {
79+ runner , exists , err := db .GetByID [actions_model.ActionRunner ](ctx , runnerID )
80+ if err != nil {
81+ ctx .APIErrorInternal (err )
82+ return
83+ }
84+ if ! exists {
85+ ctx .APIErrorNotFound ("Runner does not exist" )
86+ return
87+ }
88+ if ! runner .Editable (ownerID , repoID ) {
89+ ctx .APIErrorNotFound ("No permission to delete this runner" )
90+ return
91+ }
92+ if runner .Status () == runnerv1 .RunnerStatus_RUNNER_STATUS_ACTIVE {
93+ ctx .APIError (http .StatusConflict , "Runner is active" )
94+ return
95+ }
96+ err = actions_model .DeleteRunner (ctx , runner .ID )
97+ if err != nil {
98+ ctx .APIErrorInternal (err )
99+ }
100+ ctx .Status (http .StatusNoContent )
101+ }
0 commit comments