2016-11-07 21:53:13 +08:00
|
|
|
// Copyright 2014 The Gogs Authors. All rights reserved.
|
2017-02-23 07:53:33 +08:00
|
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
2022-11-28 02:20:29 +08:00
|
|
|
// SPDX-License-Identifier: MIT
|
2016-11-07 21:53:13 +08:00
|
|
|
|
2019-05-11 18:21:34 +08:00
|
|
|
package structs
|
2016-11-07 21:53:13 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"strings"
|
|
|
|
"time"
|
2021-03-02 05:08:10 +08:00
|
|
|
|
2021-07-25 00:03:58 +08:00
|
|
|
"code.gitea.io/gitea/modules/json"
|
2016-11-07 21:53:13 +08:00
|
|
|
)
|
|
|
|
|
2022-01-21 01:46:10 +08:00
|
|
|
// ErrInvalidReceiveHook FIXME
|
|
|
|
var ErrInvalidReceiveHook = errors.New("Invalid JSON payload received over webhook")
|
2016-11-07 21:53:13 +08:00
|
|
|
|
2016-11-29 16:09:17 +08:00
|
|
|
// Hook a hook is a web hook when one repository changed
|
2016-11-07 21:53:13 +08:00
|
|
|
type Hook struct {
|
2022-11-04 02:23:20 +08:00
|
|
|
ID int64 `json:"id"`
|
|
|
|
Type string `json:"type"`
|
2023-08-21 19:43:52 +08:00
|
|
|
BranchFilter string `json:"branch_filter"`
|
2022-11-04 02:23:20 +08: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 15:02:25 +08:00
|
|
|
// swagger:strfmt date-time
|
2018-03-06 09:22:16 +08:00
|
|
|
Updated time.Time `json:"updated_at"`
|
2017-11-13 15:02:25 +08:00
|
|
|
// swagger:strfmt date-time
|
2018-03-06 09:22:16 +08:00
|
|
|
Created time.Time `json:"created_at"`
|
2016-11-07 21:53:13 +08:00
|
|
|
}
|
|
|
|
|
2017-08-21 19:13:47 +08:00
|
|
|
// HookList represents a list of API hook.
|
|
|
|
type HookList []*Hook
|
|
|
|
|
2019-12-31 12:11:15 +08:00
|
|
|
// CreateHookOptionConfig has all config options in it
|
|
|
|
// required are "content_type" and "url" Required
|
|
|
|
type CreateHookOptionConfig map[string]string
|
|
|
|
|
2016-11-29 16:09:17 +08:00
|
|
|
// CreateHookOption options when create a hook
|
2016-11-07 21:53:13 +08:00
|
|
|
type CreateHookOption struct {
|
2017-11-13 15:02:25 +08:00
|
|
|
// required: true
|
2022-01-23 21:46:30 +08:00
|
|
|
// enum: dingtalk,discord,gitea,gogs,msteams,slack,telegram,feishu,wechatwork,packagist
|
2017-08-21 19:13:47 +08:00
|
|
|
Type string `json:"type" binding:"Required"`
|
2017-11-13 15:02:25 +08:00
|
|
|
// required: true
|
2022-11-04 02:23:20 +08: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 15:02:25 +08:00
|
|
|
// default: false
|
2017-08-21 19:13:47 +08:00
|
|
|
Active bool `json:"active"`
|
2016-11-07 21:53:13 +08:00
|
|
|
}
|
|
|
|
|
2016-11-29 16:09:17 +08:00
|
|
|
// EditHookOption options when modify one hook
|
2016-11-07 21:53:13 +08:00
|
|
|
type EditHookOption struct {
|
2022-11-04 02:23:20 +08: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 21:53:13 +08:00
|
|
|
}
|
|
|
|
|
2016-11-29 16:09:17 +08:00
|
|
|
// Payloader payload is some part of one hook
|
2016-11-07 21:53:13 +08:00
|
|
|
type Payloader interface {
|
|
|
|
JSONPayload() ([]byte, error)
|
|
|
|
}
|
|
|
|
|
2017-11-13 15:02:25 +08:00
|
|
|
// PayloadUser represents the author or committer of a commit
|
2016-11-07 21:53:13 +08:00
|
|
|
type PayloadUser struct {
|
2017-11-13 15:02:25 +08:00
|
|
|
// Full name of the commit author
|
2018-03-06 09:22:16 +08:00
|
|
|
Name string `json:"name"`
|
2017-11-13 15:02:25 +08:00
|
|
|
// swagger:strfmt email
|
2016-11-07 21:53:13 +08:00
|
|
|
Email string `json:"email"`
|
|
|
|
UserName string `json:"username"`
|
|
|
|
}
|
|
|
|
|
2017-11-13 15:02:25 +08: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 21:53:13 +08:00
|
|
|
type PayloadCommit struct {
|
2017-11-13 15:02:25 +08:00
|
|
|
// sha1 hash of the commit
|
2017-03-22 18:43:54 +08: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 15:02:25 +08:00
|
|
|
// swagger:strfmt date-time
|
2018-03-06 09:22:16 +08:00
|
|
|
Timestamp time.Time `json:"timestamp"`
|
2019-01-31 00:33:00 +08:00
|
|
|
Added []string `json:"added"`
|
|
|
|
Removed []string `json:"removed"`
|
|
|
|
Modified []string `json:"modified"`
|
2017-03-22 18:43:54 +08:00
|
|
|
}
|
|
|
|
|
2017-11-13 15:02:25 +08:00
|
|
|
// PayloadCommitVerification represents the GPG verification of a commit
|
2017-03-22 18:43:54 +08:00
|
|
|
type PayloadCommitVerification struct {
|
2019-10-16 21:42:42 +08:00
|
|
|
Verified bool `json:"verified"`
|
|
|
|
Reason string `json:"reason"`
|
|
|
|
Signature string `json:"signature"`
|
|
|
|
Signer *PayloadUser `json:"signer"`
|
|
|
|
Payload string `json:"payload"`
|
2016-11-07 21:53:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
_ Payloader = &CreatePayload{}
|
2018-05-16 22:01:55 +08:00
|
|
|
_ Payloader = &DeletePayload{}
|
|
|
|
_ Payloader = &ForkPayload{}
|
2016-11-07 21:53:13 +08:00
|
|
|
_ Payloader = &PushPayload{}
|
2017-02-23 07:53:33 +08:00
|
|
|
_ Payloader = &IssuePayload{}
|
2018-05-16 22:01:55 +08:00
|
|
|
_ Payloader = &IssueCommentPayload{}
|
2016-11-07 21:53:13 +08:00
|
|
|
_ Payloader = &PullRequestPayload{}
|
2018-05-16 22:01:55 +08:00
|
|
|
_ Payloader = &RepositoryPayload{}
|
|
|
|
_ Payloader = &ReleasePayload{}
|
2022-03-30 16:42:47 +08:00
|
|
|
_ Payloader = &PackagePayload{}
|
2016-11-07 21:53:13 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// _________ __
|
|
|
|
// \_ ___ \_______ ____ _____ _/ |_ ____
|
|
|
|
// / \ \/\_ __ \_/ __ \\__ \\ __\/ __ \
|
|
|
|
// \ \____| | \/\ ___/ / __ \| | \ ___/
|
|
|
|
// \______ /|__| \___ >____ /__| \___ >
|
|
|
|
// \/ \/ \/ \/
|
|
|
|
|
2016-11-29 16:09:17 +08:00
|
|
|
// CreatePayload FIXME
|
2016-11-07 21:53:13 +08:00
|
|
|
type CreatePayload struct {
|
2016-11-29 16:09:17 +08:00
|
|
|
Sha string `json:"sha"`
|
2016-11-07 21:53:13 +08:00
|
|
|
Ref string `json:"ref"`
|
|
|
|
RefType string `json:"ref_type"`
|
|
|
|
Repo *Repository `json:"repository"`
|
|
|
|
Sender *User `json:"sender"`
|
|
|
|
}
|
|
|
|
|
2016-11-29 16:09:17 +08:00
|
|
|
// JSONPayload return payload information
|
2016-11-07 21:53:13 +08: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 22:01:55 +08: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 17:10:05 +08: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 22:01:55 +08: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 10:28:29 +08:00
|
|
|
HookReleaseUpdated HookReleaseAction = "updated"
|
|
|
|
HookReleaseDeleted HookReleaseAction = "deleted"
|
2018-05-16 22:01:55 +08: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 21:53:13 +08:00
|
|
|
// __________ .__
|
|
|
|
// \______ \__ __ _____| |__
|
|
|
|
// | ___/ | \/ ___/ | \
|
|
|
|
// | | | | /\___ \| Y \
|
|
|
|
// |____| |____//____ >___| /
|
|
|
|
// \/ \/
|
|
|
|
|
|
|
|
// PushPayload represents a payload information of push event.
|
|
|
|
type PushPayload struct {
|
2022-10-17 00:22:34 +08: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 21:53:13 +08:00
|
|
|
}
|
|
|
|
|
2016-11-29 16:09:17 +08:00
|
|
|
// JSONPayload FIXME
|
2016-11-07 21:53:13 +08: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-12 04:27:20 +08:00
|
|
|
return strings.ReplaceAll(p.Ref, "refs/heads/", "")
|
2016-11-07 21:53:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// .___
|
|
|
|
// | | ______ ________ __ ____
|
|
|
|
// | |/ ___// ___/ | \_/ __ \
|
|
|
|
// | |\___ \ \___ \| | /\ ___/
|
|
|
|
// |___/____ >____ >____/ \___ >
|
|
|
|
// \/ \/ \/
|
|
|
|
|
2016-11-29 16:09:17 +08:00
|
|
|
// HookIssueAction FIXME
|
2016-11-07 21:53:13 +08:00
|
|
|
type HookIssueAction string
|
|
|
|
|
|
|
|
const (
|
2016-11-29 16:09:17 +08: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 23:37:32 +08:00
|
|
|
HookIssueLabelUpdated HookIssueAction = "label_updated"
|
2016-11-29 16:09:17 +08:00
|
|
|
// HookIssueLabelCleared label_cleared
|
2016-11-07 23:37:32 +08:00
|
|
|
HookIssueLabelCleared HookIssueAction = "label_cleared"
|
2016-11-29 16:09:17 +08:00
|
|
|
// HookIssueSynchronized synchronized
|
|
|
|
HookIssueSynchronized HookIssueAction = "synchronized"
|
2017-02-23 07:53:33 +08: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 13:10:48 +08:00
|
|
|
// HookIssueReviewed is an issue action for when a pull request is reviewed
|
|
|
|
HookIssueReviewed HookIssueAction = "reviewed"
|
2023-05-25 10:06:27 +08: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 21:53:13 +08:00
|
|
|
)
|
|
|
|
|
2017-02-23 07:53:33 +08: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 12:47:53 +08:00
|
|
|
CommitID string `json:"commit_id"`
|
2017-02-23 07:53:33 +08: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 16:09:17 +08:00
|
|
|
// ChangesFromPayload FIXME
|
2016-11-07 21:53:13 +08:00
|
|
|
type ChangesFromPayload struct {
|
|
|
|
From string `json:"from"`
|
|
|
|
}
|
|
|
|
|
2019-12-16 14:20:25 +08:00
|
|
|
// ChangesPayload represents the payload information of issue change
|
2016-11-07 21:53:13 +08:00
|
|
|
type ChangesPayload struct {
|
|
|
|
Title *ChangesFromPayload `json:"title,omitempty"`
|
|
|
|
Body *ChangesFromPayload `json:"body,omitempty"`
|
2019-12-16 14:20:25 +08:00
|
|
|
Ref *ChangesFromPayload `json:"ref,omitempty"`
|
2016-11-07 21:53:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// __________ .__ .__ __________ __
|
|
|
|
// \______ \__ __| | | | \______ \ ____ ________ __ ____ _______/ |_
|
|
|
|
// | ___/ | \ | | | | _// __ \/ ____/ | \_/ __ \ / ___/\ __\
|
|
|
|
// | | | | / |_| |__ | | \ ___< <_| | | /\ ___/ \___ \ | |
|
|
|
|
// |____| |____/|____/____/ |____|_ /\___ >__ |____/ \___ >____ > |__|
|
|
|
|
// \/ \/ |__| \/ \/
|
|
|
|
|
|
|
|
// PullRequestPayload represents a payload information of pull request event.
|
|
|
|
type PullRequestPayload struct {
|
2023-05-25 10:06:27 +08: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 21:53:13 +08:00
|
|
|
}
|
|
|
|
|
2016-11-29 16:09:17 +08:00
|
|
|
// JSONPayload FIXME
|
2016-11-07 21:53:13 +08:00
|
|
|
func (p *PullRequestPayload) JSONPayload() ([]byte, error) {
|
|
|
|
return json.MarshalIndent(p, "", " ")
|
|
|
|
}
|
2017-05-05 10:55:54 +08:00
|
|
|
|
2019-10-19 06:42:04 +08:00
|
|
|
// ReviewPayload FIXME
|
|
|
|
type ReviewPayload struct {
|
|
|
|
Type string `json:"type"`
|
|
|
|
Content string `json:"content"`
|
|
|
|
}
|
|
|
|
|
2022-09-05 03:54:23 +08: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 10:55:54 +08: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 16:42:47 +08: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 10:38:40 +08: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, "", " ")
|
|
|
|
}
|