mirror of
				https://codeberg.org/forgejo/forgejo.git
				synced 2025-10-31 14:31:02 +00:00 
			
		
		
		
	- Massive replacement of changing `code.gitea.io/gitea` to `forgejo.org`. - Resolves forgejo/discussions#258 Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7337 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Reviewed-by: Michael Kriese <michael.kriese@gmx.de> Reviewed-by: Beowulf <beowulf@beocode.eu> Reviewed-by: Panagiotis "Ivory" Vasilopoulos <git@n0toose.net> Co-authored-by: Gusted <postmaster@gusted.xyz> Co-committed-by: Gusted <postmaster@gusted.xyz>
		
			
				
	
	
		
			72 lines
		
	
	
	
		
			1.9 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			72 lines
		
	
	
	
		
			1.9 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| // Copyright 2023 The Gitea Authors. All rights reserved.
 | |
| // SPDX-License-Identifier: MIT
 | |
| 
 | |
| package shared
 | |
| 
 | |
| import (
 | |
| 	"errors"
 | |
| 	"net/http"
 | |
| 	"strings"
 | |
| 
 | |
| 	actions_model "forgejo.org/models/actions"
 | |
| 	"forgejo.org/models/db"
 | |
| 	"forgejo.org/modules/structs"
 | |
| 	"forgejo.org/modules/util"
 | |
| 	"forgejo.org/services/context"
 | |
| )
 | |
| 
 | |
| // RegistrationToken is a string used to register a runner with a server
 | |
| // swagger:response RegistrationToken
 | |
| type RegistrationToken struct {
 | |
| 	Token string `json:"token"`
 | |
| }
 | |
| 
 | |
| func GetRegistrationToken(ctx *context.APIContext, ownerID, repoID int64) {
 | |
| 	token, err := actions_model.GetLatestRunnerToken(ctx, ownerID, repoID)
 | |
| 	if errors.Is(err, util.ErrNotExist) || (token != nil && !token.IsActive) {
 | |
| 		token, err = actions_model.NewRunnerToken(ctx, ownerID, repoID)
 | |
| 	}
 | |
| 	if err != nil {
 | |
| 		ctx.InternalServerError(err)
 | |
| 		return
 | |
| 	}
 | |
| 
 | |
| 	ctx.JSON(http.StatusOK, RegistrationToken{Token: token.Token})
 | |
| }
 | |
| 
 | |
| func GetActionRunJobs(ctx *context.APIContext, ownerID, repoID int64) {
 | |
| 	labels := strings.Split(ctx.FormTrim("labels"), ",")
 | |
| 
 | |
| 	total, err := db.Find[actions_model.ActionRunJob](ctx, &actions_model.FindTaskOptions{
 | |
| 		Status:  []actions_model.Status{actions_model.StatusWaiting, actions_model.StatusRunning},
 | |
| 		OwnerID: ownerID,
 | |
| 		RepoID:  repoID,
 | |
| 	})
 | |
| 	if err != nil {
 | |
| 		ctx.Error(http.StatusInternalServerError, "CountWaitingActionRunJobs", err)
 | |
| 		return
 | |
| 	}
 | |
| 
 | |
| 	res := fromRunJobModelToResponse(total, labels)
 | |
| 
 | |
| 	ctx.JSON(http.StatusOK, res)
 | |
| }
 | |
| 
 | |
| func fromRunJobModelToResponse(job []*actions_model.ActionRunJob, labels []string) []*structs.ActionRunJob {
 | |
| 	var res []*structs.ActionRunJob
 | |
| 	for i := range job {
 | |
| 		if job[i].ItRunsOn(labels) {
 | |
| 			res = append(res, &structs.ActionRunJob{
 | |
| 				ID:      job[i].ID,
 | |
| 				RepoID:  job[i].RepoID,
 | |
| 				OwnerID: job[i].OwnerID,
 | |
| 				Name:    job[i].Name,
 | |
| 				Needs:   job[i].Needs,
 | |
| 				RunsOn:  job[i].RunsOn,
 | |
| 				TaskID:  job[i].TaskID,
 | |
| 				Status:  job[i].Status.String(),
 | |
| 			})
 | |
| 		}
 | |
| 	}
 | |
| 	return res
 | |
| }
 |