2016-11-07 14:53:13 +01:00
|
|
|
// Copyright 2014 The Gogs Authors. All rights reserved.
|
2017-02-23 00:53:33 +01:00
|
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
2022-11-27 19:20:29 +01:00
|
|
|
// SPDX-License-Identifier: MIT
|
2016-11-07 14:53:13 +01:00
|
|
|
|
2019-05-11 12:21:34 +02:00
|
|
|
package structs
|
2016-11-07 14:53:13 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"strings"
|
|
|
|
"time"
|
2021-03-01 22:08:10 +01:00
|
|
|
|
2021-07-24 18:03:58 +02:00
|
|
|
"code.gitea.io/gitea/modules/json"
|
2016-11-07 14:53:13 +01:00
|
|
|
)
|
|
|
|
|
2022-01-20 18:46:10 +01:00
|
|
|
// ErrInvalidReceiveHook FIXME
|
|
|
|
var ErrInvalidReceiveHook = errors.New("Invalid JSON payload received over webhook")
|
2016-11-07 14:53:13 +01:00
|
|
|
|
2016-11-29 09:09:17 +01:00
|
|
|
// Hook a hook is a web hook when one repository changed
|
2016-11-07 14:53:13 +01:00
|
|
|
type Hook struct {
|
2022-11-03 19:23:20 +01:00
|
|
|
ID int64 `json:"id"`
|
|
|
|
Type string `json:"type"`
|
2023-08-21 13:43:52 +02:00
|
|
|
BranchFilter string `json:"branch_filter"`
|
2022-11-03 19:23:20 +01:00
|
|
|
URL string `json:"-"`
|
|
|
|
Config map[string]string `json:"config"`
|
|
|
|
Events []string `json:"events"`
|
|
|
|
AuthorizationHeader string `json:"authorization_header"`
|
|
|
|
Active bool `json:"active"`
|
2017-11-13 08:02:25 +01:00
|
|
|
// swagger:strfmt date-time
|
2018-03-06 02:22:16 +01:00
|
|
|
Updated time.Time `json:"updated_at"`
|
2017-11-13 08:02:25 +01:00
|
|
|
// swagger:strfmt date-time
|
2018-03-06 02:22:16 +01:00
|
|
|
Created time.Time `json:"created_at"`
|
2016-11-07 14:53:13 +01:00
|
|
|
}
|
|
|
|
|
2017-08-21 13:13:47 +02:00
|
|
|
// HookList represents a list of API hook.
|
|
|
|
type HookList []*Hook
|
|
|
|
|
2019-12-31 05:11:15 +01:00
|
|
|
// CreateHookOptionConfig has all config options in it
|
|
|
|
// required are "content_type" and "url" Required
|
|
|
|
type CreateHookOptionConfig map[string]string
|
|
|
|
|
2016-11-29 09:09:17 +01:00
|
|
|
// CreateHookOption options when create a hook
|
2016-11-07 14:53:13 +01:00
|
|
|
type CreateHookOption struct {
|
2017-11-13 08:02:25 +01:00
|
|
|
// required: true
|
2022-01-23 14:46:30 +01:00
|
|
|
// enum: dingtalk,discord,gitea,gogs,msteams,slack,telegram,feishu,wechatwork,packagist
|
2017-08-21 13:13:47 +02:00
|
|
|
Type string `json:"type" binding:"Required"`
|
2017-11-13 08:02:25 +01:00
|
|
|
// required: true
|
2022-11-03 19:23:20 +01:00
|
|
|
Config CreateHookOptionConfig `json:"config" binding:"Required"`
|
|
|
|
Events []string `json:"events"`
|
|
|
|
BranchFilter string `json:"branch_filter" binding:"GlobPattern"`
|
|
|
|
AuthorizationHeader string `json:"authorization_header"`
|
2017-11-13 08:02:25 +01:00
|
|
|
// default: false
|
2017-08-21 13:13:47 +02:00
|
|
|
Active bool `json:"active"`
|
2016-11-07 14:53:13 +01:00
|
|
|
}
|
|
|
|
|
2016-11-29 09:09:17 +01:00
|
|
|
// EditHookOption options when modify one hook
|
2016-11-07 14:53:13 +01:00
|
|
|
type EditHookOption struct {
|
2022-11-03 19:23:20 +01:00
|
|
|
Config map[string]string `json:"config"`
|
|
|
|
Events []string `json:"events"`
|
|
|
|
BranchFilter string `json:"branch_filter" binding:"GlobPattern"`
|
|
|
|
AuthorizationHeader string `json:"authorization_header"`
|
|
|
|
Active *bool `json:"active"`
|
2016-11-07 14:53:13 +01:00
|
|
|
}
|
|
|
|
|
2016-11-29 09:09:17 +01:00
|
|
|
// Payloader payload is some part of one hook
|
2016-11-07 14:53:13 +01:00
|
|
|
type Payloader interface {
|
|
|
|
JSONPayload() ([]byte, error)
|
|
|
|
}
|
|
|
|
|
2017-11-13 08:02:25 +01:00
|
|
|
// PayloadUser represents the author or committer of a commit
|
2016-11-07 14:53:13 +01:00
|
|
|
type PayloadUser struct {
|
2017-11-13 08:02:25 +01:00
|
|
|
// Full name of the commit author
|
2018-03-06 02:22:16 +01:00
|
|
|
Name string `json:"name"`
|
2017-11-13 08:02:25 +01:00
|
|
|
// swagger:strfmt email
|
2016-11-07 14:53:13 +01:00
|
|
|
Email string `json:"email"`
|
|
|
|
UserName string `json:"username"`
|
|
|
|
}
|
|
|
|
|
2017-11-13 08:02:25 +01:00
|
|
|
// FIXME: consider using same format as API when commits API are added.
|
|
|
|
// applies to PayloadCommit and PayloadCommitVerification
|
|
|
|
|
|
|
|
// PayloadCommit represents a commit
|
2016-11-07 14:53:13 +01:00
|
|
|
type PayloadCommit struct {
|
2017-11-13 08:02:25 +01:00
|
|
|
// sha1 hash of the commit
|
2017-03-22 11:43:54 +01:00
|
|
|
ID string `json:"id"`
|
|
|
|
Message string `json:"message"`
|
|
|
|
URL string `json:"url"`
|
|
|
|
Author *PayloadUser `json:"author"`
|
|
|
|
Committer *PayloadUser `json:"committer"`
|
|
|
|
Verification *PayloadCommitVerification `json:"verification"`
|
2017-11-13 08:02:25 +01:00
|
|
|
// swagger:strfmt date-time
|
2018-03-06 02:22:16 +01:00
|
|
|
Timestamp time.Time `json:"timestamp"`
|
2019-01-30 17:33:00 +01:00
|
|
|
Added []string `json:"added"`
|
|
|
|
Removed []string `json:"removed"`
|
|
|
|
Modified []string `json:"modified"`
|
2017-03-22 11:43:54 +01:00
|
|
|
}
|
|
|
|
|
2017-11-13 08:02:25 +01:00
|
|
|
// PayloadCommitVerification represents the GPG verification of a commit
|
2017-03-22 11:43:54 +01:00
|
|
|
type PayloadCommitVerification struct {
|
2019-10-16 15:42:42 +02:00
|
|
|
Verified bool `json:"verified"`
|
|
|
|
Reason string `json:"reason"`
|
|
|
|
Signature string `json:"signature"`
|
|
|
|
Signer *PayloadUser `json:"signer"`
|
|
|
|
Payload string `json:"payload"`
|
2016-11-07 14:53:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
_ Payloader = &CreatePayload{}
|
2018-05-16 16:01:55 +02:00
|
|
|
_ Payloader = &DeletePayload{}
|
|
|
|
_ Payloader = &ForkPayload{}
|
2016-11-07 14:53:13 +01:00
|
|
|
_ Payloader = &PushPayload{}
|
2017-02-23 00:53:33 +01:00
|
|
|
_ Payloader = &IssuePayload{}
|
2018-05-16 16:01:55 +02:00
|
|
|
_ Payloader = &IssueCommentPayload{}
|
2016-11-07 14:53:13 +01:00
|
|
|
_ Payloader = &PullRequestPayload{}
|
2018-05-16 16:01:55 +02:00
|
|
|
_ Payloader = &RepositoryPayload{}
|
|
|
|
_ Payloader = &ReleasePayload{}
|
2022-03-30 10:42:47 +02:00
|
|
|
_ Payloader = &PackagePayload{}
|
2016-11-07 14:53:13 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// _________ __
|
|
|
|
// \_ ___ \_______ ____ _____ _/ |_ ____
|
|
|
|
// / \ \/\_ __ \_/ __ \\__ \\ __\/ __ \
|
|
|
|
// \ \____| | \/\ ___/ / __ \| | \ ___/
|
|
|
|
// \______ /|__| \___ >____ /__| \___ >
|
|
|
|
// \/ \/ \/ \/
|
|
|
|
|
2016-11-29 09:09:17 +01:00
|
|
|
// CreatePayload FIXME
|
2016-11-07 14:53:13 +01:00
|
|
|
type CreatePayload struct {
|
2016-11-29 09:09:17 +01:00
|
|
|
Sha string `json:"sha"`
|
2016-11-07 14:53:13 +01:00
|
|
|
Ref string `json:"ref"`
|
|
|
|
RefType string `json:"ref_type"`
|
|
|
|
Repo *Repository `json:"repository"`
|
|
|
|
Sender *User `json:"sender"`
|
|
|
|
}
|
|
|
|
|
2016-11-29 09:09:17 +01:00
|
|
|
// JSONPayload return payload information
|
2016-11-07 14:53:13 +01:00
|
|
|
func (p *CreatePayload) JSONPayload() ([]byte, error) {
|
|
|
|
return json.MarshalIndent(p, "", " ")
|
|
|
|
}
|
|
|
|
|
|
|
|
// ParseCreateHook parses create event hook content.
|
|
|
|
func ParseCreateHook(raw []byte) (*CreatePayload, error) {
|
|
|
|
hook := new(CreatePayload)
|
|
|
|
if err := json.Unmarshal(raw, hook); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// it is possible the JSON was parsed, however,
|
|
|
|
// was not from Gogs (maybe was from Bitbucket)
|
|
|
|
// So we'll check to be sure certain key fields
|
|
|
|
// were populated
|
|
|
|
switch {
|
|
|
|
case hook.Repo == nil:
|
|
|
|
return nil, ErrInvalidReceiveHook
|
|
|
|
case len(hook.Ref) == 0:
|
|
|
|
return nil, ErrInvalidReceiveHook
|
|
|
|
}
|
|
|
|
return hook, nil
|
|
|
|
}
|
|
|
|
|
2018-05-16 16:01:55 +02:00
|
|
|
// ________ .__ __
|
|
|
|
// \______ \ ____ | | _____/ |_ ____
|
|
|
|
// | | \_/ __ \| | _/ __ \ __\/ __ \
|
|
|
|
// | ` \ ___/| |_\ ___/| | \ ___/
|
|
|
|
// /_______ /\___ >____/\___ >__| \___ >
|
|
|
|
// \/ \/ \/ \/
|
|
|
|
|
|
|
|
// PusherType define the type to push
|
|
|
|
type PusherType string
|
|
|
|
|
|
|
|
// describe all the PusherTypes
|
|
|
|
const (
|
|
|
|
PusherTypeUser PusherType = "user"
|
|
|
|
)
|
|
|
|
|
|
|
|
// DeletePayload represents delete payload
|
|
|
|
type DeletePayload struct {
|
|
|
|
Ref string `json:"ref"`
|
|
|
|
RefType string `json:"ref_type"`
|
|
|
|
PusherType PusherType `json:"pusher_type"`
|
|
|
|
Repo *Repository `json:"repository"`
|
|
|
|
Sender *User `json:"sender"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// JSONPayload implements Payload
|
|
|
|
func (p *DeletePayload) JSONPayload() ([]byte, error) {
|
|
|
|
return json.MarshalIndent(p, "", " ")
|
|
|
|
}
|
|
|
|
|
|
|
|
// ___________ __
|
|
|
|
// \_ _____/__________| | __
|
|
|
|
// | __)/ _ \_ __ \ |/ /
|
|
|
|
// | \( <_> ) | \/ <
|
|
|
|
// \___ / \____/|__| |__|_ \
|
|
|
|
// \/ \/
|
|
|
|
|
|
|
|
// ForkPayload represents fork payload
|
|
|
|
type ForkPayload struct {
|
|
|
|
Forkee *Repository `json:"forkee"`
|
|
|
|
Repo *Repository `json:"repository"`
|
|
|
|
Sender *User `json:"sender"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// JSONPayload implements Payload
|
|
|
|
func (p *ForkPayload) JSONPayload() ([]byte, error) {
|
|
|
|
return json.MarshalIndent(p, "", " ")
|
|
|
|
}
|
|
|
|
|
|
|
|
// HookIssueCommentAction defines hook issue comment action
|
|
|
|
type HookIssueCommentAction string
|
|
|
|
|
|
|
|
// all issue comment actions
|
|
|
|
const (
|
|
|
|
HookIssueCommentCreated HookIssueCommentAction = "created"
|
|
|
|
HookIssueCommentEdited HookIssueCommentAction = "edited"
|
|
|
|
HookIssueCommentDeleted HookIssueCommentAction = "deleted"
|
|
|
|
)
|
|
|
|
|
|
|
|
// IssueCommentPayload represents a payload information of issue comment event.
|
|
|
|
type IssueCommentPayload struct {
|
2024-10-16 11:10:05 +02:00
|
|
|
Action HookIssueCommentAction `json:"action"`
|
|
|
|
Issue *Issue `json:"issue"`
|
|
|
|
PullRequest *PullRequest `json:"pull_request,omitempty"`
|
|
|
|
Comment *Comment `json:"comment"`
|
|
|
|
Changes *ChangesPayload `json:"changes,omitempty"`
|
|
|
|
Repository *Repository `json:"repository"`
|
|
|
|
Sender *User `json:"sender"`
|
|
|
|
IsPull bool `json:"is_pull"`
|
2018-05-16 16:01:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// JSONPayload implements Payload
|
|
|
|
func (p *IssueCommentPayload) JSONPayload() ([]byte, error) {
|
|
|
|
return json.MarshalIndent(p, "", " ")
|
|
|
|
}
|
|
|
|
|
|
|
|
// __________ .__
|
|
|
|
// \______ \ ____ | | ____ _____ ______ ____
|
|
|
|
// | _// __ \| | _/ __ \\__ \ / ___// __ \
|
|
|
|
// | | \ ___/| |_\ ___/ / __ \_\___ \\ ___/
|
|
|
|
// |____|_ /\___ >____/\___ >____ /____ >\___ >
|
|
|
|
// \/ \/ \/ \/ \/ \/
|
|
|
|
|
|
|
|
// HookReleaseAction defines hook release action type
|
|
|
|
type HookReleaseAction string
|
|
|
|
|
|
|
|
// all release actions
|
|
|
|
const (
|
|
|
|
HookReleasePublished HookReleaseAction = "published"
|
2018-05-21 04:28:29 +02:00
|
|
|
HookReleaseUpdated HookReleaseAction = "updated"
|
|
|
|
HookReleaseDeleted HookReleaseAction = "deleted"
|
2018-05-16 16:01:55 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// ReleasePayload represents a payload information of release event.
|
|
|
|
type ReleasePayload struct {
|
|
|
|
Action HookReleaseAction `json:"action"`
|
|
|
|
Release *Release `json:"release"`
|
|
|
|
Repository *Repository `json:"repository"`
|
|
|
|
Sender *User `json:"sender"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// JSONPayload implements Payload
|
|
|
|
func (p *ReleasePayload) JSONPayload() ([]byte, error) {
|
|
|
|
return json.MarshalIndent(p, "", " ")
|
|
|
|
}
|
|
|
|
|
2016-11-07 14:53:13 +01:00
|
|
|
// PushPayload represents a payload information of push event.
|
|
|
|
type PushPayload struct {
|
2022-10-16 18:22:34 +02:00
|
|
|
Ref string `json:"ref"`
|
|
|
|
Before string `json:"before"`
|
|
|
|
After string `json:"after"`
|
|
|
|
CompareURL string `json:"compare_url"`
|
|
|
|
Commits []*PayloadCommit `json:"commits"`
|
|
|
|
TotalCommits int `json:"total_commits"`
|
|
|
|
HeadCommit *PayloadCommit `json:"head_commit"`
|
|
|
|
Repo *Repository `json:"repository"`
|
|
|
|
Pusher *User `json:"pusher"`
|
|
|
|
Sender *User `json:"sender"`
|
2016-11-07 14:53:13 +01:00
|
|
|
}
|
|
|
|
|
2016-11-29 09:09:17 +01:00
|
|
|
// JSONPayload FIXME
|
2016-11-07 14:53:13 +01:00
|
|
|
func (p *PushPayload) JSONPayload() ([]byte, error) {
|
|
|
|
return json.MarshalIndent(p, "", " ")
|
|
|
|
}
|
|
|
|
|
|
|
|
// ParsePushHook parses push event hook content.
|
|
|
|
func ParsePushHook(raw []byte) (*PushPayload, error) {
|
|
|
|
hook := new(PushPayload)
|
|
|
|
if err := json.Unmarshal(raw, hook); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
switch {
|
|
|
|
case hook.Repo == nil:
|
|
|
|
return nil, ErrInvalidReceiveHook
|
|
|
|
case len(hook.Ref) == 0:
|
|
|
|
return nil, ErrInvalidReceiveHook
|
|
|
|
}
|
|
|
|
return hook, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Branch returns branch name from a payload
|
|
|
|
func (p *PushPayload) Branch() string {
|
2020-10-11 22:27:20 +02:00
|
|
|
return strings.ReplaceAll(p.Ref, "refs/heads/", "")
|
2016-11-07 14:53:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// .___
|
|
|
|
// | | ______ ________ __ ____
|
|
|
|
// | |/ ___// ___/ | \_/ __ \
|
|
|
|
// | |\___ \ \___ \| | /\ ___/
|
|
|
|
// |___/____ >____ >____/ \___ >
|
|
|
|
// \/ \/ \/
|
|
|
|
|
2016-11-29 09:09:17 +01:00
|
|
|
// HookIssueAction FIXME
|
2016-11-07 14:53:13 +01:00
|
|
|
type HookIssueAction string
|
|
|
|
|
|
|
|
const (
|
2016-11-29 09:09:17 +01:00
|
|
|
// HookIssueOpened opened
|
|
|
|
HookIssueOpened HookIssueAction = "opened"
|
|
|
|
// HookIssueClosed closed
|
|
|
|
HookIssueClosed HookIssueAction = "closed"
|
|
|
|
// HookIssueReOpened reopened
|
|
|
|
HookIssueReOpened HookIssueAction = "reopened"
|
|
|
|
// HookIssueEdited edited
|
|
|
|
HookIssueEdited HookIssueAction = "edited"
|
|
|
|
// HookIssueAssigned assigned
|
|
|
|
HookIssueAssigned HookIssueAction = "assigned"
|
|
|
|
// HookIssueUnassigned unassigned
|
|
|
|
HookIssueUnassigned HookIssueAction = "unassigned"
|
|
|
|
// HookIssueLabelUpdated label_updated
|
2016-11-07 16:37:32 +01:00
|
|
|
HookIssueLabelUpdated HookIssueAction = "label_updated"
|
2016-11-29 09:09:17 +01:00
|
|
|
// HookIssueLabelCleared label_cleared
|
2016-11-07 16:37:32 +01:00
|
|
|
HookIssueLabelCleared HookIssueAction = "label_cleared"
|
2016-11-29 09:09:17 +01:00
|
|
|
// HookIssueSynchronized synchronized
|
|
|
|
HookIssueSynchronized HookIssueAction = "synchronized"
|
2017-02-23 00:53:33 +01:00
|
|
|
// HookIssueMilestoned is an issue action for when a milestone is set on an issue.
|
|
|
|
HookIssueMilestoned HookIssueAction = "milestoned"
|
|
|
|
// HookIssueDemilestoned is an issue action for when a milestone is cleared on an issue.
|
|
|
|
HookIssueDemilestoned HookIssueAction = "demilestoned"
|
2020-03-06 06:10:48 +01:00
|
|
|
// HookIssueReviewed is an issue action for when a pull request is reviewed
|
|
|
|
HookIssueReviewed HookIssueAction = "reviewed"
|
2023-05-25 04:06:27 +02:00
|
|
|
// HookIssueReviewRequested is an issue action for when a reviewer is requested for a pull request.
|
|
|
|
HookIssueReviewRequested HookIssueAction = "review_requested"
|
|
|
|
// HookIssueReviewRequestRemoved is an issue action for removing a review request to someone on a pull request.
|
|
|
|
HookIssueReviewRequestRemoved HookIssueAction = "review_request_removed"
|
2016-11-07 14:53:13 +01:00
|
|
|
)
|
|
|
|
|
2017-02-23 00:53:33 +01:00
|
|
|
// IssuePayload represents the payload information that is sent along with an issue event.
|
|
|
|
type IssuePayload struct {
|
|
|
|
Action HookIssueAction `json:"action"`
|
|
|
|
Index int64 `json:"number"`
|
|
|
|
Changes *ChangesPayload `json:"changes,omitempty"`
|
|
|
|
Issue *Issue `json:"issue"`
|
|
|
|
Repository *Repository `json:"repository"`
|
|
|
|
Sender *User `json:"sender"`
|
2023-01-25 05:47:53 +01:00
|
|
|
CommitID string `json:"commit_id"`
|
2017-02-23 00:53:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// JSONPayload encodes the IssuePayload to JSON, with an indentation of two spaces.
|
|
|
|
func (p *IssuePayload) JSONPayload() ([]byte, error) {
|
|
|
|
return json.MarshalIndent(p, "", " ")
|
|
|
|
}
|
|
|
|
|
2016-11-29 09:09:17 +01:00
|
|
|
// ChangesFromPayload FIXME
|
2016-11-07 14:53:13 +01:00
|
|
|
type ChangesFromPayload struct {
|
|
|
|
From string `json:"from"`
|
|
|
|
}
|
|
|
|
|
2019-12-16 07:20:25 +01:00
|
|
|
// ChangesPayload represents the payload information of issue change
|
2016-11-07 14:53:13 +01:00
|
|
|
type ChangesPayload struct {
|
|
|
|
Title *ChangesFromPayload `json:"title,omitempty"`
|
|
|
|
Body *ChangesFromPayload `json:"body,omitempty"`
|
2019-12-16 07:20:25 +01:00
|
|
|
Ref *ChangesFromPayload `json:"ref,omitempty"`
|
2016-11-07 14:53:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// __________ .__ .__ __________ __
|
|
|
|
// \______ \__ __| | | | \______ \ ____ ________ __ ____ _______/ |_
|
|
|
|
// | ___/ | \ | | | | _// __ \/ ____/ | \_/ __ \ / ___/\ __\
|
|
|
|
// | | | | / |_| |__ | | \ ___< <_| | | /\ ___/ \___ \ | |
|
|
|
|
// |____| |____/|____/____/ |____|_ /\___ >__ |____/ \___ >____ > |__|
|
|
|
|
// \/ \/ |__| \/ \/
|
|
|
|
|
|
|
|
// PullRequestPayload represents a payload information of pull request event.
|
|
|
|
type PullRequestPayload struct {
|
2023-05-25 04:06:27 +02:00
|
|
|
Action HookIssueAction `json:"action"`
|
|
|
|
Index int64 `json:"number"`
|
|
|
|
Changes *ChangesPayload `json:"changes,omitempty"`
|
|
|
|
PullRequest *PullRequest `json:"pull_request"`
|
|
|
|
RequestedReviewer *User `json:"requested_reviewer"`
|
|
|
|
Repository *Repository `json:"repository"`
|
|
|
|
Sender *User `json:"sender"`
|
|
|
|
CommitID string `json:"commit_id"`
|
|
|
|
Review *ReviewPayload `json:"review"`
|
2016-11-07 14:53:13 +01:00
|
|
|
}
|
|
|
|
|
2016-11-29 09:09:17 +01:00
|
|
|
// JSONPayload FIXME
|
2016-11-07 14:53:13 +01:00
|
|
|
func (p *PullRequestPayload) JSONPayload() ([]byte, error) {
|
|
|
|
return json.MarshalIndent(p, "", " ")
|
|
|
|
}
|
2017-05-05 04:55:54 +02:00
|
|
|
|
2019-10-19 00:42:04 +02:00
|
|
|
// ReviewPayload FIXME
|
|
|
|
type ReviewPayload struct {
|
|
|
|
Type string `json:"type"`
|
|
|
|
Content string `json:"content"`
|
|
|
|
}
|
|
|
|
|
2022-09-04 21:54:23 +02:00
|
|
|
// __ __.__ __ .__
|
|
|
|
// / \ / \__| | _|__|
|
|
|
|
// \ \/\/ / | |/ / |
|
|
|
|
// \ /| | <| |
|
|
|
|
// \__/\ / |__|__|_ \__|
|
|
|
|
// \/ \/
|
|
|
|
|
|
|
|
// HookWikiAction an action that happens to a wiki page
|
|
|
|
type HookWikiAction string
|
|
|
|
|
|
|
|
const (
|
|
|
|
// HookWikiCreated created
|
|
|
|
HookWikiCreated HookWikiAction = "created"
|
|
|
|
// HookWikiEdited edited
|
|
|
|
HookWikiEdited HookWikiAction = "edited"
|
|
|
|
// HookWikiDeleted deleted
|
|
|
|
HookWikiDeleted HookWikiAction = "deleted"
|
|
|
|
)
|
|
|
|
|
|
|
|
// WikiPayload payload for repository webhooks
|
|
|
|
type WikiPayload struct {
|
|
|
|
Action HookWikiAction `json:"action"`
|
|
|
|
Repository *Repository `json:"repository"`
|
|
|
|
Sender *User `json:"sender"`
|
|
|
|
Page string `json:"page"`
|
|
|
|
Comment string `json:"comment"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// JSONPayload JSON representation of the payload
|
|
|
|
func (p *WikiPayload) JSONPayload() ([]byte, error) {
|
|
|
|
return json.MarshalIndent(p, "", " ")
|
|
|
|
}
|
|
|
|
|
2017-05-05 04:55:54 +02:00
|
|
|
//__________ .__ __
|
|
|
|
//\______ \ ____ ______ ____ _____|__|/ |_ ___________ ___.__.
|
|
|
|
// | _// __ \\____ \ / _ \/ ___/ \ __\/ _ \_ __ < | |
|
|
|
|
// | | \ ___/| |_> > <_> )___ \| || | ( <_> ) | \/\___ |
|
|
|
|
// |____|_ /\___ > __/ \____/____ >__||__| \____/|__| / ____|
|
|
|
|
// \/ \/|__| \/ \/
|
|
|
|
|
|
|
|
// HookRepoAction an action that happens to a repo
|
|
|
|
type HookRepoAction string
|
|
|
|
|
|
|
|
const (
|
|
|
|
// HookRepoCreated created
|
|
|
|
HookRepoCreated HookRepoAction = "created"
|
|
|
|
// HookRepoDeleted deleted
|
|
|
|
HookRepoDeleted HookRepoAction = "deleted"
|
|
|
|
)
|
|
|
|
|
|
|
|
// RepositoryPayload payload for repository webhooks
|
|
|
|
type RepositoryPayload struct {
|
|
|
|
Action HookRepoAction `json:"action"`
|
|
|
|
Repository *Repository `json:"repository"`
|
|
|
|
Organization *User `json:"organization"`
|
|
|
|
Sender *User `json:"sender"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// JSONPayload JSON representation of the payload
|
|
|
|
func (p *RepositoryPayload) JSONPayload() ([]byte, error) {
|
|
|
|
return json.MarshalIndent(p, "", " ")
|
|
|
|
}
|
2022-03-30 10:42:47 +02:00
|
|
|
|
|
|
|
// HookPackageAction an action that happens to a package
|
|
|
|
type HookPackageAction string
|
|
|
|
|
|
|
|
const (
|
|
|
|
// HookPackageCreated created
|
|
|
|
HookPackageCreated HookPackageAction = "created"
|
|
|
|
// HookPackageDeleted deleted
|
|
|
|
HookPackageDeleted HookPackageAction = "deleted"
|
|
|
|
)
|
|
|
|
|
|
|
|
// PackagePayload represents a package payload
|
|
|
|
type PackagePayload struct {
|
|
|
|
Action HookPackageAction `json:"action"`
|
|
|
|
Repository *Repository `json:"repository"`
|
|
|
|
Package *Package `json:"package"`
|
|
|
|
Organization *User `json:"organization"`
|
|
|
|
Sender *User `json:"sender"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// JSONPayload implements Payload
|
|
|
|
func (p *PackagePayload) JSONPayload() ([]byte, error) {
|
|
|
|
return json.MarshalIndent(p, "", " ")
|
|
|
|
}
|
Actions support workflow dispatch event (#28163)
fix #23668
My plan:
* In the `actions.list` method, if workflow is selected and IsAdmin,
check whether the on event contains `workflow_dispatch`. If so, display
a `Run workflow` button to allow the user to manually trigger the run.
* Providing a form that allows users to select target brach or tag, and
these parameters can be configured in yaml
* Simple form validation, `required` input cannot be empty
* Add a route `/actions/run`, and an `actions.Run` method to handle
* Add `WorkflowDispatchPayload` struct to pass the Webhook event payload
to the runner when triggered, this payload carries the `inputs` values
and other fields, doc: [workflow_dispatch
payload](https://docs.github.com/en/webhooks/webhook-events-and-payloads#workflow_dispatch)
Other PRs
* the `Workflow.WorkflowDispatchConfig()` method still return non-nil
when workflow_dispatch is not defined. I submitted a PR
https://gitea.com/gitea/act/pulls/85 to fix it. Still waiting for them
to process.
Behavior should be same with github, but may cause confusion. Here's a
quick reminder.
*
[Doc](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_dispatch)
Said: This event will `only` trigger a workflow run if the workflow file
is `on the default branch`.
* If the workflow yaml file only exists in a non-default branch, it
cannot be triggered. (It will not even show up in the workflow list)
* If the same workflow yaml file exists in each branch at the same time,
the version of the default branch is used. Even if `Use workflow from`
selects another branch
![image](https://github.com/go-gitea/gitea/assets/3114995/4bf596f3-426b-48e8-9b8f-0f6d18defd79)
```yaml
name: Docker Image CI
on:
workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
required: true
default: 'warning'
type: choice
options:
- info
- warning
- debug
tags:
description: 'Test scenario tags'
required: false
type: boolean
boolean_default_true:
description: 'Test scenario tags'
required: true
type: boolean
default: true
boolean_default_false:
description: 'Test scenario tags'
required: false
type: boolean
default: false
environment:
description: 'Environment to run tests against'
type: environment
required: true
default: 'environment values'
number_required_1:
description: 'number '
type: number
required: true
default: '100'
number_required_2:
description: 'number'
type: number
required: true
default: '100'
number_required_3:
description: 'number'
type: number
required: true
default: '100'
number_1:
description: 'number'
type: number
required: false
number_2:
description: 'number'
type: number
required: false
number_3:
description: 'number'
type: number
required: false
env:
inputs_logLevel: ${{ inputs.logLevel }}
inputs_tags: ${{ inputs.tags }}
inputs_boolean_default_true: ${{ inputs.boolean_default_true }}
inputs_boolean_default_false: ${{ inputs.boolean_default_false }}
inputs_environment: ${{ inputs.environment }}
inputs_number_1: ${{ inputs.number_1 }}
inputs_number_2: ${{ inputs.number_2 }}
inputs_number_3: ${{ inputs.number_3 }}
inputs_number_required_1: ${{ inputs.number_required_1 }}
inputs_number_required_2: ${{ inputs.number_required_2 }}
inputs_number_required_3: ${{ inputs.number_required_3 }}
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: ls -la
- run: env | grep inputs
- run: echo ${{ inputs.logLevel }}
- run: echo ${{ inputs.boolean_default_false }}
```
![image](https://github.com/go-gitea/gitea/assets/3114995/a58a842d-a0ff-4618-bc6d-83a9596d07c8)
![image](https://github.com/go-gitea/gitea/assets/3114995/44a7cca5-7bd4-42a9-8723-91751a501c88)
---------
Co-authored-by: TKaxv_7S <954067342@qq.com>
Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: Denys Konovalov <kontakt@denyskon.de>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
2024-08-19 04:38:40 +02:00
|
|
|
|
|
|
|
// WorkflowDispatchPayload represents a workflow dispatch payload
|
|
|
|
type WorkflowDispatchPayload struct {
|
|
|
|
Workflow string `json:"workflow"`
|
|
|
|
Ref string `json:"ref"`
|
|
|
|
Inputs map[string]any `json:"inputs"`
|
|
|
|
Repository *Repository `json:"repository"`
|
|
|
|
Sender *User `json:"sender"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// JSONPayload implements Payload
|
|
|
|
func (p *WorkflowDispatchPayload) JSONPayload() ([]byte, error) {
|
|
|
|
return json.MarshalIndent(p, "", " ")
|
|
|
|
}
|
2024-11-07 07:41:49 +01:00
|
|
|
|
|
|
|
// CommitStatusPayload represents a payload information of commit status event.
|
|
|
|
type CommitStatusPayload struct {
|
|
|
|
// TODO: add Branches per https://docs.github.com/en/webhooks/webhook-events-and-payloads#status
|
|
|
|
Commit *PayloadCommit `json:"commit"`
|
|
|
|
Context string `json:"context"`
|
|
|
|
// swagger:strfmt date-time
|
|
|
|
CreatedAt time.Time `json:"created_at"`
|
|
|
|
Description string `json:"description"`
|
|
|
|
ID int64 `json:"id"`
|
|
|
|
Repo *Repository `json:"repository"`
|
|
|
|
Sender *User `json:"sender"`
|
|
|
|
SHA string `json:"sha"`
|
|
|
|
State string `json:"state"`
|
|
|
|
TargetURL string `json:"target_url"`
|
|
|
|
// swagger:strfmt date-time
|
|
|
|
UpdatedAt *time.Time `json:"updated_at"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// JSONPayload implements Payload
|
|
|
|
func (p *CommitStatusPayload) JSONPayload() ([]byte, error) {
|
|
|
|
return json.MarshalIndent(p, "", " ")
|
|
|
|
}
|