mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Actions Runner rest api (#33873)
Implements runner apis based on https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#list-self-hosted-runners-for-an-organization - Add Post endpoints for registration-token, google/go-github revealed this as problem - We should deprecate Get Endpoints, leaving them for compatibility - Get endpoint of admin has api path /admin/runners/registration-token that feels wrong, /admin/actions/runners/registration-token seems more consistent with user/org/repo api - Get Runner Api - List Runner Api - Delete Runner Api - Tests admin / user / org / repo level endpoints Related to #33750 (implements point 1 and 2) Via needs discovered in #32461, this runner api is needed to allow cleanup of runners that are deallocated without user interaction. --------- Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -30,6 +30,8 @@ import (
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
asymkey_service "code.gitea.io/gitea/services/asymkey"
|
||||
"code.gitea.io/gitea/services/gitdiff"
|
||||
|
||||
runnerv1 "code.gitea.io/actions-proto-go/runner/v1"
|
||||
)
|
||||
|
||||
// ToEmail convert models.EmailAddress to api.Email
|
||||
@@ -252,6 +254,30 @@ func ToActionArtifact(repo *repo_model.Repository, art *actions_model.ActionArti
|
||||
}, nil
|
||||
}
|
||||
|
||||
func ToActionRunner(ctx context.Context, runner *actions_model.ActionRunner) *api.ActionRunner {
|
||||
status := runner.Status()
|
||||
apiStatus := "offline"
|
||||
if runner.IsOnline() {
|
||||
apiStatus = "online"
|
||||
}
|
||||
labels := make([]*api.ActionRunnerLabel, len(runner.AgentLabels))
|
||||
for i, label := range runner.AgentLabels {
|
||||
labels[i] = &api.ActionRunnerLabel{
|
||||
ID: int64(i),
|
||||
Name: label,
|
||||
Type: "custom",
|
||||
}
|
||||
}
|
||||
return &api.ActionRunner{
|
||||
ID: runner.ID,
|
||||
Name: runner.Name,
|
||||
Status: apiStatus,
|
||||
Busy: status == runnerv1.RunnerStatus_RUNNER_STATUS_ACTIVE,
|
||||
Ephemeral: runner.Ephemeral,
|
||||
Labels: labels,
|
||||
}
|
||||
}
|
||||
|
||||
// ToVerification convert a git.Commit.Signature to an api.PayloadCommitVerification
|
||||
func ToVerification(ctx context.Context, c *git.Commit) *api.PayloadCommitVerification {
|
||||
verif := asymkey_service.ParseCommitWithSignature(ctx, c)
|
||||
|
Reference in New Issue
Block a user