github

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2026 License: MIT Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package github provides GitHub API integration

Index

Constants

View Source
const (
	EventIssues            = "issues"
	EventIssueComment      = "issue_comment"
	EventPullRequest       = "pull_request"
	EventPullRequestReview = "pull_request_review"
	EventPush              = "push"
)

Event types

Variables

This section is empty.

Functions

func FormatEvent

func FormatEvent(e PREvent) string

FormatEvent formats a PREvent for display

func FormatEventNotification added in v0.9.0

func FormatEventNotification(e Event) string

FormatEventNotification formats an event for display

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client wraps the GitHub API client

func NewClient

func NewClient(owner, repo string) (*Client, error)

NewClient creates a new GitHub client

func NewClientWithToken

func NewClientWithToken(owner, repo, token string) *Client

NewClientWithToken creates a client with explicit token

func (*Client) AddLabel added in v0.8.0

func (c *Client) AddLabel(ctx context.Context, number int, label string) error

AddLabel adds a label to an issue

func (*Client) AssignIssue

func (c *Client) AssignIssue(ctx context.Context, number int, assignees []string) error

AssignIssue assigns an issue to users

func (*Client) CloseIssue

func (c *Client) CloseIssue(ctx context.Context, number int) error

CloseIssue closes an issue

func (*Client) CommentIssue

func (c *Client) CommentIssue(ctx context.Context, number int, body string) error

CommentIssue adds a comment to an issue

func (*Client) CreateIssue

func (c *Client) CreateIssue(ctx context.Context, title, body string, labels []string) (*github.Issue, error)

CreateIssue creates a new issue

func (*Client) CreatePR

func (c *Client) CreatePR(ctx context.Context, title, body, head, base string) (*github.PullRequest, error)

CreatePR creates a new pull request

func (*Client) EditIssue added in v0.10.0

func (c *Client) EditIssue(ctx context.Context, number int, title, body *string) (*github.Issue, error)

EditIssue updates an issue's title and/or body

func (*Client) GetIssue

func (c *Client) GetIssue(ctx context.Context, number int) (*github.Issue, error)

GetIssue retrieves an issue by number

func (*Client) GetPR

func (c *Client) GetPR(ctx context.Context, number int) (*github.PullRequest, error)

GetPR retrieves a pull request by number

func (*Client) GetPRFiles

func (c *Client) GetPRFiles(ctx context.Context, number int) ([]*github.CommitFile, error)

GetPRFiles returns files changed in a PR

func (*Client) HasLabel added in v0.8.0

func (c *Client) HasLabel(ctx context.Context, number int, label string) (bool, error)

HasLabel checks if an issue has a specific label

func (*Client) ListIssueComments added in v0.8.0

func (c *Client) ListIssueComments(ctx context.Context, number int) ([]*github.IssueComment, error)

ListIssueComments lists comments on an issue

func (*Client) ListIssueCommentsSince added in v0.8.0

func (c *Client) ListIssueCommentsSince(ctx context.Context, number int, since time.Time) ([]*github.IssueComment, error)

ListIssueCommentsSince lists comments on an issue created after a specific time

func (*Client) ListIssues

func (c *Client) ListIssues(ctx context.Context, labels []string) ([]*github.Issue, error)

ListIssues lists open issues

func (*Client) ListIssuesWithOptions

func (c *Client) ListIssuesWithOptions(ctx context.Context, state, assignee string, labels []string) ([]*github.Issue, error)

ListIssuesWithOptions lists issues with filtering options

func (*Client) ListPRs

func (c *Client) ListPRs(ctx context.Context) ([]*github.PullRequest, error)

ListPRs lists open pull requests

func (*Client) MergePR

func (c *Client) MergePR(ctx context.Context, number int, message string) error

MergePR merges a pull request

func (*Client) RemoveLabel added in v0.8.0

func (c *Client) RemoveLabel(ctx context.Context, number int, label string) error

RemoveLabel removes a label from an issue

func (*Client) ReviewPR

func (c *Client) ReviewPR(ctx context.Context, number int, body string, approve bool) error

ReviewPR submits a review on a PR

type Event added in v0.9.0

type Event struct {
	Type      EventType
	Number    int
	Title     string
	Author    string
	URL       string
	CreatedAt time.Time
	Labels    []string
	Body      string
}

Event represents a new Issue or PR creation event

type EventHandler

type EventHandler func(payload json.RawMessage) error

EventHandler processes a specific event type

type EventType added in v0.9.0

type EventType string

EventType represents the type of GitHub event

const (
	EventTypeIssue EventType = "issue"
	EventTypePR    EventType = "pr"
)

type EventWatcher added in v0.9.0

type EventWatcher struct {
	// contains filtered or unexported fields
}

EventWatcher monitors new Issue/PR creations

func NewEventWatcher added in v0.9.0

func NewEventWatcher(client *Client) *EventWatcher

NewEventWatcher creates a new event watcher

func NewEventWatcherWithSince added in v0.9.0

func NewEventWatcherWithSince(client *Client, since time.Time) *EventWatcher

NewEventWatcherWithSince creates an event watcher with custom start time

func (*EventWatcher) CheckEvents added in v0.9.0

func (w *EventWatcher) CheckEvents(ctx context.Context) ([]Event, error)

CheckEvents fetches new Issue/PR events since last check

func (*EventWatcher) MarkAsSeen added in v0.9.0

func (w *EventWatcher) MarkAsSeen(eventType EventType, number int)

MarkAsSeen marks an event as seen (useful for initialization)

func (*EventWatcher) Reset added in v0.9.0

func (w *EventWatcher) Reset()

Reset clears all seen IDs and resets lastCheck

type IssuesEvent

type IssuesEvent struct {
	Action string `json:"action"`
	Issue  struct {
		Number int    `json:"number"`
		Title  string `json:"title"`
		Body   string `json:"body"`
		State  string `json:"state"`
		User   struct {
			Login string `json:"login"`
		} `json:"user"`
		Labels []struct {
			Name string `json:"name"`
		} `json:"labels"`
		Assignees []struct {
			Login string `json:"login"`
		} `json:"assignees"`
	} `json:"issue"`
	Repository struct {
		FullName string `json:"full_name"`
	} `json:"repository"`
}

IssuesEvent represents an issues event payload

func ParseIssuesEvent

func ParseIssuesEvent(payload json.RawMessage) (*IssuesEvent, error)

ParseIssuesEvent parses an issues event

type PRAction

type PRAction string

PRAction represents the type of PR event

const (
	PRActionMerged PRAction = "merged"
	PRActionClosed PRAction = "closed" // closed without merge (rejected/abandoned)
)

type PREvent

type PREvent struct {
	Number     int
	Title      string
	Author     string
	Action     PRAction
	MergedAt   *time.Time
	ClosedAt   *time.Time
	URL        string
	MergedBy   string
	CreatedAt  time.Time
	HeadBranch string // source branch name (e.g., "feature/xxx")
}

PREvent represents a PR event (merge or close)

type PullRequestEvent

type PullRequestEvent struct {
	Action      string `json:"action"`
	Number      int    `json:"number"`
	PullRequest struct {
		Number int    `json:"number"`
		Title  string `json:"title"`
		Body   string `json:"body"`
		State  string `json:"state"`
		Head   struct {
			Ref string `json:"ref"`
			SHA string `json:"sha"`
		} `json:"head"`
		Base struct {
			Ref string `json:"ref"`
		} `json:"base"`
		User struct {
			Login string `json:"login"`
		} `json:"user"`
	} `json:"pull_request"`
	Repository struct {
		FullName string `json:"full_name"`
	} `json:"repository"`
}

PullRequestEvent represents a pull_request event payload

func ParsePullRequestEvent

func ParsePullRequestEvent(payload json.RawMessage) (*PullRequestEvent, error)

ParsePullRequestEvent parses a pull_request event

type PullRequestReviewEvent

type PullRequestReviewEvent struct {
	Action string `json:"action"`
	Review struct {
		State string `json:"state"`
		Body  string `json:"body"`
		User  struct {
			Login string `json:"login"`
		} `json:"user"`
	} `json:"review"`
	PullRequest struct {
		Number int    `json:"number"`
		Title  string `json:"title"`
	} `json:"pull_request"`
	Repository struct {
		FullName string `json:"full_name"`
	} `json:"repository"`
}

PullRequestReviewEvent represents a pull_request_review event

func ParsePullRequestReviewEvent

func ParsePullRequestReviewEvent(payload json.RawMessage) (*PullRequestReviewEvent, error)

ParsePullRequestReviewEvent parses a pull_request_review event

type Watcher

type Watcher struct {
	// contains filtered or unexported fields
}

Watcher monitors PR events

func NewWatcher

func NewWatcher(client *Client) *Watcher

NewWatcher creates a new PR event watcher

func NewWatcherWithSince

func NewWatcherWithSince(client *Client, since time.Time) *Watcher

NewWatcherWithSince creates a watcher with custom start time

func (*Watcher) CheckEvents

func (w *Watcher) CheckEvents(ctx context.Context) ([]PREvent, error)

CheckEvents fetches recent PR events since last check

func (*Watcher) CheckEventsSince

func (w *Watcher) CheckEventsSince(ctx context.Context, since time.Time) ([]PREvent, error)

CheckEventsSince fetches PR events since a specific time

type WebhookHandler

type WebhookHandler struct {
	// contains filtered or unexported fields
}

WebhookHandler handles GitHub webhook events

func NewWebhookHandler

func NewWebhookHandler(secret string) *WebhookHandler

NewWebhookHandler creates a new webhook handler

func (*WebhookHandler) On

func (h *WebhookHandler) On(event string, handler EventHandler)

On registers a handler for an event type

func (*WebhookHandler) ServeHTTP

func (h *WebhookHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler

Jump to

Keyboard shortcuts

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