mirror of
https://github.com/go-gitea/gitea.git
synced 2026-05-25 16:08:46 +09:00
feat(actions): add before/after to PR synchronize event payload (#37827)
## Summary - Add `before` and `after` fields to `PullRequestPayload` for `synchronize` events - Thread push old/new commit SHAs through the PR synchronize notifier path (regular and Agit flows) - Populate the fields in webhook and Actions event payloads so workflows can access them via `github.event.before` and `github.event.after` Fixes #33395 --------- Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
59
modules/structs/hook_test.go
Normal file
59
modules/structs/hook_test.go
Normal file
@@ -0,0 +1,59 @@
|
||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package structs
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestPullRequestPayloadSynchronizeBeforeAfter(t *testing.T) {
|
||||
payload := &PullRequestPayload{
|
||||
Action: HookIssueSynchronized,
|
||||
Before: "1111111111111111111111111111111111111111",
|
||||
After: "2222222222222222222222222222222222222222",
|
||||
Index: 12,
|
||||
}
|
||||
|
||||
data, err := json.Marshal(payload)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.JSONEq(t, `{
|
||||
"action": "synchronized",
|
||||
"before": "1111111111111111111111111111111111111111",
|
||||
"after": "2222222222222222222222222222222222222222",
|
||||
"number": 12,
|
||||
"commit_id": "",
|
||||
"pull_request": null,
|
||||
"repository": null,
|
||||
"requested_reviewer": null,
|
||||
"review": null,
|
||||
"sender": null
|
||||
}`, string(data))
|
||||
}
|
||||
|
||||
func TestPullRequestPayloadNonSynchronizeOmitsBeforeAfter(t *testing.T) {
|
||||
payload := &PullRequestPayload{
|
||||
Action: HookIssueOpened,
|
||||
Index: 12,
|
||||
}
|
||||
|
||||
data, err := json.Marshal(payload)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.JSONEq(t, `{
|
||||
"action": "opened",
|
||||
"number": 12,
|
||||
"commit_id": "",
|
||||
"pull_request": null,
|
||||
"repository": null,
|
||||
"requested_reviewer": null,
|
||||
"review": null,
|
||||
"sender": null
|
||||
}`, string(data))
|
||||
}
|
||||
Reference in New Issue
Block a user