github

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: BSD-3-Clause, MIT Imports: 8 Imported by: 0

Documentation

Overview

Package github defines provider-neutral GitHub identities, models, enums, normalization rules, and URL parsing shared across the app. Keep `gh` CLI behavior, REST or GraphQL transport, and command formatting out.

Index

Constants

View Source
const (
	NotificationSubjectTypePullRequest = "PullRequest"
	NotificationSubjectTypeIssue       = "Issue"
	NotificationSubjectTypeRelease     = "Release"
)
View Source
const (
	ReviewEventComment        ReviewEvent = "COMMENT"
	ReviewEventApprove        ReviewEvent = "APPROVE"
	ReviewEventRequestChanges ReviewEvent = "REQUEST_CHANGES"

	PullRequestReviewEventComment        PullRequestReviewEvent = ReviewEventComment
	PullRequestReviewEventApprove        PullRequestReviewEvent = ReviewEventApprove
	PullRequestReviewEventRequestChanges PullRequestReviewEvent = ReviewEventRequestChanges
)

Variables

View Source
var (
	ErrMissingPullRequestBuildLink    = errors.New("missing pull request build link")
	ErrInvalidPullRequestBuildLink    = errors.New("invalid pull request build link")
	ErrPullRequestBuildRunJobNotFound = errors.New("pull request build run job not found")
)
View Source
var (
	ErrUnavailable        = errors.New("gh is unavailable")
	ErrUnauthenticated    = errors.New("gh is not authenticated")
	ErrEmptyConnectedUser = errors.New("empty connected user response")
)
View Source
var (
	ErrInvalidPullRequestURL      = errors.New("invalid GitHub pull request URL")
	ErrMissingPullRequestIdentity = errors.New("missing pull request identity")
)
View Source
var (
	ErrInvalidReviewEvent        = errors.New("invalid pull request review submission")
	ErrInvalidReviewThreadTarget = errors.New("invalid pull request review thread target")
)
View Source
var ErrMissingNotificationSubjectTarget = errors.New("missing notification subject target")

Functions

func BuildRunJobIDFromURL

func BuildRunJobIDFromURL(raw string) (int, bool)

func BuildRunPathFromURL

func BuildRunPathFromURL(raw string) string

func CanonicalPullRequestURL

func CanonicalPullRequestURL(repository string, number int) string

func NormalizeNotificationSubjectTarget

func NormalizeNotificationSubjectTarget(repository string, id int) (string, error)

func NormalizePullRequestDiffFileTeamOwners added in v0.6.1

func NormalizePullRequestDiffFileTeamOwners(teamOwners []string) []string

func NormalizePullRequestDiffText added in v0.6.1

func NormalizePullRequestDiffText(text string) string

func NormalizePullRequestIdentity

func NormalizePullRequestIdentity(repository string, number int) (string, int, error)

func PullRequestCommitChangesURL added in v0.7.0

func PullRequestCommitChangesURL(repository Repository, number int, commitOID string) (string, bool)

func PullRequestHTMLURL

func PullRequestHTMLURL(repository string, number int) string

func RepositoryShortName added in v0.7.0

func RepositoryShortName(repository RepositoryRef) string

Types

type BuildInfo

type BuildInfo struct {
	TypeName     string `json:"__typename"`
	Name         string `json:"name"`
	Status       string `json:"status"`
	Conclusion   string `json:"conclusion"`
	WorkflowName string `json:"workflowName"`
	Link         string `json:"link,omitempty"`
}

type BuildRunJob

type BuildRunJob struct {
	DatabaseID int    `json:"databaseId"`
	Name       string `json:"name"`
	Status     string `json:"status"`
	Conclusion string `json:"conclusion"`
	URL        string `json:"url"`
}

type BuildRunReference

type BuildRunReference struct {
	ID      string
	Attempt int
}

func ParseBuildRunReferenceFromURL

func ParseBuildRunReferenceFromURL(raw string) (BuildRunReference, error)

type CommitDiff added in v0.7.0

type CommitDiff struct {
	Files []PullRequestDiffFile `json:"files"`
}

type ConnectedUser

type ConnectedUser struct {
	Login       string `json:"login"`
	Name        string `json:"name"`
	Bio         string `json:"bio"`
	Company     string `json:"company"`
	Location    string `json:"location"`
	PublicRepos int    `json:"public_repos"`
	Followers   int    `json:"followers"`
	URL         string `json:"html_url"`
}

type IssueDetail

type IssueDetail struct {
	Title     string              `json:"title"`
	Number    int                 `json:"number"`
	URL       string              `json:"html_url"`
	Body      string              `json:"body"`
	BodyHTML  string              `json:"bodyHTML,omitempty"`
	Author    *PullRequestAuthor  `json:"user"`
	State     string              `json:"state"`
	CreatedAt string              `json:"created_at"`
	UpdatedAt string              `json:"updated_at"`
	Labels    []PullRequestLabel  `json:"labels"`
	Assignees []PullRequestAuthor `json:"assignees"`
	Comments  int                 `json:"comments"`
}

type Notification

type Notification struct {
	ID              string              `json:"id"`
	Done            bool                `json:"done"`
	Unread          bool                `json:"unread"`
	Reason          string              `json:"reason"`
	UpdatedAt       string              `json:"updated_at"`
	LastReadAt      string              `json:"last_read_at"`
	URL             string              `json:"url"`
	SubscriptionURL string              `json:"subscription_url"`
	Repository      RepositoryRef       `json:"repository"`
	Subject         NotificationSubject `json:"subject"`
}

func (Notification) IssueIdentity

func (notification Notification) IssueIdentity() (string, int, bool)

func (Notification) PullRequestSummary

func (notification Notification) PullRequestSummary() (PullRequestSummary, bool)

func (Notification) ReleaseIdentity

func (notification Notification) ReleaseIdentity() (string, int, bool)

type NotificationBulkReadResult

type NotificationBulkReadResult struct {
	Accepted bool
}

type NotificationSubject

type NotificationSubject struct {
	Title            string `json:"title"`
	Type             string `json:"type"`
	URL              string `json:"url"`
	LatestCommentURL string `json:"latest_comment_url"`
}

type PullRequest

type PullRequest = PullRequestSummary

type PullRequestAuthor

type PullRequestAuthor struct {
	Login string `json:"login"`
	Name  string `json:"name"`
	IsBot bool   `json:"is_bot"`
}

type PullRequestAutoMergeRequest added in v0.6.0

type PullRequestAutoMergeRequest struct {
	EnabledAt string `json:"enabledAt"`
}

type PullRequestBuildRunJob

type PullRequestBuildRunJob = BuildRunJob

type PullRequestComment

type PullRequestComment struct {
	ID              string                    `json:"id"`
	Author          *PullRequestCommentAuthor `json:"author"`
	Body            string                    `json:"body"`
	BodyHTML        string                    `json:"bodyHTML,omitempty"`
	CreatedAt       string                    `json:"createdAt"`
	URL             string                    `json:"url"`
	DiffHunk        string                    `json:"diffHunk"`
	State           string                    `json:"state"`
	ViewerDidAuthor bool                      `json:"viewerDidAuthor"`
	ReactionGroups  []ReactionGroup           `json:"reactionGroups,omitempty"`
}

type PullRequestCommentAuthor

type PullRequestCommentAuthor struct {
	Login string `json:"login"`
}

type PullRequestCommit

type PullRequestCommit struct {
	OID             string                    `json:"oid"`
	MessageHeadline string                    `json:"messageHeadline"`
	MessageBody     string                    `json:"messageBody"`
	MessageBodyHTML string                    `json:"messageBodyHTML,omitempty"`
	AuthoredDate    string                    `json:"authoredDate"`
	CommittedDate   string                    `json:"committedDate"`
	Authors         []PullRequestCommitAuthor `json:"authors"`
}

type PullRequestCommitAuthor

type PullRequestCommitAuthor struct {
	Login string `json:"login"`
	Name  string `json:"name"`
	Email string `json:"email"`
}

type PullRequestDetail

type PullRequestDetail struct {
	ID                       string                       `json:"id,omitempty"`
	Title                    string                       `json:"title"`
	Number                   int                          `json:"number"`
	URL                      string                       `json:"url"`
	Body                     string                       `json:"body"`
	BodyHTML                 string                       `json:"bodyHTML,omitempty"`
	Author                   *PullRequestAuthor           `json:"author"`
	State                    string                       `json:"state"`
	IsDraft                  bool                         `json:"isDraft"`
	CreatedAt                string                       `json:"createdAt"`
	UpdatedAt                string                       `json:"updatedAt"`
	Labels                   []PullRequestLabel           `json:"labels"`
	Assignees                []PullRequestAuthor          `json:"assignees"`
	ReviewDecision           string                       `json:"reviewDecision"`
	ReviewRequests           []PullRequestReviewRequest   `json:"reviewRequests"`
	BaseRefName              string                       `json:"baseRefName"`
	HeadRefName              string                       `json:"headRefName"`
	MergeStateStatus         string                       `json:"mergeStateStatus"`
	Mergeable                string                       `json:"mergeable"`
	AutoMergeRequest         *PullRequestAutoMergeRequest `json:"autoMergeRequest,omitempty"`
	IsMergeQueueEnabled      bool                         `json:"isMergeQueueEnabled,omitempty"`
	IsInMergeQueue           bool                         `json:"isInMergeQueue,omitempty"`
	MergeQueueEntry          *PullRequestMergeQueueEntry  `json:"mergeQueueEntry,omitempty"`
	ViewerCanEnableAutoMerge bool                         `json:"viewerCanEnableAutoMerge,omitempty"`
	OutOfDateWithBase        bool                         `json:"outOfDateWithBase,omitempty"`
	ReactionGroups           []ReactionGroup              `json:"reactionGroups,omitempty"`
	Comments                 []PullRequestComment         `json:"comments"`
	Commits                  []PullRequestCommit          `json:"commits"`
	Reviews                  []PullRequestReview          `json:"reviews"`
	InlineComments           []PullRequestInlineComment   `json:"-"`
	InlineCommentThreads     []ReviewThread               `json:"-"`
	Additions                int                          `json:"additions"`
	Deletions                int                          `json:"deletions"`
	ChangedFiles             int                          `json:"changedFiles"`
	StatusCheckRollup        []BuildInfo                  `json:"statusCheckRollup"`
}

type PullRequestDiff

type PullRequestDiff struct {
	UnifiedDiff             string
	Files                   []PullRequestDiffFile
	Threads                 []ReviewThread
	FileTeamOwnersAttempted bool `json:"fileTeamOwnersAttempted,omitempty"`
}

type PullRequestDiffFile

type PullRequestDiffFile struct {
	Path         string   `json:"filename"`
	PreviousPath string   `json:"previous_filename"`
	ChangeType   string   `json:"status"`
	Additions    int      `json:"additions"`
	Deletions    int      `json:"deletions"`
	Patch        string   `json:"patch"`
	TeamOwners   []string `json:"teamOwners,omitempty"`
}

type PullRequestInlineComment

type PullRequestInlineComment struct {
	ID                string                    `json:"node_id"`
	Author            *PullRequestCommentAuthor `json:"user"`
	Body              string                    `json:"body"`
	BodyHTML          string                    `json:"bodyHTML,omitempty"`
	CreatedAt         string                    `json:"created_at"`
	URL               string                    `json:"html_url"`
	Path              string                    `json:"path"`
	DiffHunk          string                    `json:"diff_hunk"`
	Line              int                       `json:"line"`
	OriginalLine      int                       `json:"original_line"`
	StartLine         int                       `json:"start_line"`
	OriginalStartLine int                       `json:"original_start_line"`
	Side              string                    `json:"side"`
	StartSide         string                    `json:"start_side"`
	SubjectType       string                    `json:"subject_type"`
	ReactionGroups    []ReactionGroup           `json:"reactionGroups,omitempty"`
}

type PullRequestLabel

type PullRequestLabel struct {
	Name string `json:"name"`
}

type PullRequestMergeQueueEntry added in v0.7.0

type PullRequestMergeQueueEntry struct {
	ID                   string `json:"id,omitempty"`
	State                string `json:"state,omitempty"`
	Position             int    `json:"position,omitempty"`
	EstimatedTimeToMerge int    `json:"estimatedTimeToMerge,omitempty"`
}

type PullRequestRequestedReviewer

type PullRequestRequestedReviewer struct {
	TypeName     string                                `json:"__typename"`
	Login        string                                `json:"login"`
	Name         string                                `json:"name"`
	Slug         string                                `json:"slug"`
	Organization *PullRequestReviewRequestOrganization `json:"organization"`
}

type PullRequestReview

type PullRequestReview struct {
	ID             string                    `json:"id"`
	Author         *PullRequestCommentAuthor `json:"author"`
	Body           string                    `json:"body"`
	State          string                    `json:"state"`
	SubmittedAt    string                    `json:"submittedAt"`
	ReactionGroups []ReactionGroup           `json:"reactionGroups,omitempty"`
}

type PullRequestReviewEvent

type PullRequestReviewEvent = ReviewEvent

type PullRequestReviewRequest

type PullRequestReviewRequest struct {
	RequestedReviewer PullRequestRequestedReviewer `json:"requestedReviewer"`
}

func (*PullRequestReviewRequest) UnmarshalJSON

func (reviewRequest *PullRequestReviewRequest) UnmarshalJSON(data []byte) error

type PullRequestReviewRequestOrganization

type PullRequestReviewRequestOrganization struct {
	Login string `json:"login"`
}

type PullRequestReviewThread

type PullRequestReviewThread = ReviewThread

type PullRequestReviewThreadTarget

type PullRequestReviewThreadTarget = ReviewThreadTarget

type PullRequestStatusCheck

type PullRequestStatusCheck = BuildInfo

type PullRequestSummary

type PullRequestSummary struct {
	ID                       string                       `json:"id"`
	Title                    string                       `json:"title"`
	Number                   int                          `json:"number"`
	Repository               RepositoryRef                `json:"repository"`
	URL                      string                       `json:"url"`
	Body                     string                       `json:"body"`
	State                    string                       `json:"state"`
	IsDraft                  bool                         `json:"isDraft"`
	UpdatedAt                string                       `json:"updatedAt"`
	ReviewDecision           string                       `json:"reviewDecision"`
	ReviewRequests           []PullRequestReviewRequest   `json:"reviewRequests"`
	MergeStateStatus         string                       `json:"mergeStateStatus"`
	Mergeable                string                       `json:"mergeable"`
	AutoMergeRequest         *PullRequestAutoMergeRequest `json:"autoMergeRequest,omitempty"`
	IsMergeQueueEnabled      bool                         `json:"isMergeQueueEnabled,omitempty"`
	IsInMergeQueue           bool                         `json:"isInMergeQueue,omitempty"`
	MergeQueueEntry          *PullRequestMergeQueueEntry  `json:"mergeQueueEntry,omitempty"`
	ViewerCanEnableAutoMerge bool                         `json:"viewerCanEnableAutoMerge,omitempty"`
	StatusCheckRollupState   string                       `json:"statusCheckRollupState"`
}

func ParsePullRequestURL

func ParsePullRequestURL(raw string) (PullRequestSummary, error)

type ReactionContent

type ReactionContent string
const (
	ReactionContentThumbsUp   ReactionContent = "+1"
	ReactionContentThumbsDown ReactionContent = "-1"
	ReactionContentLaugh      ReactionContent = "laugh"
	ReactionContentHooray     ReactionContent = "hooray"
	ReactionContentConfused   ReactionContent = "confused"
	ReactionContentHeart      ReactionContent = "heart"
	ReactionContentRocket     ReactionContent = "rocket"
	ReactionContentEyes       ReactionContent = "eyes"
)

func NormalizeReactionContent

func NormalizeReactionContent(value string) ReactionContent

type ReactionGroup

type ReactionGroup struct {
	Content          ReactionContent `json:"content"`
	TotalCount       int             `json:"totalCount"`
	ViewerHasReacted bool            `json:"viewerHasReacted"`
}

func (*ReactionGroup) UnmarshalJSON

func (group *ReactionGroup) UnmarshalJSON(data []byte) error

type ReleaseDetail

type ReleaseDetail struct {
	Name        string             `json:"name"`
	TagName     string             `json:"tag_name"`
	URL         string             `json:"html_url"`
	Body        string             `json:"body"`
	BodyHTML    string             `json:"bodyHTML,omitempty"`
	Draft       bool               `json:"draft"`
	PreRelease  bool               `json:"prerelease"`
	CreatedAt   string             `json:"created_at"`
	UpdatedAt   string             `json:"updated_at"`
	PublishedAt string             `json:"published_at"`
	Author      *PullRequestAuthor `json:"author"`
}

type Repository

type Repository = RepositoryRef

type RepositoryRef

type RepositoryRef struct {
	Name          string `json:"name"`
	NameWithOwner string `json:"nameWithOwner"`
}

func (*RepositoryRef) UnmarshalJSON

func (repository *RepositoryRef) UnmarshalJSON(data []byte) error

type ReviewEvent

type ReviewEvent string

func NormalizeReviewEvent

func NormalizeReviewEvent(event ReviewEvent) (ReviewEvent, error)

type ReviewThread

type ReviewThread struct {
	ID                 string               `json:"id"`
	IsResolved         bool                 `json:"isResolved"`
	IsOutdated         bool                 `json:"isOutdated"`
	ViewerCanResolve   bool                 `json:"viewerCanResolve"`
	ViewerCanUnresolve bool                 `json:"viewerCanUnresolve"`
	Path               string               `json:"path"`
	Line               int                  `json:"line"`
	OriginalLine       int                  `json:"originalLine"`
	StartLine          int                  `json:"startLine"`
	OriginalStartLine  int                  `json:"originalStartLine"`
	DiffSide           string               `json:"diffSide"`
	StartDiffSide      string               `json:"startDiffSide"`
	Comments           []PullRequestComment `json:"-"`
}

type ReviewThreadTarget

type ReviewThreadTarget struct {
	Path        string
	Line        int
	Side        string
	StartLine   int
	StartSide   string
	SubjectType string
}

func NormalizeReviewThreadTarget

func NormalizeReviewThreadTarget(target ReviewThreadTarget) (ReviewThreadTarget, error)

Jump to

Keyboard shortcuts

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