[ACTIONS] on.schedule: the event is always "schedule"

handleSchedules() is called every time an event is received and will
check the content of the main branch to (re)create scheduled events.
There is no reason why intput.Event will be relevant when the schedule
workflow runs.

(cherry picked from commit 9a712bb276f2103cd7bccc4bb07b6cc669537e38)
This commit is contained in:
Earl Warren 2023-12-23 12:14:02 +01:00
parent 248b8bb0fa
commit 892a8e1f4a
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
6 changed files with 15 additions and 1 deletions

View file

@ -22,6 +22,7 @@ const (
GithubEventRelease = "release"
GithubEventPullRequestComment = "pull_request_comment"
GithubEventGollum = "gollum"
GithubEventSchedule = "schedule"
)
// canGithubEventMatch check if the input Github event can match any Gitea event.
@ -34,6 +35,9 @@ func canGithubEventMatch(eventName string, triggedEvent webhook_module.HookEvent
case GithubEventGollum:
return triggedEvent == webhook_module.HookEventWiki
case GithubEventSchedule:
return triggedEvent == webhook_module.HookEventSchedule
case GithubEventIssues:
switch triggedEvent {
case webhook_module.HookEventIssues,

View file

@ -153,6 +153,7 @@ func detectMatched(gitRepo *git.Repository, commit *git.Commit, triggedEvent web
switch triggedEvent {
case // events with no activity types
webhook_module.HookEventSchedule,
webhook_module.HookEventCreate,
webhook_module.HookEventDelete,
webhook_module.HookEventFork,

View file

@ -118,6 +118,13 @@ func TestDetectMatched(t *testing.T) {
yamlOn: "on: gollum",
expected: true,
},
{
desc: "HookEventSchedue(schedule) matches GithubEventSchedule(schedule)",
triggedEvent: webhook_module.HookEventSchedule,
payload: nil,
yamlOn: "on: schedule",
expected: true,
},
}
for _, tc := range testCases {

View file

@ -31,6 +31,7 @@ const (
HookEventRepository HookEventType = "repository"
HookEventRelease HookEventType = "release"
HookEventPackage HookEventType = "package"
HookEventSchedule HookEventType = "schedule"
)
// Event returns the HookEventType as an event string

View file

@ -424,7 +424,7 @@ func handleSchedules(
TriggerUserID: input.Doer.ID,
Ref: input.Repo.DefaultBranch,
CommitSHA: commit.ID.String(),
Event: input.Event,
Event: webhook_module.HookEventType(api.HookScheduleCreated),
EventPayload: string(p),
Specs: schedules,
Content: dwf.Content,

View file

@ -112,6 +112,7 @@ func CreateScheduleTask(ctx context.Context, cron *actions_model.ActionSchedule)
Ref: cron.Ref,
CommitSHA: cron.CommitSHA,
Event: cron.Event,
TriggerEvent: string(webhook_module.HookEventSchedule),
EventPayload: cron.EventPayload,
ScheduleID: cron.ID,
Status: actions_model.StatusWaiting,