Fix compatible for webhook ref type (#25195)
Fix #25185 Caused by #24634
This commit is contained in:
parent
2126f712bf
commit
419804fd4d
|
@ -163,6 +163,7 @@ func (ref RefName) ShortName() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// RefGroup returns the group type of the reference
|
// RefGroup returns the group type of the reference
|
||||||
|
// Using the name of the directory under .git/refs
|
||||||
func (ref RefName) RefGroup() string {
|
func (ref RefName) RefGroup() string {
|
||||||
if ref.IsBranch() {
|
if ref.IsBranch() {
|
||||||
return "heads"
|
return "heads"
|
||||||
|
@ -182,6 +183,19 @@ func (ref RefName) RefGroup() string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RefType returns the simple ref type of the reference, e.g. branch, tag
|
||||||
|
// It's differrent from RefGroup, which is using the name of the directory under .git/refs
|
||||||
|
// Here we using branch but not heads, using tag but not tags
|
||||||
|
func (ref RefName) RefType() string {
|
||||||
|
var refType string
|
||||||
|
if ref.IsBranch() {
|
||||||
|
refType = "branch"
|
||||||
|
} else if ref.IsTag() {
|
||||||
|
refType = "tag"
|
||||||
|
}
|
||||||
|
return refType
|
||||||
|
}
|
||||||
|
|
||||||
// RefURL returns the absolute URL for a ref in a repository
|
// RefURL returns the absolute URL for a ref in a repository
|
||||||
func RefURL(repoURL, ref string) string {
|
func RefURL(repoURL, ref string) string {
|
||||||
refFullName := RefName(ref)
|
refFullName := RefName(ref)
|
||||||
|
|
|
@ -98,8 +98,8 @@ func generateTaskContext(t *actions_model.ActionTask) *structpb.Struct {
|
||||||
baseRef = pullPayload.PullRequest.Base.Ref
|
baseRef = pullPayload.PullRequest.Base.Ref
|
||||||
headRef = pullPayload.PullRequest.Head.Ref
|
headRef = pullPayload.PullRequest.Head.Ref
|
||||||
}
|
}
|
||||||
|
|
||||||
refName := git.RefName(t.Job.Run.Ref)
|
refName := git.RefName(t.Job.Run.Ref)
|
||||||
refType := refName.RefGroup()
|
|
||||||
|
|
||||||
taskContext, err := structpb.NewStruct(map[string]interface{}{
|
taskContext, err := structpb.NewStruct(map[string]interface{}{
|
||||||
// standard contexts, see https://docs.github.com/en/actions/learn-github-actions/contexts#github-context
|
// standard contexts, see https://docs.github.com/en/actions/learn-github-actions/contexts#github-context
|
||||||
|
@ -121,7 +121,7 @@ func generateTaskContext(t *actions_model.ActionTask) *structpb.Struct {
|
||||||
"ref": t.Job.Run.Ref, // string, The fully-formed ref of the branch or tag that triggered the workflow run. For workflows triggered by push, this is the branch or tag ref that was pushed. For workflows triggered by pull_request, this is the pull request merge branch. For workflows triggered by release, this is the release tag created. For other triggers, this is the branch or tag ref that triggered the workflow run. This is only set if a branch or tag is available for the event type. The ref given is fully-formed, meaning that for branches the format is refs/heads/<branch_name>, for pull requests it is refs/pull/<pr_number>/merge, and for tags it is refs/tags/<tag_name>. For example, refs/heads/feature-branch-1.
|
"ref": t.Job.Run.Ref, // string, The fully-formed ref of the branch or tag that triggered the workflow run. For workflows triggered by push, this is the branch or tag ref that was pushed. For workflows triggered by pull_request, this is the pull request merge branch. For workflows triggered by release, this is the release tag created. For other triggers, this is the branch or tag ref that triggered the workflow run. This is only set if a branch or tag is available for the event type. The ref given is fully-formed, meaning that for branches the format is refs/heads/<branch_name>, for pull requests it is refs/pull/<pr_number>/merge, and for tags it is refs/tags/<tag_name>. For example, refs/heads/feature-branch-1.
|
||||||
"ref_name": refName.String(), // string, The short ref name of the branch or tag that triggered the workflow run. This value matches the branch or tag name shown on GitHub. For example, feature-branch-1.
|
"ref_name": refName.String(), // string, The short ref name of the branch or tag that triggered the workflow run. This value matches the branch or tag name shown on GitHub. For example, feature-branch-1.
|
||||||
"ref_protected": false, // boolean, true if branch protections are configured for the ref that triggered the workflow run.
|
"ref_protected": false, // boolean, true if branch protections are configured for the ref that triggered the workflow run.
|
||||||
"ref_type": refType, // string, The type of ref that triggered the workflow run. Valid values are branch or tag.
|
"ref_type": refName.RefType(), // string, The type of ref that triggered the workflow run. Valid values are branch or tag.
|
||||||
"path": "", // string, Path on the runner to the file that sets system PATH variables from workflow commands. This file is unique to the current step and is a different file for each step in a job. For more information, see "Workflow commands for GitHub Actions."
|
"path": "", // string, Path on the runner to the file that sets system PATH variables from workflow commands. This file is unique to the current step and is a different file for each step in a job. For more information, see "Workflow commands for GitHub Actions."
|
||||||
"repository": t.Job.Run.Repo.OwnerName + "/" + t.Job.Run.Repo.Name, // string, The owner and repository name. For example, Codertocat/Hello-World.
|
"repository": t.Job.Run.Repo.OwnerName + "/" + t.Job.Run.Repo.Name, // string, The owner and repository name. For example, Codertocat/Hello-World.
|
||||||
"repository_owner": t.Job.Run.Repo.OwnerName, // string, The repository owner's name. For example, Codertocat.
|
"repository_owner": t.Job.Run.Repo.OwnerName, // string, The repository owner's name. For example, Codertocat.
|
||||||
|
|
|
@ -384,7 +384,7 @@ func (n *actionsNotifier) NotifyCreateRef(ctx context.Context, pusher *user_mode
|
||||||
WithPayload(&api.CreatePayload{
|
WithPayload(&api.CreatePayload{
|
||||||
Ref: refFullName.ShortName(),
|
Ref: refFullName.ShortName(),
|
||||||
Sha: refID,
|
Sha: refID,
|
||||||
RefType: refFullName.RefGroup(),
|
RefType: refFullName.RefType(),
|
||||||
Repo: apiRepo,
|
Repo: apiRepo,
|
||||||
Sender: apiPusher,
|
Sender: apiPusher,
|
||||||
}).
|
}).
|
||||||
|
@ -401,7 +401,7 @@ func (n *actionsNotifier) NotifyDeleteRef(ctx context.Context, pusher *user_mode
|
||||||
WithRef(refFullName.ShortName()). // FIXME: should we use a full ref name
|
WithRef(refFullName.ShortName()). // FIXME: should we use a full ref name
|
||||||
WithPayload(&api.DeletePayload{
|
WithPayload(&api.DeletePayload{
|
||||||
Ref: refFullName.ShortName(),
|
Ref: refFullName.ShortName(),
|
||||||
RefType: refFullName.RefGroup(),
|
RefType: refFullName.RefType(),
|
||||||
PusherType: api.PusherTypeUser,
|
PusherType: api.PusherTypeUser,
|
||||||
Repo: apiRepo,
|
Repo: apiRepo,
|
||||||
Sender: apiPusher,
|
Sender: apiPusher,
|
||||||
|
|
|
@ -755,7 +755,7 @@ func (m *webhookNotifier) NotifyCreateRef(ctx context.Context, pusher *user_mode
|
||||||
if err := PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventCreate, &api.CreatePayload{
|
if err := PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventCreate, &api.CreatePayload{
|
||||||
Ref: refName, // FIXME: should it be a full ref name?
|
Ref: refName, // FIXME: should it be a full ref name?
|
||||||
Sha: refID,
|
Sha: refID,
|
||||||
RefType: refFullName.RefGroup(),
|
RefType: refFullName.RefType(),
|
||||||
Repo: apiRepo,
|
Repo: apiRepo,
|
||||||
Sender: apiPusher,
|
Sender: apiPusher,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
|
@ -791,12 +791,12 @@ func (m *webhookNotifier) NotifyDeleteRef(ctx context.Context, pusher *user_mode
|
||||||
|
|
||||||
if err := PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventDelete, &api.DeletePayload{
|
if err := PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventDelete, &api.DeletePayload{
|
||||||
Ref: refName, // FIXME: should it be a full ref name?
|
Ref: refName, // FIXME: should it be a full ref name?
|
||||||
RefType: refFullName.RefGroup(),
|
RefType: refFullName.RefType(),
|
||||||
PusherType: api.PusherTypeUser,
|
PusherType: api.PusherTypeUser,
|
||||||
Repo: apiRepo,
|
Repo: apiRepo,
|
||||||
Sender: apiPusher,
|
Sender: apiPusher,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
log.Error("PrepareWebhooks.(delete %s): %v", refFullName.RefGroup(), err)
|
log.Error("PrepareWebhooks.(delete %s): %v", refFullName.RefType(), err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue