-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Add event.schedule context for schedule actions task #37320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+70
−4
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
dde8339
Add event.schedule context for schedule actions task
lunny f665654
fix
lunny 8a737be
Log payload errors and tighten schedule tests
silverwind dc5a4f9
Merge branch 'main' into lunny/add_schedule_actions
GiteaBot d01be45
Merge branch 'main' into lunny/add_schedule_actions
GiteaBot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| // Copyright 2026 The Gitea Authors. All rights reserved. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package actions | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "code.gitea.io/gitea/modules/json" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| 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 * * * *") | ||
|
|
||
| event := map[string]any{} | ||
| assert.NoError(t, json.Unmarshal([]byte(updated), &event)) | ||
| assert.Equal(t, "*/5 * * * *", event["schedule"]) | ||
| assert.Equal(t, "refs/heads/main", event["ref"]) | ||
| }) | ||
|
|
||
| t.Run("keeps empty payload", func(t *testing.T) { | ||
| updated := withScheduleInEventPayload("", "37 12 5 1 2") | ||
| assert.Empty(t, updated) | ||
| }) | ||
|
|
||
| t.Run("keeps payload when schedule empty", func(t *testing.T) { | ||
| payload := `{"ref":"refs/heads/main"}` | ||
| updated := withScheduleInEventPayload(payload, "") | ||
| 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 * * * *") | ||
| assert.Equal(t, payload, updated) | ||
| }) | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
withScheduleInEventPayload will panic when eventPayload is the JSON literal "null": json.Unmarshal succeeds but sets the map to nil, and then event["schedule"] assignment panics. This can happen because schedule specs created via DetectAndHandleSchedules marshal a nil payload, resulting in "null" being stored. Also, when eventPayload is empty/whitespace, Unmarshal fails and the schedule is silently not added. Consider treating empty/"null" payloads as an empty object ({}), and after unmarshal defensively re-initialize the map if it is nil before setting the "schedule" field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This review is right, who marked it as resolved ........
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "fix" to this review is just wrong f665654