1
0
mirror of https://github.com/go-gitea/gitea.git synced 2025-02-02 15:09:33 -05:00

fix: use webhook_module

This commit is contained in:
Jason Song 2023-01-06 20:46:36 +08:00
parent 4c65c1d8b0
commit 21db670907
No known key found for this signature in database
GPG Key ID: 8402EEEE4511A8B5
5 changed files with 36 additions and 36 deletions

View File

@ -11,11 +11,11 @@ import (
"code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo" repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/models/webhook"
"code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/json"
api "code.gitea.io/gitea/modules/structs" api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
webhook_module "code.gitea.io/gitea/modules/webhook"
"github.com/nektos/act/pkg/jobparser" "github.com/nektos/act/pkg/jobparser"
"golang.org/x/exp/slices" "golang.org/x/exp/slices"
@ -36,7 +36,7 @@ type ActionRun struct {
Ref string Ref string
CommitSHA string CommitSHA string
IsForkPullRequest bool IsForkPullRequest bool
Event webhook.HookEventType Event webhook_module.HookEventType
EventPayload string `xorm:"LONGTEXT"` EventPayload string `xorm:"LONGTEXT"`
Status Status `xorm:"index"` Status Status `xorm:"index"`
Started timeutil.TimeStamp Started timeutil.TimeStamp
@ -97,7 +97,7 @@ func (run *ActionRun) Duration() time.Duration {
} }
func (run *ActionRun) GetPushEventPayload() (*api.PushPayload, error) { func (run *ActionRun) GetPushEventPayload() (*api.PushPayload, error) {
if run.Event == webhook.HookEventPush { if run.Event == webhook_module.HookEventPush {
var payload api.PushPayload var payload api.PushPayload
if err := json.Unmarshal([]byte(run.EventPayload), &payload); err != nil { if err := json.Unmarshal([]byte(run.EventPayload), &payload); err != nil {
return nil, err return nil, err

View File

@ -8,9 +8,9 @@ import (
"io" "io"
"strings" "strings"
"code.gitea.io/gitea/models/webhook"
"code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
webhook_module "code.gitea.io/gitea/modules/webhook"
"github.com/nektos/act/pkg/model" "github.com/nektos/act/pkg/model"
) )
@ -41,7 +41,7 @@ func ListWorkflows(commit *git.Commit) (git.Entries, error) {
return ret, nil return ret, nil
} }
func DetectWorkflows(commit *git.Commit, event webhook.HookEventType) (map[string][]byte, error) { func DetectWorkflows(commit *git.Commit, event webhook_module.HookEventType) (map[string][]byte, error) {
entries, err := ListWorkflows(commit) entries, err := ListWorkflows(commit)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -11,8 +11,8 @@ import (
"code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/db"
git_model "code.gitea.io/gitea/models/git" git_model "code.gitea.io/gitea/models/git"
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
webhook_model "code.gitea.io/gitea/models/webhook"
api "code.gitea.io/gitea/modules/structs" api "code.gitea.io/gitea/modules/structs"
webhook_module "code.gitea.io/gitea/modules/webhook"
) )
func CreateCommitStatus(ctx context.Context, job *actions_model.ActionRunJob) error { func CreateCommitStatus(ctx context.Context, job *actions_model.ActionRunJob) error {
@ -21,7 +21,7 @@ func CreateCommitStatus(ctx context.Context, job *actions_model.ActionRunJob) er
} }
run := job.Run run := job.Run
if run.Event != webhook_model.HookEventPush { if run.Event != webhook_module.HookEventPush {
return nil return nil
} }

View File

@ -13,13 +13,13 @@ import (
access_model "code.gitea.io/gitea/models/perm/access" access_model "code.gitea.io/gitea/models/perm/access"
repo_model "code.gitea.io/gitea/models/repo" repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
webhook_model "code.gitea.io/gitea/models/webhook"
"code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification/base" "code.gitea.io/gitea/modules/notification/base"
"code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs" api "code.gitea.io/gitea/modules/structs"
webhook_module "code.gitea.io/gitea/modules/webhook"
"code.gitea.io/gitea/services/convert" "code.gitea.io/gitea/services/convert"
) )
@ -47,7 +47,7 @@ func (n *actionsNotifier) NotifyNewIssue(ctx context.Context, issue *issues_mode
} }
mode, _ := access_model.AccessLevel(ctx, issue.Poster, issue.Repo) mode, _ := access_model.AccessLevel(ctx, issue.Poster, issue.Repo)
newNotifyInputFromIssue(issue, webhook_model.HookEventIssues).WithPayload(&api.IssuePayload{ newNotifyInputFromIssue(issue, webhook_module.HookEventIssues).WithPayload(&api.IssuePayload{
Action: api.HookIssueOpened, Action: api.HookIssueOpened,
Index: issue.Index, Index: issue.Index,
Issue: convert.ToAPIIssue(ctx, issue), Issue: convert.ToAPIIssue(ctx, issue),
@ -77,7 +77,7 @@ func (n *actionsNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *use
} else { } else {
apiPullRequest.Action = api.HookIssueReOpened apiPullRequest.Action = api.HookIssueReOpened
} }
newNotifyInputFromIssue(issue, webhook_model.HookEventPullRequest). newNotifyInputFromIssue(issue, webhook_module.HookEventPullRequest).
WithDoer(doer). WithDoer(doer).
WithPayload(apiPullRequest). WithPayload(apiPullRequest).
Notify(ctx) Notify(ctx)
@ -94,7 +94,7 @@ func (n *actionsNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *use
} else { } else {
apiIssue.Action = api.HookIssueReOpened apiIssue.Action = api.HookIssueReOpened
} }
newNotifyInputFromIssue(issue, webhook_model.HookEventIssues). newNotifyInputFromIssue(issue, webhook_module.HookEventIssues).
WithDoer(doer). WithDoer(doer).
WithPayload(apiIssue). WithPayload(apiIssue).
Notify(ctx) Notify(ctx)
@ -126,7 +126,7 @@ func (n *actionsNotifier) NotifyIssueChangeLabels(ctx context.Context, doer *use
log.Error("LoadIssue: %v", err) log.Error("LoadIssue: %v", err)
return return
} }
newNotifyInputFromIssue(issue, webhook_model.HookEventPullRequestLabel). newNotifyInputFromIssue(issue, webhook_module.HookEventPullRequestLabel).
WithDoer(doer). WithDoer(doer).
WithPayload(&api.PullRequestPayload{ WithPayload(&api.PullRequestPayload{
Action: api.HookIssueLabelUpdated, Action: api.HookIssueLabelUpdated,
@ -138,7 +138,7 @@ func (n *actionsNotifier) NotifyIssueChangeLabels(ctx context.Context, doer *use
Notify(ctx) Notify(ctx)
return return
} }
newNotifyInputFromIssue(issue, webhook_model.HookEventIssueLabel). newNotifyInputFromIssue(issue, webhook_module.HookEventIssueLabel).
WithDoer(doer). WithDoer(doer).
WithPayload(&api.IssuePayload{ WithPayload(&api.IssuePayload{
Action: api.HookIssueLabelUpdated, Action: api.HookIssueLabelUpdated,
@ -159,7 +159,7 @@ func (n *actionsNotifier) NotifyCreateIssueComment(ctx context.Context, doer *us
mode, _ := access_model.AccessLevel(ctx, doer, repo) mode, _ := access_model.AccessLevel(ctx, doer, repo)
if issue.IsPull { if issue.IsPull {
newNotifyInputFromIssue(issue, webhook_model.HookEventPullRequestComment). newNotifyInputFromIssue(issue, webhook_module.HookEventPullRequestComment).
WithDoer(doer). WithDoer(doer).
WithPayload(&api.IssueCommentPayload{ WithPayload(&api.IssueCommentPayload{
Action: api.HookIssueCommentCreated, Action: api.HookIssueCommentCreated,
@ -172,7 +172,7 @@ func (n *actionsNotifier) NotifyCreateIssueComment(ctx context.Context, doer *us
Notify(ctx) Notify(ctx)
return return
} }
newNotifyInputFromIssue(issue, webhook_model.HookEventIssueComment). newNotifyInputFromIssue(issue, webhook_module.HookEventIssueComment).
WithDoer(doer). WithDoer(doer).
WithPayload(&api.IssueCommentPayload{ WithPayload(&api.IssueCommentPayload{
Action: api.HookIssueCommentCreated, Action: api.HookIssueCommentCreated,
@ -203,7 +203,7 @@ func (n *actionsNotifier) NotifyNewPullRequest(ctx context.Context, pull *issues
mode, _ := access_model.AccessLevel(ctx, pull.Issue.Poster, pull.Issue.Repo) mode, _ := access_model.AccessLevel(ctx, pull.Issue.Poster, pull.Issue.Repo)
newNotifyInputFromIssue(pull.Issue, webhook_model.HookEventPullRequest). newNotifyInputFromIssue(pull.Issue, webhook_module.HookEventPullRequest).
WithPayload(&api.PullRequestPayload{ WithPayload(&api.PullRequestPayload{
Action: api.HookIssueOpened, Action: api.HookIssueOpened,
Index: pull.Issue.Index, Index: pull.Issue.Index,
@ -218,7 +218,7 @@ func (n *actionsNotifier) NotifyNewPullRequest(ctx context.Context, pull *issues
func (n *actionsNotifier) NotifyCreateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) { func (n *actionsNotifier) NotifyCreateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) {
ctx = withMethod(ctx, "NotifyCreateRepository") ctx = withMethod(ctx, "NotifyCreateRepository")
newNotifyInput(repo, doer, webhook_model.HookEventRepository).WithPayload(&api.RepositoryPayload{ newNotifyInput(repo, doer, webhook_module.HookEventRepository).WithPayload(&api.RepositoryPayload{
Action: api.HookRepoCreated, Action: api.HookRepoCreated,
Repository: convert.ToRepo(ctx, repo, perm_model.AccessModeOwner), Repository: convert.ToRepo(ctx, repo, perm_model.AccessModeOwner),
Organization: convert.ToUser(u, nil), Organization: convert.ToUser(u, nil),
@ -233,7 +233,7 @@ func (n *actionsNotifier) NotifyForkRepository(ctx context.Context, doer *user_m
mode, _ := access_model.AccessLevel(ctx, doer, repo) mode, _ := access_model.AccessLevel(ctx, doer, repo)
// forked webhook // forked webhook
newNotifyInput(oldRepo, doer, webhook_model.HookEventFork).WithPayload(&api.ForkPayload{ newNotifyInput(oldRepo, doer, webhook_module.HookEventFork).WithPayload(&api.ForkPayload{
Forkee: convert.ToRepo(ctx, oldRepo, oldMode), Forkee: convert.ToRepo(ctx, oldRepo, oldMode),
Repo: convert.ToRepo(ctx, repo, mode), Repo: convert.ToRepo(ctx, repo, mode),
Sender: convert.ToUser(doer, nil), Sender: convert.ToUser(doer, nil),
@ -243,7 +243,7 @@ func (n *actionsNotifier) NotifyForkRepository(ctx context.Context, doer *user_m
// Add to hook queue for created repo after session commit. // Add to hook queue for created repo after session commit.
if u.IsOrganization() { if u.IsOrganization() {
newNotifyInput(repo, doer, webhook_model.HookEventRepository). newNotifyInput(repo, doer, webhook_module.HookEventRepository).
WithRef(oldRepo.DefaultBranch). WithRef(oldRepo.DefaultBranch).
WithPayload(&api.RepositoryPayload{ WithPayload(&api.RepositoryPayload{
Action: api.HookRepoCreated, Action: api.HookRepoCreated,
@ -257,15 +257,15 @@ func (n *actionsNotifier) NotifyForkRepository(ctx context.Context, doer *user_m
func (n *actionsNotifier) NotifyPullRequestReview(ctx context.Context, pr *issues_model.PullRequest, review *issues_model.Review, _ *issues_model.Comment, _ []*user_model.User) { func (n *actionsNotifier) NotifyPullRequestReview(ctx context.Context, pr *issues_model.PullRequest, review *issues_model.Review, _ *issues_model.Comment, _ []*user_model.User) {
ctx = withMethod(ctx, "NotifyPullRequestReview") ctx = withMethod(ctx, "NotifyPullRequestReview")
var reviewHookType webhook_model.HookEventType var reviewHookType webhook_module.HookEventType
switch review.Type { switch review.Type {
case issues_model.ReviewTypeApprove: case issues_model.ReviewTypeApprove:
reviewHookType = webhook_model.HookEventPullRequestReviewApproved reviewHookType = webhook_module.HookEventPullRequestReviewApproved
case issues_model.ReviewTypeComment: case issues_model.ReviewTypeComment:
reviewHookType = webhook_model.HookEventPullRequestComment reviewHookType = webhook_module.HookEventPullRequestComment
case issues_model.ReviewTypeReject: case issues_model.ReviewTypeReject:
reviewHookType = webhook_model.HookEventPullRequestReviewRejected reviewHookType = webhook_module.HookEventPullRequestReviewRejected
default: default:
// unsupported review webhook type here // unsupported review webhook type here
log.Error("Unsupported review webhook type") log.Error("Unsupported review webhook type")
@ -332,7 +332,7 @@ func (*actionsNotifier) NotifyMergePullRequest(ctx context.Context, doer *user_m
Action: api.HookIssueClosed, Action: api.HookIssueClosed,
} }
newNotifyInput(pr.Issue.Repo, doer, webhook_model.HookEventPullRequest). newNotifyInput(pr.Issue.Repo, doer, webhook_module.HookEventPullRequest).
WithRef(pr.MergedCommitID). WithRef(pr.MergedCommitID).
WithPayload(apiPullRequest). WithPayload(apiPullRequest).
WithPullRequest(pr). WithPullRequest(pr).
@ -349,7 +349,7 @@ func (n *actionsNotifier) NotifyPushCommits(ctx context.Context, pusher *user_mo
return return
} }
newNotifyInput(repo, pusher, webhook_model.HookEventPush). newNotifyInput(repo, pusher, webhook_module.HookEventPush).
WithRef(opts.RefFullName). WithRef(opts.RefFullName).
WithPayload(&api.PushPayload{ WithPayload(&api.PushPayload{
Ref: opts.RefFullName, Ref: opts.RefFullName,
@ -372,7 +372,7 @@ func (n *actionsNotifier) NotifyCreateRef(ctx context.Context, pusher *user_mode
apiRepo := convert.ToRepo(ctx, repo, perm_model.AccessModeNone) apiRepo := convert.ToRepo(ctx, repo, perm_model.AccessModeNone)
refName := git.RefEndName(refFullName) refName := git.RefEndName(refFullName)
newNotifyInput(repo, pusher, webhook_model.HookEventCreate). newNotifyInput(repo, pusher, webhook_module.HookEventCreate).
WithRef(refName). WithRef(refName).
WithPayload(&api.CreatePayload{ WithPayload(&api.CreatePayload{
Ref: refName, Ref: refName,
@ -391,7 +391,7 @@ func (n *actionsNotifier) NotifyDeleteRef(ctx context.Context, pusher *user_mode
apiRepo := convert.ToRepo(ctx, repo, perm_model.AccessModeNone) apiRepo := convert.ToRepo(ctx, repo, perm_model.AccessModeNone)
refName := git.RefEndName(refFullName) refName := git.RefEndName(refFullName)
newNotifyInput(repo, pusher, webhook_model.HookEventDelete). newNotifyInput(repo, pusher, webhook_module.HookEventDelete).
WithRef(refName). WithRef(refName).
WithPayload(&api.DeletePayload{ WithPayload(&api.DeletePayload{
Ref: refName, Ref: refName,
@ -413,7 +413,7 @@ func (n *actionsNotifier) NotifySyncPushCommits(ctx context.Context, pusher *use
return return
} }
newNotifyInput(repo, pusher, webhook_model.HookEventPush). newNotifyInput(repo, pusher, webhook_module.HookEventPush).
WithRef(opts.RefFullName). WithRef(opts.RefFullName).
WithPayload(&api.PushPayload{ WithPayload(&api.PushPayload{
Ref: opts.RefFullName, Ref: opts.RefFullName,
@ -483,7 +483,7 @@ func (n *actionsNotifier) NotifyPullRequestSynchronized(ctx context.Context, doe
return return
} }
newNotifyInput(pr.Issue.Repo, doer, webhook_model.HookEventPullRequestSync). newNotifyInput(pr.Issue.Repo, doer, webhook_module.HookEventPullRequestSync).
WithPayload(&api.PullRequestPayload{ WithPayload(&api.PullRequestPayload{
Action: api.HookIssueSynchronized, Action: api.HookIssueSynchronized,
Index: pr.Issue.Index, Index: pr.Issue.Index,
@ -509,7 +509,7 @@ func (n *actionsNotifier) NotifyPullRequestChangeTargetBranch(ctx context.Contex
} }
mode, _ := access_model.AccessLevel(ctx, pr.Issue.Poster, pr.Issue.Repo) mode, _ := access_model.AccessLevel(ctx, pr.Issue.Poster, pr.Issue.Repo)
newNotifyInput(pr.Issue.Repo, doer, webhook_model.HookEventPullRequest). newNotifyInput(pr.Issue.Repo, doer, webhook_module.HookEventPullRequest).
WithPayload(&api.PullRequestPayload{ WithPayload(&api.PullRequestPayload{
Action: api.HookIssueEdited, Action: api.HookIssueEdited,
Index: pr.Issue.Index, Index: pr.Issue.Index,

View File

@ -15,12 +15,12 @@ import (
repo_model "code.gitea.io/gitea/models/repo" repo_model "code.gitea.io/gitea/models/repo"
unit_model "code.gitea.io/gitea/models/unit" unit_model "code.gitea.io/gitea/models/unit"
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
webhook_model "code.gitea.io/gitea/models/webhook"
actions_module "code.gitea.io/gitea/modules/actions" actions_module "code.gitea.io/gitea/modules/actions"
"code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
api "code.gitea.io/gitea/modules/structs" api "code.gitea.io/gitea/modules/structs"
webhook_module "code.gitea.io/gitea/modules/webhook"
"code.gitea.io/gitea/services/convert" "code.gitea.io/gitea/services/convert"
"github.com/nektos/act/pkg/jobparser" "github.com/nektos/act/pkg/jobparser"
@ -56,7 +56,7 @@ type notifyInput struct {
// required // required
Repo *repo_model.Repository Repo *repo_model.Repository
Doer *user_model.User Doer *user_model.User
Event webhook_model.HookEventType Event webhook_module.HookEventType
// optional // optional
Ref string Ref string
@ -64,7 +64,7 @@ type notifyInput struct {
PullRequest *issues_model.PullRequest PullRequest *issues_model.PullRequest
} }
func newNotifyInput(repo *repo_model.Repository, doer *user_model.User, event webhook_model.HookEventType) *notifyInput { func newNotifyInput(repo *repo_model.Repository, doer *user_model.User, event webhook_module.HookEventType) *notifyInput {
return &notifyInput{ return &notifyInput{
Repo: repo, Repo: repo,
Ref: repo.DefaultBranch, Ref: repo.DefaultBranch,
@ -182,7 +182,7 @@ func notify(ctx context.Context, input *notifyInput) error {
return nil return nil
} }
func newNotifyInputFromIssue(issue *issues_model.Issue, event webhook_model.HookEventType) *notifyInput { func newNotifyInputFromIssue(issue *issues_model.Issue, event webhook_module.HookEventType) *notifyInput {
return newNotifyInput(issue.Repo, issue.Poster, event) return newNotifyInput(issue.Repo, issue.Poster, event)
} }
@ -194,7 +194,7 @@ func notifyRelease(ctx context.Context, doer *user_model.User, rel *repo_model.R
mode, _ := access_model.AccessLevel(ctx, doer, rel.Repo) mode, _ := access_model.AccessLevel(ctx, doer, rel.Repo)
newNotifyInput(rel.Repo, doer, webhook_model.HookEventRelease). newNotifyInput(rel.Repo, doer, webhook_module.HookEventRelease).
WithRef(ref). WithRef(ref).
WithPayload(&api.ReleasePayload{ WithPayload(&api.ReleasePayload{
Action: action, Action: action,
@ -219,7 +219,7 @@ func notifyPackage(ctx context.Context, sender *user_model.User, pd *packages_mo
return return
} }
newNotifyInput(pd.Repository, sender, webhook_model.HookEventPackage). newNotifyInput(pd.Repository, sender, webhook_module.HookEventPackage).
WithPayload(&api.PackagePayload{ WithPayload(&api.PackagePayload{
Action: action, Action: action,
Package: apiPackage, Package: apiPackage,