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:
parent
4c65c1d8b0
commit
21db670907
@ -11,11 +11,11 @@ import (
|
||||
"code.gitea.io/gitea/models/db"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/models/webhook"
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
webhook_module "code.gitea.io/gitea/modules/webhook"
|
||||
|
||||
"github.com/nektos/act/pkg/jobparser"
|
||||
"golang.org/x/exp/slices"
|
||||
@ -36,7 +36,7 @@ type ActionRun struct {
|
||||
Ref string
|
||||
CommitSHA string
|
||||
IsForkPullRequest bool
|
||||
Event webhook.HookEventType
|
||||
Event webhook_module.HookEventType
|
||||
EventPayload string `xorm:"LONGTEXT"`
|
||||
Status Status `xorm:"index"`
|
||||
Started timeutil.TimeStamp
|
||||
@ -97,7 +97,7 @@ func (run *ActionRun) Duration() time.Duration {
|
||||
}
|
||||
|
||||
func (run *ActionRun) GetPushEventPayload() (*api.PushPayload, error) {
|
||||
if run.Event == webhook.HookEventPush {
|
||||
if run.Event == webhook_module.HookEventPush {
|
||||
var payload api.PushPayload
|
||||
if err := json.Unmarshal([]byte(run.EventPayload), &payload); err != nil {
|
||||
return nil, err
|
||||
|
@ -8,9 +8,9 @@ import (
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/models/webhook"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
webhook_module "code.gitea.io/gitea/modules/webhook"
|
||||
|
||||
"github.com/nektos/act/pkg/model"
|
||||
)
|
||||
@ -41,7 +41,7 @@ func ListWorkflows(commit *git.Commit) (git.Entries, error) {
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -11,8 +11,8 @@ import (
|
||||
"code.gitea.io/gitea/models/db"
|
||||
git_model "code.gitea.io/gitea/models/git"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
webhook_model "code.gitea.io/gitea/models/webhook"
|
||||
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 {
|
||||
@ -21,7 +21,7 @@ func CreateCommitStatus(ctx context.Context, job *actions_model.ActionRunJob) er
|
||||
}
|
||||
|
||||
run := job.Run
|
||||
if run.Event != webhook_model.HookEventPush {
|
||||
if run.Event != webhook_module.HookEventPush {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -13,13 +13,13 @@ import (
|
||||
access_model "code.gitea.io/gitea/models/perm/access"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
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/log"
|
||||
"code.gitea.io/gitea/modules/notification/base"
|
||||
"code.gitea.io/gitea/modules/repository"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
webhook_module "code.gitea.io/gitea/modules/webhook"
|
||||
"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)
|
||||
|
||||
newNotifyInputFromIssue(issue, webhook_model.HookEventIssues).WithPayload(&api.IssuePayload{
|
||||
newNotifyInputFromIssue(issue, webhook_module.HookEventIssues).WithPayload(&api.IssuePayload{
|
||||
Action: api.HookIssueOpened,
|
||||
Index: issue.Index,
|
||||
Issue: convert.ToAPIIssue(ctx, issue),
|
||||
@ -77,7 +77,7 @@ func (n *actionsNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *use
|
||||
} else {
|
||||
apiPullRequest.Action = api.HookIssueReOpened
|
||||
}
|
||||
newNotifyInputFromIssue(issue, webhook_model.HookEventPullRequest).
|
||||
newNotifyInputFromIssue(issue, webhook_module.HookEventPullRequest).
|
||||
WithDoer(doer).
|
||||
WithPayload(apiPullRequest).
|
||||
Notify(ctx)
|
||||
@ -94,7 +94,7 @@ func (n *actionsNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *use
|
||||
} else {
|
||||
apiIssue.Action = api.HookIssueReOpened
|
||||
}
|
||||
newNotifyInputFromIssue(issue, webhook_model.HookEventIssues).
|
||||
newNotifyInputFromIssue(issue, webhook_module.HookEventIssues).
|
||||
WithDoer(doer).
|
||||
WithPayload(apiIssue).
|
||||
Notify(ctx)
|
||||
@ -126,7 +126,7 @@ func (n *actionsNotifier) NotifyIssueChangeLabels(ctx context.Context, doer *use
|
||||
log.Error("LoadIssue: %v", err)
|
||||
return
|
||||
}
|
||||
newNotifyInputFromIssue(issue, webhook_model.HookEventPullRequestLabel).
|
||||
newNotifyInputFromIssue(issue, webhook_module.HookEventPullRequestLabel).
|
||||
WithDoer(doer).
|
||||
WithPayload(&api.PullRequestPayload{
|
||||
Action: api.HookIssueLabelUpdated,
|
||||
@ -138,7 +138,7 @@ func (n *actionsNotifier) NotifyIssueChangeLabels(ctx context.Context, doer *use
|
||||
Notify(ctx)
|
||||
return
|
||||
}
|
||||
newNotifyInputFromIssue(issue, webhook_model.HookEventIssueLabel).
|
||||
newNotifyInputFromIssue(issue, webhook_module.HookEventIssueLabel).
|
||||
WithDoer(doer).
|
||||
WithPayload(&api.IssuePayload{
|
||||
Action: api.HookIssueLabelUpdated,
|
||||
@ -159,7 +159,7 @@ func (n *actionsNotifier) NotifyCreateIssueComment(ctx context.Context, doer *us
|
||||
mode, _ := access_model.AccessLevel(ctx, doer, repo)
|
||||
|
||||
if issue.IsPull {
|
||||
newNotifyInputFromIssue(issue, webhook_model.HookEventPullRequestComment).
|
||||
newNotifyInputFromIssue(issue, webhook_module.HookEventPullRequestComment).
|
||||
WithDoer(doer).
|
||||
WithPayload(&api.IssueCommentPayload{
|
||||
Action: api.HookIssueCommentCreated,
|
||||
@ -172,7 +172,7 @@ func (n *actionsNotifier) NotifyCreateIssueComment(ctx context.Context, doer *us
|
||||
Notify(ctx)
|
||||
return
|
||||
}
|
||||
newNotifyInputFromIssue(issue, webhook_model.HookEventIssueComment).
|
||||
newNotifyInputFromIssue(issue, webhook_module.HookEventIssueComment).
|
||||
WithDoer(doer).
|
||||
WithPayload(&api.IssueCommentPayload{
|
||||
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)
|
||||
|
||||
newNotifyInputFromIssue(pull.Issue, webhook_model.HookEventPullRequest).
|
||||
newNotifyInputFromIssue(pull.Issue, webhook_module.HookEventPullRequest).
|
||||
WithPayload(&api.PullRequestPayload{
|
||||
Action: api.HookIssueOpened,
|
||||
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) {
|
||||
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,
|
||||
Repository: convert.ToRepo(ctx, repo, perm_model.AccessModeOwner),
|
||||
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)
|
||||
|
||||
// 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),
|
||||
Repo: convert.ToRepo(ctx, repo, mode),
|
||||
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.
|
||||
if u.IsOrganization() {
|
||||
newNotifyInput(repo, doer, webhook_model.HookEventRepository).
|
||||
newNotifyInput(repo, doer, webhook_module.HookEventRepository).
|
||||
WithRef(oldRepo.DefaultBranch).
|
||||
WithPayload(&api.RepositoryPayload{
|
||||
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) {
|
||||
ctx = withMethod(ctx, "NotifyPullRequestReview")
|
||||
|
||||
var reviewHookType webhook_model.HookEventType
|
||||
var reviewHookType webhook_module.HookEventType
|
||||
|
||||
switch review.Type {
|
||||
case issues_model.ReviewTypeApprove:
|
||||
reviewHookType = webhook_model.HookEventPullRequestReviewApproved
|
||||
reviewHookType = webhook_module.HookEventPullRequestReviewApproved
|
||||
case issues_model.ReviewTypeComment:
|
||||
reviewHookType = webhook_model.HookEventPullRequestComment
|
||||
reviewHookType = webhook_module.HookEventPullRequestComment
|
||||
case issues_model.ReviewTypeReject:
|
||||
reviewHookType = webhook_model.HookEventPullRequestReviewRejected
|
||||
reviewHookType = webhook_module.HookEventPullRequestReviewRejected
|
||||
default:
|
||||
// unsupported review webhook type here
|
||||
log.Error("Unsupported review webhook type")
|
||||
@ -332,7 +332,7 @@ func (*actionsNotifier) NotifyMergePullRequest(ctx context.Context, doer *user_m
|
||||
Action: api.HookIssueClosed,
|
||||
}
|
||||
|
||||
newNotifyInput(pr.Issue.Repo, doer, webhook_model.HookEventPullRequest).
|
||||
newNotifyInput(pr.Issue.Repo, doer, webhook_module.HookEventPullRequest).
|
||||
WithRef(pr.MergedCommitID).
|
||||
WithPayload(apiPullRequest).
|
||||
WithPullRequest(pr).
|
||||
@ -349,7 +349,7 @@ func (n *actionsNotifier) NotifyPushCommits(ctx context.Context, pusher *user_mo
|
||||
return
|
||||
}
|
||||
|
||||
newNotifyInput(repo, pusher, webhook_model.HookEventPush).
|
||||
newNotifyInput(repo, pusher, webhook_module.HookEventPush).
|
||||
WithRef(opts.RefFullName).
|
||||
WithPayload(&api.PushPayload{
|
||||
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)
|
||||
refName := git.RefEndName(refFullName)
|
||||
|
||||
newNotifyInput(repo, pusher, webhook_model.HookEventCreate).
|
||||
newNotifyInput(repo, pusher, webhook_module.HookEventCreate).
|
||||
WithRef(refName).
|
||||
WithPayload(&api.CreatePayload{
|
||||
Ref: refName,
|
||||
@ -391,7 +391,7 @@ func (n *actionsNotifier) NotifyDeleteRef(ctx context.Context, pusher *user_mode
|
||||
apiRepo := convert.ToRepo(ctx, repo, perm_model.AccessModeNone)
|
||||
refName := git.RefEndName(refFullName)
|
||||
|
||||
newNotifyInput(repo, pusher, webhook_model.HookEventDelete).
|
||||
newNotifyInput(repo, pusher, webhook_module.HookEventDelete).
|
||||
WithRef(refName).
|
||||
WithPayload(&api.DeletePayload{
|
||||
Ref: refName,
|
||||
@ -413,7 +413,7 @@ func (n *actionsNotifier) NotifySyncPushCommits(ctx context.Context, pusher *use
|
||||
return
|
||||
}
|
||||
|
||||
newNotifyInput(repo, pusher, webhook_model.HookEventPush).
|
||||
newNotifyInput(repo, pusher, webhook_module.HookEventPush).
|
||||
WithRef(opts.RefFullName).
|
||||
WithPayload(&api.PushPayload{
|
||||
Ref: opts.RefFullName,
|
||||
@ -483,7 +483,7 @@ func (n *actionsNotifier) NotifyPullRequestSynchronized(ctx context.Context, doe
|
||||
return
|
||||
}
|
||||
|
||||
newNotifyInput(pr.Issue.Repo, doer, webhook_model.HookEventPullRequestSync).
|
||||
newNotifyInput(pr.Issue.Repo, doer, webhook_module.HookEventPullRequestSync).
|
||||
WithPayload(&api.PullRequestPayload{
|
||||
Action: api.HookIssueSynchronized,
|
||||
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)
|
||||
newNotifyInput(pr.Issue.Repo, doer, webhook_model.HookEventPullRequest).
|
||||
newNotifyInput(pr.Issue.Repo, doer, webhook_module.HookEventPullRequest).
|
||||
WithPayload(&api.PullRequestPayload{
|
||||
Action: api.HookIssueEdited,
|
||||
Index: pr.Issue.Index,
|
||||
|
@ -15,12 +15,12 @@ import (
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
unit_model "code.gitea.io/gitea/models/unit"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
webhook_model "code.gitea.io/gitea/models/webhook"
|
||||
actions_module "code.gitea.io/gitea/modules/actions"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
webhook_module "code.gitea.io/gitea/modules/webhook"
|
||||
"code.gitea.io/gitea/services/convert"
|
||||
|
||||
"github.com/nektos/act/pkg/jobparser"
|
||||
@ -56,7 +56,7 @@ type notifyInput struct {
|
||||
// required
|
||||
Repo *repo_model.Repository
|
||||
Doer *user_model.User
|
||||
Event webhook_model.HookEventType
|
||||
Event webhook_module.HookEventType
|
||||
|
||||
// optional
|
||||
Ref string
|
||||
@ -64,7 +64,7 @@ type notifyInput struct {
|
||||
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 ¬ifyInput{
|
||||
Repo: repo,
|
||||
Ref: repo.DefaultBranch,
|
||||
@ -182,7 +182,7 @@ func notify(ctx context.Context, input *notifyInput) error {
|
||||
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)
|
||||
}
|
||||
|
||||
@ -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)
|
||||
|
||||
newNotifyInput(rel.Repo, doer, webhook_model.HookEventRelease).
|
||||
newNotifyInput(rel.Repo, doer, webhook_module.HookEventRelease).
|
||||
WithRef(ref).
|
||||
WithPayload(&api.ReleasePayload{
|
||||
Action: action,
|
||||
@ -219,7 +219,7 @@ func notifyPackage(ctx context.Context, sender *user_model.User, pd *packages_mo
|
||||
return
|
||||
}
|
||||
|
||||
newNotifyInput(pd.Repository, sender, webhook_model.HookEventPackage).
|
||||
newNotifyInput(pd.Repository, sender, webhook_module.HookEventPackage).
|
||||
WithPayload(&api.PackagePayload{
|
||||
Action: action,
|
||||
Package: apiPackage,
|
||||
|
Loading…
Reference in New Issue
Block a user