github

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2026 License: MIT Imports: 13 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

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) 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) 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) 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) ReviewPR

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

ReviewPR submits a review on a PR

type EventHandler

type EventHandler func(payload json.RawMessage) error

EventHandler processes a specific event type

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