代码拉取完成,页面将自动刷新
before
annotation for push and checksuite
package handler
import (
"errors"
"github.com/google/go-github/v24/github"
)
var (
ErrEventNotSupported = errors.New("Event not supported")
ErrEventInvalid = errors.New("Not a valid event")
)
type Event struct {
Type string
Action string
Revision string
Ref string
Before string
*github.Repository
}
func (e *Event) Annotations() map[string]string {
return map[string]string{
annotationPrefix + "event_type": e.Type,
annotationPrefix + "event_action": e.Action,
annotationPrefix + "repo_name": *e.Repository.FullName,
annotationPrefix + "repo_url": *e.Repository.GitURL,
annotationPrefix + "repo_ssh": *e.Repository.SSHURL,
annotationPrefix + "ref": e.Ref,
annotationPrefix + "revision": e.Revision,
annotationPrefix + "before": e.Before,
}
}
func ParseEvent(ev interface{}) (*Event, error) {
event := &Event{}
switch e := ev.(type) {
case *github.PushEvent:
event.Type = "push"
event.Repository = pushEventRepoToRepo(e.GetRepo())
event.Revision = *e.After
event.Ref = *e.Ref
event.Before = *e.Before
case *github.DeleteEvent:
event.Type = "delete"
event.Repository = e.GetRepo()
event.Ref = formatRef(*e.RefType, *e.Ref)
case *github.CheckRunEvent:
event.Type = "check_run"
event.Action = *e.Action
event.Repository = e.GetRepo()
event.Revision = *e.CheckRun.HeadSHA
event.Ref = branchToRef(*e.CheckRun.CheckSuite.HeadBranch)
case *github.CheckSuiteEvent:
event.Type = "check_suite"
event.Action = *e.Action
event.Repository = e.GetRepo()
event.Revision = *e.CheckSuite.AfterSHA
event.Before = *e.CheckSuite.BeforeSHA
event.Ref = branchToRef(*e.CheckSuite.HeadBranch)
}
return event, nil
}
func formatRef(refType, ref string) string {
if refType == "branch" {
refType = "head"
}
return "refs/" + refType + "s/" + ref
}
func branchToRef(branch string) string {
return "refs/heads/" + branch
}
// FIXME: We should translate all fields or clean that mess up at upstream.
func pushEventRepoToRepo(r *github.PushEventRepository) *github.Repository {
return &github.Repository{
FullName: r.FullName,
GitURL: r.GitURL,
SSHURL: r.SSHURL,
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。