github

package
v0.97.8 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package github implements the GitHub adapter for the github capability.

Index

Constants

View Source
const (
	OpGetUser           = "get_user"
	OpGetUserByLogin    = "get_user_by_login"
	OpGetRepo           = "get_repo"
	OpListIssues        = "list_issues"
	OpGetIssue          = "get_issue"
	OpGetCommitDiff     = "get_commit_diff"
	OpGetFileContent    = "get_file_content"
	OpListNotifications = "list_notifications"
	OpListReleases      = "list_releases"
	OpHealth            = "health"
)

Capability is the GitHub capability type constant.

Variables

This section is empty.

Functions

func Register

func Register(app string, svc Service) error

Register registers the github capability with hub and invoker registry. When svc is nil the provider is not configured and registration is skipped.

Types

type Adapter

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

Adapter implements Service using the GitHub provider client.

func (*Adapter) GetCommitDiff

func (a *Adapter) GetCommitDiff(ctx context.Context, owner, repo, commitID string) (*capability.ForgeCommitDiff, error)

GetCommitDiff returns the diff for a specific commit from the GitHub API.

func (*Adapter) GetFileContent

func (a *Adapter) GetFileContent(ctx context.Context, owner, repo, commitID, filePath string, lineStart, lineCount int) ([]byte, error)

GetFileContent returns file content at a specific commit with line range from the GitHub API.

func (*Adapter) GetIssue

func (a *Adapter) GetIssue(ctx context.Context, owner, repo string, index int64) (*capability.ForgeIssue, error)

GetIssue returns a single issue by owner, repo name, and index. Lists issues for the owner and filters by repository name and index.

func (*Adapter) GetRepo

func (a *Adapter) GetRepo(ctx context.Context, owner, repo string) (*capability.ForgeRepo, error)

GetRepo returns a single repository by owner and name from the GitHub API.

func (*Adapter) GetUser

func (a *Adapter) GetUser(ctx context.Context) (*capability.ForgeUser, error)

GetUser returns the authenticated user's profile from the GitHub API.

func (*Adapter) GetUserByLogin

func (a *Adapter) GetUserByLogin(ctx context.Context, login string) (*capability.ForgeUser, error)

GetUserByLogin returns a GitHub user's profile by login name from the GitHub API.

func (*Adapter) HealthCheck

func (a *Adapter) HealthCheck(ctx context.Context) (bool, error)

HealthCheck reports whether the GitHub backend is reachable by querying the authenticated user.

func (*Adapter) ListIssues

ListIssues returns a paginated list of issues for the given owner from the GitHub API.

func (*Adapter) ListNotifications

func (a *Adapter) ListNotifications(ctx context.Context, q *PageQuery) (*capability.ListResult[capability.Notification], error)

ListNotifications returns the authenticated user's notifications from the GitHub API.

func (*Adapter) ListReleases

func (a *Adapter) ListReleases(ctx context.Context, owner, repo string, q *PageQuery) (*capability.ListResult[capability.Release], error)

ListReleases returns releases for a repository from the GitHub API.

func (*Adapter) SetCursorSecret

func (a *Adapter) SetCursorSecret(secret []byte)

SetCursorSecret sets the cursor signing secret (for testing).

type GithubWebhook

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

GithubWebhook implements capability.WebhookConverter for the GitHub provider. It validates HMAC-SHA256 signature and converts GitHub webhook payloads into DataEvent records.

func NewGithubWebhook

func NewGithubWebhook() *GithubWebhook

NewGithubWebhook creates a GithubWebhook that reads the HMAC secret from the github provider config at verification time.

func (*GithubWebhook) Convert

func (*GithubWebhook) Convert(body []byte, headers map[string]string) ([]types.DataEvent, error)

Convert transforms the raw GitHub webhook body into DataEvent records. Event type is determined by the X-GitHub-Event header:

"push"   — emitted as forge.push
"issues" — emitted as forge.issue.<action>

Unsupported event types and actions are logged and yield no events.

func (*GithubWebhook) VerifySignature

func (w *GithubWebhook) VerifySignature(headers map[string]string, body []byte) error

VerifySignature validates the HMAC-SHA256 signature from the X-Hub-Signature-256 header. GitHub signs the raw body with the configured webhook secret using SHA-256, and sends it as "sha256=<hex digest>".

func (*GithubWebhook) WebhookPath

func (*GithubWebhook) WebhookPath() string

WebhookPath returns the URL path that receives webhook events from GitHub. The full URL is /webhook/provider/github/events.

type ListIssuesQuery

type ListIssuesQuery = capability.GithubListIssuesQuery

ListIssuesQuery wraps pagination and filtering for listing issues.

type PageQuery

type PageQuery = capability.GithubPageQuery

PageQuery wraps pagination for list operations.

type Service

type Service interface {
	GetUser(ctx context.Context) (*capability.ForgeUser, error)
	GetUserByLogin(ctx context.Context, login string) (*capability.ForgeUser, error)
	GetRepo(ctx context.Context, owner, repo string) (*capability.ForgeRepo, error)
	ListIssues(ctx context.Context, owner string, q *ListIssuesQuery) (*capability.ListResult[capability.ForgeIssue], error)
	GetIssue(ctx context.Context, owner, repo string, number int64) (*capability.ForgeIssue, error)
	GetCommitDiff(ctx context.Context, owner, repo, commitID string) (*capability.ForgeCommitDiff, error)
	GetFileContent(ctx context.Context, owner, repo, commitID, filePath string, lineStart, lineCount int) ([]byte, error)
	ListNotifications(ctx context.Context, q *PageQuery) (*capability.ListResult[capability.Notification], error)
	ListReleases(ctx context.Context, owner, repo string, q *PageQuery) (*capability.ListResult[capability.Release], error)
	HealthCheck(ctx context.Context) (bool, error)
}

Service defines the GitHub capability contract.

func New

func New() Service

New creates an Adapter using the default provider client.

func NewWithClient

func NewWithClient(c client) Service

NewWithClient creates an Adapter with a specific client, useful for testing.

Jump to

Keyboard shortcuts

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