Add commit status for push event

This commit is contained in:
Lunny Xiao
2022-10-24 22:59:55 +08:00
committed by Jason Song
parent 0bc995889f
commit 82c6fc2217
5 changed files with 106 additions and 24 deletions

View File

@ -6,6 +6,7 @@ package bots
import (
"context"
"encoding/json"
"fmt"
"time"
@ -14,8 +15,9 @@ import (
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/models/webhook"
"code.gitea.io/gitea/modules/timeutil"
"xorm.io/builder"
api "code.gitea.io/gitea/modules/structs"
"xorm.io/builder"
"github.com/nektos/act/pkg/jobparser"
"golang.org/x/exp/slices"
)
@ -96,6 +98,17 @@ func (run *Run) TakeTime() time.Duration {
return time.Since(started).Truncate(time.Second)
}
func (run *Run) GetPushEventPayload() (*api.PushPayload, error) {
if run.Event == webhook.HookEventPush {
var payload api.PushPayload
if err := json.Unmarshal([]byte(run.EventPayload), &payload); err != nil {
return nil, err
}
return &payload, nil
}
return nil, fmt.Errorf("event %s is not a push event", run.Event)
}
func updateRepoRunsNumbers(ctx context.Context, repo *repo_model.Repository) error {
_, err := db.GetEngine(ctx).ID(repo.ID).
SetExpr("num_runs",