github

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: MIT Imports: 14 Imported by: 0

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 FormatCIResult added in v0.13.0

func FormatCIResult(r CIResult) string

FormatCIResult formats a CI result for display

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 CIResult added in v0.13.0

type CIResult struct {
	PRNumber    int
	PRTitle     string
	PRURL       string
	PRAuthor    string
	Status      CIStatus
	TotalChecks int
	Passed      int
	Failed      int
	Pending     int
	Details     []CheckDetail
	CompletedAt time.Time
}

CIResult represents the result of CI check monitoring

type CIStatus added in v0.13.0

type CIStatus string

CIStatus represents the status of CI checks

const (
	CIStatusPending   CIStatus = "pending"
	CIStatusRunning   CIStatus = "running"
	CIStatusSuccess   CIStatus = "success"
	CIStatusFailure   CIStatus = "failure"
	CIStatusCancelled CIStatus = "cancelled"
)

type CIWatcher added in v0.13.0

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

CIWatcher monitors CI status for PRs

func NewCIWatcher added in v0.13.0

func NewCIWatcher(client *Client, config CIWatcherConfig) *CIWatcher

NewCIWatcher creates a new CI watcher

func (*CIWatcher) GetCIStatus added in v0.13.0

func (w *CIWatcher) GetCIStatus(ctx context.Context, prNumber int) (*CIResult, error)

GetCIStatus gets the current CI status for a PR

func (*CIWatcher) IsWatching added in v0.13.0

func (w *CIWatcher) IsWatching(prNumber int) bool

IsWatching returns true if the PR is being watched

func (*CIWatcher) NotifyCh added in v0.13.0

func (w *CIWatcher) NotifyCh() <-chan CIResult

NotifyCh returns the notification channel

func (*CIWatcher) StopWatching added in v0.13.0

func (w *CIWatcher) StopWatching(prNumber int)

StopWatching stops watching a PR

func (*CIWatcher) WatchPR added in v0.13.0

func (w *CIWatcher) WatchPR(ctx context.Context, prNumber int) error

WatchPR starts watching CI status for a PR

func (*CIWatcher) WatchingPRs added in v0.13.0

func (w *CIWatcher) WatchingPRs() []int

WatchingPRs returns the list of PRs being watched

type CIWatcherConfig added in v0.13.0

type CIWatcherConfig struct {
	// PollInterval is the interval between polling
	PollInterval time.Duration
	// Timeout is the maximum time to wait for CI completion
	Timeout time.Duration
}

CIWatcherConfig holds configuration for CI watcher

func DefaultCIWatcherConfig added in v0.13.0

func DefaultCIWatcherConfig() CIWatcherConfig

DefaultCIWatcherConfig returns default configuration

type CheckDetail added in v0.13.0

type CheckDetail struct {
	Name       string
	Status     CIStatus
	Conclusion string
	URL        string
}

CheckDetail represents details of a single check

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) CountOpenIssues added in v0.11.0

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

CountOpenIssues returns the number of open issues Implements the auto.IssueChecker interface

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) GetPRReviewStatus added in v0.13.0

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

GetPRReviewStatus returns the current review status of a PR

func (*Client) GetUnderlyingClient added in v0.12.0

func (c *Client) GetUnderlyingClient() *github.Client

GetUnderlyingClient returns the underlying go-github client

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) ListPRsAwaitingReview added in v0.13.0

func (c *Client) ListPRsAwaitingReview(ctx context.Context) ([]*PRWithReviewStatus, error)

ListPRsAwaitingReview returns PRs that are waiting for review A PR is considered "awaiting review" if: - It has no reviews yet, OR - It has review_requested status (someone was requested to review) PRs with CHANGES_REQUESTED are NOT included (author needs to fix first)

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
	MergedAt  time.Time // Only set for EventTypeMergedPR
	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"
	EventTypeMergedPR EventType = "merged_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 PRReviewStatus added in v0.13.0

type PRReviewStatus string

PRReviewStatus represents the review status of a pull request

const (
	// PRReviewStatusPending means no reviews yet or review requested
	PRReviewStatusPending PRReviewStatus = "PENDING"
	// PRReviewStatusApproved means the PR has been approved
	PRReviewStatusApproved PRReviewStatus = "APPROVED"
	// PRReviewStatusChangesRequested means changes have been requested
	PRReviewStatusChangesRequested PRReviewStatus = "CHANGES_REQUESTED"
)

type PRWithReviewStatus added in v0.13.0

type PRWithReviewStatus struct {
	PR           *github.PullRequest
	ReviewStatus PRReviewStatus
}

PRWithReviewStatus contains a PR and its review status

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