giteabot

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 20, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatCreateMsg

func FormatCreateMsg(ref string, refType string, repo string) string

func FormatDeleteMsg

func FormatDeleteMsg(ref string, refType string, repo string) string

func FormatForkMsg

func FormatForkMsg(original string, newFork string) string

func FormatIssueCommentMsg

func FormatIssueCommentMsg(action gitea.HookIssueCommentAction, username string, issueNum int64, repo string, comment string, issueTitle string, commentURL string) (message string)

func FormatIssueMsg

func FormatIssueMsg(action gitea.HookIssueAction, username string, issueNum int64, repo string, assignee string, title string, issueURL string) (message string)

func FormatPullRequestMsg

func FormatPullRequestMsg(action gitea.HookIssueAction, username string, repo string, prNum int64, title string, sourceBranch string, assignee string, URL string) (message string)

func FormatPushMsg

func FormatPushMsg(username string, repo string, branch string, numCommits int, messages []string, commitURL string) (res string)

Borrowed from https://github.com/keybase/managed-bots/blob/master/base/git/git.go (3dbf0f6)

func FormatReleaseMsg

func FormatReleaseMsg(action gitea.HookReleaseAction, username string, repo string, release string, tag string, tarURL string) (message string)

func FormatRepositoryMsg

func FormatRepositoryMsg(action gitea.HookRepoAction, username string, repo string) (message string)

func ParseWebhook

func ParseWebhook(eventType EventType, payload []byte) (event interface{}, err error)

ParseWebhook parses the event payload. For recognized event types, a value of the corresponding struct type will be returned. An error will be returned for unrecognized event types.

The payloads are defined in Gitea's source at modules/structs/hook.go

https://github.com/go-gitea/gitea/blob/master/modules/structs/hook.go

Example usage:

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
    payload, err := ioutil.ReadAll(r.Body)
    if err != nil { ... }
    event, err := ParseWebhook(EventType(r), payload)
    if err != nil { ... }
    switch event := event.(type) {
    case *gitea.PushPayload:
        processPushEvent(event)
    case *gitea.ForkPayload:
        processForkEvent(event)
    ...
    }
}

Types

type DB

type DB struct {
	*base.DB
}

func NewDB

func NewDB(db *sql.DB) *DB

func (*DB) CreateSubscription

func (d *DB) CreateSubscription(convID chat1.ConvIDStr, repo string, oauthIdentifier string) error

func (*DB) DeleteSubscription

func (d *DB) DeleteSubscription(convID chat1.ConvIDStr, repo string) error

func (*DB) DeleteSubscriptionsForRepo

func (d *DB) DeleteSubscriptionsForRepo(convID chat1.ConvIDStr, repo string) error

func (*DB) GetAllSubscriptionsForConvID

func (d *DB) GetAllSubscriptionsForConvID(convID chat1.ConvIDStr) (res []string, err error)

func (*DB) GetSubscribedConvs

func (d *DB) GetSubscribedConvs(repo string) (res []chat1.ConvIDStr, err error)

func (*DB) GetSubscriptionExists

func (d *DB) GetSubscriptionExists(convID chat1.ConvIDStr, repo string) (exists bool, err error)

func (*DB) GetSubscriptionForRepoExists

func (d *DB) GetSubscriptionForRepoExists(convID chat1.ConvIDStr, repo string) (exists bool, err error)

type EventType

type EventType string

EventType represents a Gitea webhook event

const (
	EventTypeCreate              EventType = "create"
	EventTypeDelete              EventType = "delete"
	EventTypeFork                EventType = "fork"
	EventTypePush                EventType = "push"
	EventTypeIssues              EventType = "issues"
	EventTypeIssueComment        EventType = "issue_comment"
	EventTypeRepository          EventType = "repository"
	EventTypeRelease             EventType = "release"
	EventTypePullRequest         EventType = "pull_request"
	EventTypePullRequestApproved EventType = "pull_request_approved"
	EventTypePullRequestRejected EventType = "pull_request_rejected"
	EventTypePullRequestComment  EventType = "pull_request_comment"
)

List of supported events

Find them in Gitea's source at /models/webhook.go as HookEventType. To correlate with when each of these trigger, see the Trigger On -> Custom Events options when editing a repo's webhook in a Gitea project. Those descriptions are helpful.

func WebhookEventType

func WebhookEventType(r *http.Request) EventType

WebhookEventType returns the event type for the given request.

type HTTPSrv

type HTTPSrv struct {
	*base.HTTPSrv
	// contains filtered or unexported fields
}

func NewHTTPSrv

func NewHTTPSrv(stats *base.StatsRegistry, kbc *kbchat.API, debugConfig *base.ChatDebugOutputConfig,
	db *DB, handler *Handler, secret string) *HTTPSrv

type Handler

type Handler struct {
	*base.DebugOutput
	// contains filtered or unexported fields
}

func NewHandler

func NewHandler(stats *base.StatsRegistry, kbc *kbchat.API, debugConfig *base.ChatDebugOutputConfig,
	db *DB, httpPrefix string, secret string, giteaURL string) *Handler

func (*Handler) HandleCommand

func (h *Handler) HandleCommand(msg chat1.MsgSummary) error

func (*Handler) HandleNewConv

func (h *Handler) HandleNewConv(conv chat1.ConvSummary) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL