github

package
v1.9.3-0...-159659e Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: MIT Imports: 17 Imported by: 0

README

github

import "github.com/tagoro9/fotingo/internal/github"

Index

Variables

var ErrAuthRequired = errors.New("github authentication required; run `fotingo login` interactively")

var ErrOAuthClientIDMissing = errors.New("github oauth client id is missing in this build; use `fotingo login` with API token auth or rebuild with oauth ldflags")

func FetchLatestReleaseTag

func FetchLatestReleaseTag(ctx context.Context, client *http.Client, owner string, repo string) (string, error)

FetchLatestReleaseTag fetches the latest release tag for a public repository without requiring authentication.

type CreatePROptions

CreatePROptions contains the options for creating a pull request

type CreatePROptions struct {
    Title string
    Body  string
    Head  string
    Base  string
    Draft bool
}

type CreateReleaseOptions

CreateReleaseOptions contains the options for creating a release

type CreateReleaseOptions struct {
    TagName         string
    TargetCommitish string
    Name            string
    Body            string
    Draft           bool
    Prerelease      bool
}

type Github

type Github interface {
    auth.OauthService
    config.ConfigurableService
    // GetPullRequestUrl returns the URL of the pull request for current branch or an error if it can't be found
    GetPullRequestUrl() (string, error)
    // GetCurrentUser returns the information about the current authenticated user
    GetCurrentUser() (*hub.User, error)
    // CreatePullRequest creates a new pull request
    CreatePullRequest(opts CreatePROptions) (*PullRequest, error)
    // UpdatePullRequest updates an existing pull request
    UpdatePullRequest(prNumber int, opts UpdatePROptions) (*PullRequest, error)
    // GetPullRequestDiscussion returns comments and reviews for an existing pull request
    GetPullRequestDiscussion(prNumber int) (*PullRequestDiscussion, error)
    // GetLabels returns all labels from the repository
    GetLabels() ([]Label, error)
    // AddLabelsToPR adds labels to a pull request
    AddLabelsToPR(prNumber int, labels []string) error
    // GetCollaborators returns repository collaborators for reviewer selection
    GetCollaborators() ([]User, error)
    // GetOrgMembers returns organization members for participant selection
    GetOrgMembers() ([]User, error)
    // GetTeams returns organization teams for team reviewer selection
    GetTeams() ([]Team, error)
    // RequestReviewers requests reviewers on a pull request
    RequestReviewers(prNumber int, reviewers []string, teamReviewers []string) error
    // RemoveReviewers removes pending reviewer requests from a pull request
    RemoveReviewers(prNumber int, reviewers []string, teamReviewers []string) error
    // AssignUsersToPR assigns users to a pull request
    AssignUsersToPR(prNumber int, assignees []string) error
    // RemoveAssigneesFromPR removes users assigned to a pull request
    RemoveAssigneesFromPR(prNumber int, assignees []string) error
    // MarkPullRequestReadyForReview moves a draft pull request to ready for review
    MarkPullRequestReadyForReview(prNodeID string) error
    // DoesPRExistForBranch checks if a PR exists for a given branch
    DoesPRExistForBranch(branch string) (bool, *PullRequest, error)
    // CreateRelease creates a GitHub release
    CreateRelease(opts CreateReleaseOptions) (*Release, error)
}

func New
func New(git git.Git, cfg *viper.Viper) (Github, error)

func NewAuthOnly
func NewAuthOnly(cfg *viper.Viper) (Github, error)

func NewAuthOnlyWithOptions
func NewAuthOnlyWithOptions(cfg *viper.Viper, allowPrompt bool) (Github, error)

func NewWithHTTPClient
func NewWithHTTPClient(g git.Git, cfg *viper.Viper, httpClient *http.Client, baseURL string) (Github, error)

NewWithHTTPClient returns a new GitHub client using the provided HTTP client and base URL. This bypasses OAuth authentication and is intended for testing with mock servers.

func NewWithHTTPClientAndRepo
func NewWithHTTPClientAndRepo(g git.Git, cfg *viper.Viper, httpClient *http.Client, baseURL, owner, repo string) (Github, error)

NewWithHTTPClientAndRepo creates a GitHub client with explicit owner/repo, bypassing remote URL parsing.

func NewWithOptions
func NewWithOptions(git git.Git, cfg *viper.Viper, allowPrompt bool) (Github, error)

type GithubConfig

type GithubConfig struct {
    Token string
}

type Label

Label represents a GitHub label

type Label struct {
    Name        string
    Description string
    Color       string
}

type NativeStackClient

NativeStackClient is implemented by GitHub clients that support native PR stacks.

type NativeStackClient interface {
    ListPullRequestStacks(pullRequestNumber int) ([]PullRequestStack, error)
    CreatePullRequestStack(pullRequestNumbers []int) (*PullRequestStack, error)
    AddPullRequestsToStack(stackNumber int, pullRequestNumbers []int) (*PullRequestStack, error)
}

type PullRequest

PullRequest represents a GitHub pull request

type PullRequest struct {
    Title     string
    Body      string
    Number    int
    NodeID    string
    URL       string
    HTMLURL   string
    HeadRef   string
    HeadSHA   string
    BaseRef   string
    Draft     bool
    State     string
    Merged    bool
    Mergeable *bool
}

type PullRequestBodyUpdate

PullRequestBodyUpdate contains a PR body update for stack synchronization.

type PullRequestBodyUpdate struct {
    Number int
    Body   string
}

type PullRequestConversation

PullRequestConversation groups related inline review comments.

type PullRequestConversation struct {
    ID       string
    Resolved *bool
    Comments []PullRequestReviewComment
}

func GroupPullRequestReviewComments
func GroupPullRequestReviewComments(comments []PullRequestReviewComment) []PullRequestConversation

GroupPullRequestReviewComments groups inline review comments into conversation-like threads.

type PullRequestDiscussion

PullRequestDiscussion contains comments, reviews, and review conversations for a pull request.

type PullRequestDiscussion struct {
    Comments       []PullRequestIssueComment
    Reviews        []PullRequestReview
    ReviewComments []PullRequestReviewComment
    Conversations  []PullRequestConversation
}

type PullRequestIssueComment

PullRequestIssueComment represents a top-level pull request issue comment.

type PullRequestIssueComment struct {
    ID                int64
    Author            string
    Body              string
    URL               string
    HTMLURL           string
    AuthorAssociation string
    CreatedAt         string
    UpdatedAt         string
}

type PullRequestLoader

PullRequestLoader loads complete pull request metadata by number.

type PullRequestLoader interface {
    GetPullRequest(prNumber int) (*PullRequest, error)
}

type PullRequestReview

PullRequestReview represents a submitted pull request review.

type PullRequestReview struct {
    ID                int64
    Author            string
    State             string
    Body              string
    CommitID          string
    URL               string
    HTMLURL           string
    AuthorAssociation string
    SubmittedAt       string
}

type PullRequestReviewComment

PullRequestReviewComment represents an inline pull request review comment.

type PullRequestReviewComment struct {
    ID                   int64
    NodeID               string
    ReviewID             int64
    InReplyToID          int64
    Author               string
    Body                 string
    Path                 string
    DiffHunk             string
    Side                 string
    StartSide            string
    Line                 int
    StartLine            int
    OriginalLine         int
    OriginalStartLine    int
    Position             int
    OriginalPosition     int
    CommitID             string
    OriginalCommitID     string
    SubjectType          string
    URL                  string
    HTMLURL              string
    PullRequestURL       string
    AuthorAssociation    string
    CreatedAt            string
    UpdatedAt            string
    ConversationID       string
    ConversationResolved *bool
}

type PullRequestStack

PullRequestStack contains GitHub-native stack metadata and its ordered PRs.

type PullRequestStack struct {
    ID           int64
    Number       int
    BaseRef      string
    Open         bool
    PullRequests []PullRequest
}

type Release

Release represents a GitHub release

type Release struct {
    ID      int64
    TagName string
    Name    string
    URL     string
    HTMLURL string
}

type Team

Team represents a GitHub organization team.

type Team struct {
    Organization string
    Slug         string
    Name         string
    Description  string
}

func (Team) Canonical
func (t Team) Canonical() string

Canonical returns the canonical team identifier (<org>/<team-slug>).

type UpdatePROptions

UpdatePROptions contains optional fields for editing an existing pull request.

type UpdatePROptions struct {
    Title *string
    Body  *string
}

type User

User represents a GitHub user

type User struct {
    Login string
    Name  string
}

Generated by gomarkdoc

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAuthRequired = errors.New("github authentication required; run `fotingo login` interactively")
View Source
var ErrOAuthClientIDMissing = errors.New("github oauth client id is missing in this build; use `fotingo login` with API token auth or rebuild with oauth ldflags")

Functions

func FetchLatestReleaseTag

func FetchLatestReleaseTag(ctx context.Context, client *http.Client, owner string, repo string) (string, error)

FetchLatestReleaseTag fetches the latest release tag for a public repository without requiring authentication.

Types

type CreatePROptions

type CreatePROptions struct {
	Title string
	Body  string
	Head  string
	Base  string
	Draft bool
}

CreatePROptions contains the options for creating a pull request

type CreateReleaseOptions

type CreateReleaseOptions struct {
	TagName         string
	TargetCommitish string
	Name            string
	Body            string
	Draft           bool
	Prerelease      bool
}

CreateReleaseOptions contains the options for creating a release

type Github

type Github interface {
	auth.OauthService
	config.ConfigurableService
	// GetPullRequestUrl returns the URL of the pull request for current branch or an error if it can't be found
	GetPullRequestUrl() (string, error)
	// GetCurrentUser returns the information about the current authenticated user
	GetCurrentUser() (*hub.User, error)
	// CreatePullRequest creates a new pull request
	CreatePullRequest(opts CreatePROptions) (*PullRequest, error)
	// UpdatePullRequest updates an existing pull request
	UpdatePullRequest(prNumber int, opts UpdatePROptions) (*PullRequest, error)
	// GetPullRequestDiscussion returns comments and reviews for an existing pull request
	GetPullRequestDiscussion(prNumber int) (*PullRequestDiscussion, error)
	// GetLabels returns all labels from the repository
	GetLabels() ([]Label, error)
	// AddLabelsToPR adds labels to a pull request
	AddLabelsToPR(prNumber int, labels []string) error
	// GetCollaborators returns repository collaborators for reviewer selection
	GetCollaborators() ([]User, error)
	// GetOrgMembers returns organization members for participant selection
	GetOrgMembers() ([]User, error)
	// GetTeams returns organization teams for team reviewer selection
	GetTeams() ([]Team, error)
	// RequestReviewers requests reviewers on a pull request
	RequestReviewers(prNumber int, reviewers []string, teamReviewers []string) error
	// RemoveReviewers removes pending reviewer requests from a pull request
	RemoveReviewers(prNumber int, reviewers []string, teamReviewers []string) error
	// AssignUsersToPR assigns users to a pull request
	AssignUsersToPR(prNumber int, assignees []string) error
	// RemoveAssigneesFromPR removes users assigned to a pull request
	RemoveAssigneesFromPR(prNumber int, assignees []string) error
	// MarkPullRequestReadyForReview moves a draft pull request to ready for review
	MarkPullRequestReadyForReview(prNodeID string) error
	// DoesPRExistForBranch checks if a PR exists for a given branch
	DoesPRExistForBranch(branch string) (bool, *PullRequest, error)
	// CreateRelease creates a GitHub release
	CreateRelease(opts CreateReleaseOptions) (*Release, error)
}

func New

func New(git git.Git, cfg *viper.Viper) (Github, error)

func NewAuthOnly

func NewAuthOnly(cfg *viper.Viper) (Github, error)

func NewAuthOnlyWithOptions

func NewAuthOnlyWithOptions(cfg *viper.Viper, allowPrompt bool) (Github, error)

func NewWithHTTPClient

func NewWithHTTPClient(g git.Git, cfg *viper.Viper, httpClient *http.Client, baseURL string) (Github, error)

NewWithHTTPClient returns a new GitHub client using the provided HTTP client and base URL. This bypasses OAuth authentication and is intended for testing with mock servers.

func NewWithHTTPClientAndRepo

func NewWithHTTPClientAndRepo(g git.Git, cfg *viper.Viper, httpClient *http.Client, baseURL, owner, repo string) (Github, error)

NewWithHTTPClientAndRepo creates a GitHub client with explicit owner/repo, bypassing remote URL parsing.

func NewWithOptions

func NewWithOptions(git git.Git, cfg *viper.Viper, allowPrompt bool) (Github, error)

type GithubConfig

type GithubConfig struct {
	Token string
}

type Label

type Label struct {
	Name        string
	Description string
	Color       string
}

