Compare commits

...

4 Commits

Author SHA1 Message Date
Giteabot
5cb7ec9304 fix: make "test push webhook" always work (#38425) (#38455)
Backport #38425

* fix #38309
* fix #26238
* fix #37886

Co-authored-by: Harsh Satyajit Thakur <f20240223@goa.bits-pilani.ac.in>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
2026-07-15 05:51:44 +00:00
Giteabot
6e86c4cde8 fix(actions): prevent bulk actions from affecting all runners (#38453) (#38457)
Backport #38453

Co-authored-by: xkm <fzc_study@163.com>
2026-07-14 20:06:17 -07:00
Giteabot
c32af046a2 fix(org): align follow button and wrap description (#38448) (#38454)
Backport #38448

Co-authored-by: Shudhanshu Singh <sudhanshuwriterblc@gmail.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
2026-07-15 10:12:39 +08:00
Giteabot
a98468da30 fix(actions): populate github.event for scheduled runs (#38446) (#38452)
Backport #38446 by @silverwind

Scheduled runs stored a `null` event payload, so
`github.event.repository`/`sender`/`organization` were empty in
scheduled workflows. Every other event carries them, and so does GitHub
Actions. `CreateScheduleTask` now synthesizes them.

Co-authored-by: silverwind <me@silverwind.io>
2026-07-14 19:32:08 +02:00
15 changed files with 160 additions and 60 deletions

View File

@@ -2251,7 +2251,6 @@
"repo.settings.webhook_deletion_success": "The webhook has been removed.",
"repo.settings.webhook.test_delivery": "Test Push Event",
"repo.settings.webhook.test_delivery_desc": "Test this webhook with a fake push event.",
"repo.settings.webhook.test_delivery_desc_disabled": "To test this webhook with a fake event, activate it.",
"repo.settings.webhook.request": "Request",
"repo.settings.webhook.response": "Response",
"repo.settings.webhook.headers": "Headers",

View File

@@ -177,7 +177,7 @@ func TestHook(ctx *context.APIContext) {
commit := convert.ToPayloadCommit(ctx, ctx.Repo.Repository, ctx.Repo.Commit)
commitID := ctx.Repo.Commit.ID.String()
if err := webhook_service.PrepareWebhook(ctx, hook, webhook_module.HookEventPush, &api.PushPayload{
if err := webhook_service.PrepareTestWebhook(ctx, hook, webhook_module.HookEventPush, &api.PushPayload{
Ref: ref,
Before: commitID,
After: commitID,

View File

@@ -664,19 +664,14 @@ func TestWebhook(ctx *context.Context) {
return
}
// Grab latest commit or fake one if it's empty repository.
// Note: in old code, the "ctx.Repo.Commit" is the last commit of the default branch.
// New code doesn't set that commit, so it always uses the fake commit to test webhook.
commit := ctx.Repo.Commit
if commit == nil {
ghost := user_model.NewGhostUser()
objectFormat := git.ObjectFormatFromName(ctx.Repo.Repository.ObjectFormatName)
commit = &git.Commit{
ID: objectFormat.EmptyObjectID(),
Author: ghost.NewGitSig(),
Committer: ghost.NewGitSig(),
CommitMessage: git.CommitMessage{MessageRaw: "This is a fake commit"},
}
// use a fake commit to test webhook
ghostUser := user_model.NewGhostUser()
objectFormat := git.ObjectFormatFromName(ctx.Repo.Repository.ObjectFormatName)
commit := &git.Commit{
ID: objectFormat.EmptyObjectID(),
Author: ghostUser.NewGitSig(),
Committer: ghostUser.NewGitSig(),
CommitMessage: git.CommitMessage{MessageRaw: "This is a fake commit for webhook push test"},
}
apiUser := convert.ToUserWithAccessMode(ctx, ctx.Doer, perm.AccessModeNone)
@@ -697,7 +692,7 @@ func TestWebhook(ctx *context.Context) {
commitID := commit.ID.String()
p := &api.PushPayload{
Ref: git.BranchPrefix + ctx.Repo.Repository.DefaultBranch,
Ref: git.RefNameFromBranch(ctx.Repo.Repository.DefaultBranch).String(),
Before: commitID,
After: commitID,
CompareURL: setting.AppURL + ctx.Repo.Repository.ComposeCompareURL(commitID, commitID),
@@ -708,8 +703,8 @@ func TestWebhook(ctx *context.Context) {
Pusher: apiUser,
Sender: apiUser,
}
if err := webhook_service.PrepareWebhook(ctx, w, webhook_module.HookEventPush, p); err != nil {
ctx.Flash.Error("PrepareWebhook: " + err.Error())
if err := webhook_service.PrepareTestWebhook(ctx, w, webhook_module.HookEventPush, p); err != nil {
ctx.Flash.Error("PrepareTestWebhook: " + err.Error())
ctx.Status(http.StatusInternalServerError)
} else {
ctx.Flash.Info(ctx.Tr("repo.settings.webhook.delivery.success"))

View File

@@ -373,16 +373,18 @@ func RunnerBulkActionPost(ctx *context.Context) {
return
}
var runnerIDs []int64
if rCtx.IsAdmin {
// ATTENTION: it completely depends on the assumption that the doer is "site admin"
// So it doesn't do extra permission check to the runner IDs
// In the future, if you need to support such operation on non-admin pages, be careful!
runnerIDs = ctx.FormStringInt64s("ids")
} else {
if !rCtx.IsAdmin {
ctx.HTTPError(http.StatusForbidden, "bulk actions are admin-only")
return
}
// ATTENTION: it completely depends on the assumption that the doer is "site admin"
// So it doesn't do extra permission check to the runner IDs
// In the future, if you need to support such operation on non-admin pages, be careful!
runnerIDs := ctx.FormStringInt64s("ids")
if len(runnerIDs) == 0 {
ctx.HTTPError(http.StatusBadRequest, "missing runner IDs")
return
}
action := ctx.FormString("action")
var successKey, failedKey string

View File

@@ -6,16 +6,22 @@ package actions
import (
"context"
"fmt"
"maps"
"time"
actions_model "gitea.dev/models/actions"
"gitea.dev/models/db"
"gitea.dev/models/organization"
perm_model "gitea.dev/models/perm"
access_model "gitea.dev/models/perm/access"
repo_model "gitea.dev/models/repo"
"gitea.dev/models/unit"
user_model "gitea.dev/models/user"
"gitea.dev/modules/json"
"gitea.dev/modules/log"
"gitea.dev/modules/timeutil"
webhook_module "gitea.dev/modules/webhook"
"gitea.dev/services/convert"
)
// StartScheduleTasks start the task
@@ -102,7 +108,19 @@ func startTasks(ctx context.Context) error {
// It creates an action run based on the schedule, inserts it into the database, and creates commit statuses for each job.
func CreateScheduleTask(ctx context.Context, spec *actions_model.ActionScheduleSpec) error {
cron := spec.Schedule
eventPayload := withScheduleInEventPayload(cron.EventPayload, spec.Spec)
// Scheduled runs carry no webhook payload; synthesize what github.event.* expects.
if err := spec.Repo.LoadOwner(ctx); err != nil {
return fmt.Errorf("LoadOwner: %w", err)
}
fields := map[string]any{
"repository": convert.ToRepo(ctx, spec.Repo, access_model.Permission{AccessMode: perm_model.AccessModeRead}),
"sender": convert.ToUser(ctx, user_model.NewActionsUser(), nil),
}
if spec.Repo.Owner.IsOrganization() {
fields["organization"] = convert.ToOrganization(ctx, organization.OrgFromUser(spec.Repo.Owner))
}
eventPayload := withScheduleInEventPayload(cron.EventPayload, spec.Spec, fields)
// Create a new action run based on the schedule
run := &actions_model.ActionRun{
@@ -134,7 +152,7 @@ func CreateScheduleTask(ctx context.Context, spec *actions_model.ActionScheduleS
return nil
}
func withScheduleInEventPayload(eventPayload, schedule string) string {
func withScheduleInEventPayload(eventPayload, schedule string, fields map[string]any) string {
if schedule == "" {
return eventPayload
}
@@ -153,6 +171,7 @@ func withScheduleInEventPayload(eventPayload, schedule string) string {
event = map[string]any{}
}
maps.Copy(event, fields)
event["schedule"] = schedule
updatedPayload, err := json.Marshal(event)
if err != nil {

View File

@@ -7,6 +7,7 @@ import (
"testing"
"gitea.dev/modules/json"
api "gitea.dev/modules/structs"
"github.com/stretchr/testify/assert"
)
@@ -14,7 +15,7 @@ import (
func TestWithScheduleInEventPayload(t *testing.T) {
t.Run("adds schedule to existing payload", func(t *testing.T) {
payload := `{"ref":"refs/heads/main"}`
updated := withScheduleInEventPayload(payload, "*/5 * * * *")
updated := withScheduleInEventPayload(payload, "*/5 * * * *", nil)
event := map[string]any{}
assert.NoError(t, json.Unmarshal([]byte(updated), &event))
@@ -23,7 +24,7 @@ func TestWithScheduleInEventPayload(t *testing.T) {
})
t.Run("adds schedule to null payload", func(t *testing.T) {
updated := withScheduleInEventPayload("null", "37 12 5 1 2")
updated := withScheduleInEventPayload("null", "37 12 5 1 2", nil)
event := map[string]any{}
assert.NoError(t, json.Unmarshal([]byte(updated), &event))
@@ -31,22 +32,37 @@ func TestWithScheduleInEventPayload(t *testing.T) {
})
t.Run("adds schedule to empty payload", func(t *testing.T) {
updated := withScheduleInEventPayload("", "37 12 5 1 2")
updated := withScheduleInEventPayload("", "37 12 5 1 2", nil)
event := map[string]any{}
assert.NoError(t, json.Unmarshal([]byte(updated), &event))
assert.Equal(t, "37 12 5 1 2", event["schedule"])
})
t.Run("adds schedule with repository, sender, organization", func(t *testing.T) {
updated := withScheduleInEventPayload("null", "@weekly", map[string]any{
"repository": &api.Repository{Name: "test-repo"},
"sender": &api.User{UserName: "test-user"},
"organization": &api.Organization{Name: "test-org"},
})
event := map[string]any{}
assert.NoError(t, json.Unmarshal([]byte(updated), &event))
assert.Equal(t, "@weekly", event["schedule"])
assert.Equal(t, "test-repo", event["repository"].(map[string]any)["name"])
assert.Equal(t, "test-user", event["sender"].(map[string]any)["login"])
assert.Equal(t, "test-org", event["organization"].(map[string]any)["name"])
})
t.Run("keeps payload when schedule empty", func(t *testing.T) {
payload := `{"ref":"refs/heads/main"}`
updated := withScheduleInEventPayload(payload, "")
updated := withScheduleInEventPayload(payload, "", nil)
assert.Equal(t, payload, updated)
})
t.Run("keeps payload when malformed JSON", func(t *testing.T) {
payload := `not a json object`
updated := withScheduleInEventPayload(payload, "*/5 * * * *")
updated := withScheduleInEventPayload(payload, "*/5 * * * *", nil)
assert.Equal(t, payload, updated)
})
}

View File

@@ -129,6 +129,33 @@ func checkBranchFilter(branchFilter string, ref git.RefName) bool {
return g.Match(ref.String())
}
// PrepareTestWebhook always creates and enqueues a hook task for manual testing.
// Unlike PrepareWebhook, it ignores event subscriptions and branch filters so the
// Test Push Event control can verify delivery even when those gates would suppress
// a real event.
func PrepareTestWebhook(ctx context.Context, w *webhook_model.Webhook, event webhook_module.HookEventType, p api.Payloader) error {
if setting.DisableWebhooks {
return nil
}
payload, err := p.JSONPayload()
if err != nil {
return fmt.Errorf("JSONPayload for %s: %w", event, err)
}
task, err := webhook_model.CreateHookTask(ctx, &webhook_model.HookTask{
HookID: w.ID,
PayloadContent: string(payload),
EventType: event,
PayloadVersion: 2,
})
if err != nil {
return fmt.Errorf("CreateHookTask for %s: %w", event, err)
}
return enqueueHookTask(task.ID)
}
// PrepareWebhook creates a hook task and enqueues it for processing.
// The payload is saved as-is. The adjustments depending on the webhook type happen
// right before delivery, in the [Deliver] method.

View File

@@ -30,6 +30,7 @@ func TestWebhookService(t *testing.T) {
t.Run("PrepareBranchFilterNoMatch", testWebhookPrepareBranchFilterNoMatch)
t.Run("WebhookUserMail", testWebhookUserMail)
t.Run("CheckBranchFilter", testWebhookCheckBranchFilter)
t.Run("PrepareTestWebhookIgnoresGates", testPrepareTestWebhookIgnoresGates)
}
func testWebhookGetSlackHook(t *testing.T) {
@@ -132,3 +133,37 @@ func testWebhookCheckBranchFilter(t *testing.T) {
assert.Equal(t, v.match, checkBranchFilter(v.filter, v.ref), "filter: %q ref: %q", v.filter, v.ref)
}
}
func testPrepareTestWebhookIgnoresGates(t *testing.T) {
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
hook := &webhook_model.Webhook{
RepoID: repo.ID,
URL: "http://localhost/gitea-webhook-test-prepare_test_webhook",
ContentType: webhook_model.ContentTypeJSON,
IsActive: true,
HookEvent: &webhook_module.HookEvent{
ChooseEvents: true,
BranchFilter: "dev",
HookEvents: webhook_module.HookEvents{
webhook_module.HookEventWorkflowRun: true,
},
},
}
require.NoError(t, hook.UpdateEvent())
require.NoError(t, db.Insert(t.Context(), hook))
payload := &api.PushPayload{
Ref: "refs/heads/master",
Commits: []*api.PayloadCommit{{}},
}
hookTask := &webhook_model.HookTask{HookID: hook.ID, EventType: webhook_module.HookEventPush}
// Real deliveries stay gated: no push event + branch filter mismatch => nothing queued.
unittest.AssertNotExistsBean(t, hookTask)
require.NoError(t, PrepareWebhook(t.Context(), hook, webhook_module.HookEventPush, payload))
unittest.AssertNotExistsBean(t, hookTask)
// Manual test delivery always queues so the endpoint can be verified.
require.NoError(t, PrepareTestWebhook(t.Context(), hook, webhook_module.HookEventPush, payload))
unittest.AssertExistsAndLoadBean(t, hookTask)
}

View File

@@ -1,7 +1,17 @@
{{template "devtest/devtest-header"}}
<div class="page-content devtest">
<div class="ui container">
<h3>Flex List (standalone)</h3>
<h3>Flex Relaxed List</h3>
<div class="flex-container tw-border">
<div class="flex-relaxed-list tw-flex-1">
<div class="flex-left-right">
<span class="gt-ellipsis">left looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong</span>
<span>right</span>
</div>
</div>
</div>
<h3>Flex Divided List (standalone)</h3>
<div class="divider"></div>
<div class="flex-divided-list items-with-main">
<div class="item">
@@ -87,7 +97,7 @@
<div class="divider"></div>
<h3>Flex List (with "ui segment")</h3>
<h3>Flex Divided List (with "ui segment")</h3>
<div class="ui attached segment">
<div class="flex-divided-list">
<div class="item">item 1</div>
@@ -101,7 +111,7 @@
<div class="item">item 2</div>
</div>
</div>
<h3>Flex List (with "ui segment fitted", items have their own padding)</h3>
<h3>Flex Divided List (with "ui segment fitted", items have their own padding)</h3>
<div class="ui fitted segment">
<div class="flex-divided-list items-px-default">
<div class="item">item 1</div>

View File

@@ -1,6 +1,6 @@
<div class="ui container tw-flex tw-gap-4">
<div class="ui container flex-container">
<div>{{ctx.AvatarUtils.Avatar .Org 100}}</div>
<div class="flex-relaxed-list">
<div class="flex-relaxed-list tw-flex-1">
<div class="ui header flex-left-right tw-m-0">
<div class="flex-text-block">
<span class="tw-text-2xl">{{.Org.DisplayName}}</span>

View File

@@ -1,16 +1,12 @@
{{$isNew:=or .PageIsSettingsHooksNew .PageIsAdminDefaultHooksNew .PageIsAdminSystemHooksNew}}
{{if .PageIsSettingsHooksEdit}}
<h4 class="ui top attached header">
{{ctx.Locale.Tr "repo.settings.recent_deliveries"}}
<h4 class="ui top attached header flex-left-right">
<span>{{ctx.Locale.Tr "repo.settings.recent_deliveries"}}</span>
{{if .Permission.IsAdmin}}
<div class="ui right">
<!-- the button is wrapped with a span because the tooltip doesn't show on hover if we put data-tooltip-content directly on the button -->
<span data-tooltip-content="{{if or $isNew .Webhook.IsActive}}{{ctx.Locale.Tr "repo.settings.webhook.test_delivery_desc"}}{{else}}{{ctx.Locale.Tr "repo.settings.webhook.test_delivery_desc_disabled"}}{{end}}">
<button class="ui tiny button{{if not (or $isNew .Webhook.IsActive)}} disabled{{end}}" id="test-delivery" data-link="{{.Link}}/test">
<span class="text">{{ctx.Locale.Tr "repo.settings.webhook.test_delivery"}}</span>
</button>
</span>
</div>
<button class="ui tiny button" id="test-delivery" data-link="{{.Link}}/test"
data-tooltip-content="{{ctx.Locale.Tr "repo.settings.webhook.test_delivery_desc"}}"
>
{{ctx.Locale.Tr "repo.settings.webhook.test_delivery"}}
</button>
{{end}}
</h4>
<div class="ui attached segment">

View File

@@ -44,9 +44,9 @@
<div class="ui attached segment tw-hidden" data-global-init="initRunnerBulkToolbar">
<form action="{{$.Link}}/bulk" method="post" class="form-fetch-action">
<input type="hidden" name="ids">
<button class="ui small button" name="action" value="disable">{{ctx.Locale.Tr "actions.runners.disable_runner"}} <span class="runner-bulk-count"></span></button>
<button class="ui small button" name="action" value="enable">{{ctx.Locale.Tr "actions.runners.enable_runner"}} <span class="runner-bulk-count"></span></button>
<button class="ui small red button" name="action" value="delete"
<button class="ui small button runner-bulk-action" name="action" value="disable">{{ctx.Locale.Tr "actions.runners.disable_runner"}} <span class="runner-bulk-count"></span></button>
<button class="ui small button runner-bulk-action" name="action" value="enable">{{ctx.Locale.Tr "actions.runners.enable_runner"}} <span class="runner-bulk-count"></span></button>
<button class="ui small red button runner-bulk-action" name="action" value="delete"
data-modal-confirm-header="{{ctx.Locale.Tr "actions.runners.delete_runner_header"}}"
data-modal-confirm-content="{{ctx.Locale.Tr "actions.runners.delete_runner_notice"}}"
>{{ctx.Locale.Tr "actions.runners.delete_runner"}} <span class="runner-bulk-count"></span>

View File

@@ -196,6 +196,13 @@ func TestActionsRunnerModify(t *testing.T) {
doBulk(t, sessionAdmin, "evict", allIDs, http.StatusBadRequest)
})
t.Run("EmptyIDs", func(t *testing.T) {
doBulk(t, sessionAdmin, "delete", nil, http.StatusBadRequest)
for _, id := range allIDs {
unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRunner{ID: id})
}
})
t.Run("DisableEnable", func(t *testing.T) {
doBulk(t, sessionAdmin, "disable", allIDs, http.StatusOK)
for _, id := range allIDs {

View File

@@ -3,6 +3,8 @@
display: flex;
flex-direction: column;
gap: var(--gap-block);
min-width: 0; /* keep the same style as "flex-text-block" etc, make the text content wrap/ellipse correctly */
max-width: 100%;
}
.flex-relaxed-list > .divider {

View File

@@ -36,6 +36,7 @@ function initAdminRunnerBulk(toolbar: HTMLElement) {
const refresh = () => {
const checked = Array.from(rowCheckboxes).filter((c) => c.checked);
formRunnerIds.value = checked.map((c) => c.getAttribute('data-runner-id')!).join(',');
toggleElem(toolbar, checked.length > 0);
for (const btn of actionButtons) {
btn.querySelector<HTMLElement>('.runner-bulk-count')!.textContent = `(${checked.length})`;
@@ -50,15 +51,6 @@ function initAdminRunnerBulk(toolbar: HTMLElement) {
});
for (const cb of rowCheckboxes) cb.addEventListener('change', refresh);
refresh();
const collectSelectedIds = () => {
const ids = [];
for (const cb of rowCheckboxes) {
if (cb.checked) ids.push(cb.getAttribute('data-runner-id')!);
}
return ids.join(',');
};
formRunnerIds.value = collectSelectedIds();
}
function initAdminUser() {