Label represents a GitHub label

type NativeStackClient

type NativeStackClient interface {
	ListPullRequestStacks(pullRequestNumber int) ([]PullRequestStack, error)
	CreatePullRequestStack(pullRequestNumbers []int) (*PullRequestStack, error)
	AddPullRequestsToStack(stackNumber int, pullRequestNumbers []int) (*PullRequestStack, error)
}

NativeStackClient is implemented by GitHub clients that support native PR stacks.

type PullRequest

type PullRequest struct {
	Title     string
	Body      string
	Number    int
	NodeID    string
	URL       string
	HTMLURL   string
	HeadRef   string
	HeadSHA   string
	BaseRef   string
	Draft     bool
	State     string
	Merged    bool
	Mergeable *bool
}

PullRequest represents a GitHub pull request

type PullRequestBodyUpdate

type PullRequestBodyUpdate struct {
	Number int
	Body   string
}

PullRequestBodyUpdate contains a PR body update for stack synchronization.

type PullRequestConversation

type PullRequestConversation struct {
	ID       string
	Resolved *bool
	Comments []PullRequestReviewComment
}

PullRequestConversation groups related inline review comments.

func GroupPullRequestReviewComments

func GroupPullRequestReviewComments(comments []PullRequestReviewComment) []PullRequestConversation

GroupPullRequestReviewComments groups inline review comments into conversation-like threads.

type PullRequestDiscussion

type PullRequestDiscussion struct {
	Comments       []PullRequestIssueComment
	Reviews        []PullRequestReview
	ReviewComments []PullRequestReviewComment
	Conversations  []PullRequestConversation
}

PullRequestDiscussion contains comments, reviews, and review conversations for a pull request.

type PullRequestIssueComment

type PullRequestIssueComment struct {
	ID                int64
	Author            string
	Body              string
	URL               string
	HTMLURL           string
	AuthorAssociation string
	CreatedAt         string
	UpdatedAt         string
}

PullRequestIssueComment represents a top-level pull request issue comment.

type PullRequestLoader

type PullRequestLoader interface {
	GetPullRequest(prNumber int) (*PullRequest, error)
}

PullRequestLoader loads complete pull request metadata by number.

type PullRequestReview

type PullRequestReview struct {
	ID                int64
	Author            string
	State             string
	Body              string
	CommitID          string
	URL               string
	HTMLURL           string
	AuthorAssociation string
	SubmittedAt       string
}

PullRequestReview represents a submitted pull request review.

type PullRequestReviewComment

type PullRequestReviewComment struct {
	ID                   int64
	NodeID               string
	ReviewID             int64
	InReplyToID          int64
	Author               string
	Body                 string
	Path                 string
	DiffHunk             string
	Side                 string
	StartSide            string
	Line                 int
	StartLine            int
	OriginalLine         int
	OriginalStartLine    int
	Position             int
	OriginalPosition     int
	CommitID             string
	OriginalCommitID     string
	SubjectType          string
	URL                  string
	HTMLURL              string
	PullRequestURL       string
	AuthorAssociation    string
	CreatedAt            string
	UpdatedAt            string
	ConversationID       string
	ConversationResolved *bool
}

PullRequestReviewComment represents an inline pull request review comment.

type PullRequestStack

type PullRequestStack struct {
	ID           int64
	Number       int
	BaseRef      string
	Open         bool
	PullRequests []PullRequest
}

PullRequestStack contains GitHub-native stack metadata and its ordered PRs.

type Release

type Release struct {
	ID      int64
	TagName string
	Name    string
	URL     string
	HTMLURL string
}

Release represents a GitHub release

type Team

type Team struct {
	Organization string
	Slug         string
	Name         string
	Description  string
}

Team represents a GitHub organization team.

func (Team) Canonical

func (t Team) Canonical() string

Canonical returns the canonical team identifier (<org>/<team-slug>).

type UpdatePROptions

type UpdatePROptions struct {
	Title *string
	Body  *string
}

UpdatePROptions contains optional fields for editing an existing pull request.

type User

type User struct {
	Login string
	Name  string
}

User represents a GitHub user

Directories

Path Synopsis
Package testutil provides mock HTTP server utilities for testing GitHub client code.
Package testutil provides mock HTTP server utilities for testing GitHub client code.

Jump to

Keyboard shortcuts

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