github

package
v3.27.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2023 License: LGPL-3.0 Imports: 20 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrProjectHasNoStatusField    = errors.New("project has no status field")
	ErrProjectHasNoSuchField      = errors.New("project field not found")
	ErrProjectHasNoSuchFieldValue = errors.New("project field value not found")
	ErrProjectItemsNotFound       = errors.New("project items not found")
	ErrProjectNotFound            = errors.New("project not found")
	ErrProjectStatusNotFound      = errors.New("project status not found")
)

Functions

func CheckoutBranch added in v3.5.0

func CheckoutBranch(log *logrus.Entry, repo *git.Repository, branchName string) error

CheckoutBranch checks out a given branch in the given repository.

func CloneRepository added in v3.5.0

func CloneRepository(log *logrus.Entry, url string, token string, path string, options *git.CloneOptions) (*git.Repository, string, error)

CloneRepository clones a repository from a given URL to the provided path. url needs to be an HTTPS uri (e.g. https://github.com/libgit2/TestGitRepository) path can be empty. In this case, the repository will be cloned to a temporary location and the location is returned.

func GetPullRequestBaseOwnerName

func GetPullRequestBaseOwnerName(pullRequest *github.PullRequest) string

func GetPullRequestBaseRepoName

func GetPullRequestBaseRepoName(pullRequest *github.PullRequest) string

func GetPullRequestHeadOwnerName

func GetPullRequestHeadOwnerName(pullRequest *github.PullRequest) string

func GetPullRequestHeadRepoName

func GetPullRequestHeadRepoName(pullRequest *github.PullRequest) string

func GetPullRequestNumber

func GetPullRequestNumber(pullRequest *github.PullRequest) int

func PaginatedRequest

func PaginatedRequest(
	initFn func() interface{},
	reqFn func(interface{}, int) (interface{}, *github.Response, error),
) (interface{}, error)

func ParseNumPages

func ParseNumPages(resp *github.Response) int

ParseNumPages Given a link header string representing pagination info, returns total number of pages.

func ParseNumPagesFromLink(link string) int

func Push added in v3.5.0

func Push(log *logrus.Entry, repo *git.Repository, remoteName string, branchName string, token string, force bool) error

Push performs a push of the provided remote/branch.

func RebaseOnto added in v3.5.0

func RebaseOnto(log *logrus.Entry, repo *git.Repository, branchName string, rebaseOptions *git.RebaseOptions) error

RebaseOnto performs a rebase of the current repository Head onto the given branch. Inspired by https://github.com/libgit2/git2go/blob/main/rebase_test.go#L359

Types

type AddProjectV2ItemByIdInput added in v3.19.0

type AddProjectV2ItemByIdInput struct {
	ProjectID string `json:"projectId"`
	ContentID string `json:"contentId"`
	// A unique identifier for the client performing the mutation. (Optional.)
	ClientMutationID *string `json:"clientMutationId,omitempty"`
}

type CommitStatus added in v3.24.0

type CommitStatus struct {
	ID  uint64 `json:"id"`
	URL string `json:"url"`
}

type CompareBaseAndHeadQuery added in v3.26.0

type CompareBaseAndHeadQuery struct {
	Repository struct {
		PullRequest struct {
			BaseRef struct {
				Compare struct {
					BehindBy int
				} `graphql:"compare(headRef: $headRef)"`
			} `graphql:"baseRef"`
		} `graphql:"pullRequest(number: $number)"`
	} `graphql:"repository(owner: $owner, name: $name)"`
}

type CreateCommitStatusOptions added in v3.24.0

type CreateCommitStatusOptions struct {
	State       string `json:"state"`
	Context     string `json:"context"`
	Description string `json:"description"`
}

type FieldDetails

type FieldDetails struct {
	ID       string
	Name     string
	DataType string
}

type FieldNode

type FieldNode struct {
	TypeName                 string                   `graphql:"__typename"`
	SingleSelectFieldDetails SingleSelectFieldDetails `graphql:"... on ProjectV2SingleSelectField"`
	FieldDetails             FieldDetails             `graphql:"... on ProjectV2Field"`
}

type FieldValue added in v3.19.0

type FieldValue interface{}

type Fields

type Fields struct {
	PageInfo PageInfo
	Nodes    []FieldNode
}

type FileSliceLimits added in v3.25.0

type FileSliceLimits struct {
	From uint64
	To   uint64
}

type FirstCommitAndReviewDateQuery added in v3.13.0

type FirstCommitAndReviewDateQuery struct {
	Repository struct {
		PullRequest struct {
			Commits struct {
				Nodes []struct {
					Commit struct {
						AuthoredDate time.Time
					}
				}
			} `graphql:"commits(first: 1)"`
			Reviews struct {
				Nodes []struct {
					CreatedAt time.Time
				}
			} `graphql:"reviews(first: 1)"`
		} `graphql:"pullRequest(number: $pullRequestNumber)"`
	} `graphql:"repository(owner: $repositoryOwner, name: $repositoryName)"`
}

type GQLProjectV2Item added in v3.16.0

type GQLProjectV2Item struct {
	ID      string
	Project ProjectV2
}

type GQLReviewThread

type GQLReviewThread struct {
	IsResolved githubv4.Boolean
	IsOutdated githubv4.Boolean
}

type GetApprovalsCountQuery added in v3.18.0

type GetApprovalsCountQuery struct {
	Repository struct {
		PullRequest struct {
			Reviews struct {
				TotalCount int `graphql:"totalCount"`
			} `graphql:"reviews(first: 1, states: [APPROVED])"`
		} `graphql:"pullRequest(number: $pullRequestNumber)"`
	} `graphql:"repository(owner: $repositoryOwner, name: $repositoryName)"`
}

type GetLastCommitSHAQuery added in v3.16.0

type GetLastCommitSHAQuery struct {
	Repository struct {
		PullRequest struct {
			Commits struct {
				Nodes []struct {
					Commit struct {
						OID string
					}
				}
			} `graphql:"commits(last: 1)"`
		} `graphql:"pullRequest(number: $pullRequestNumber)"`
	} `graphql:"repository(owner: $repositoryOwner, name: $repositoryName)"`
}

type GetObjectQuery added in v3.16.0

type GetObjectQuery struct {
	Repository struct {
		Object struct {
			Blog struct {
				IsBinary bool
			} `graphql:"... on Blob"`
		} `graphql:"object(expression: $expression)"`
	} `graphql:"repository(owner: $repositoryOwner, name: $repositoryName)"`
}

type GetRefIDQuery added in v3.25.0

type GetRefIDQuery struct {
	Repository struct {
		Ref struct {
			ID string
		} `graphql:"ref(qualifiedName: $ref)"`
	} `graphql:"repository(owner: $owner, name: $repo)"`
}

type GitBlame added in v3.25.0

type GitBlame struct {
	CommitSHA string
	Files     map[string]GitBlameFile
}

type GitBlameAuthorRank added in v3.25.0

type GitBlameAuthorRank struct {
	Username   string
	TotalLines int
}

type GitBlameFile added in v3.25.0

type GitBlameFile struct {
	FilePath  string
	LineCount uint64
	Lines     []GitBlameFileLines
}

type GitBlameFileLines added in v3.25.0

type GitBlameFileLines struct {
	FromLine uint64
	ToLine   uint64
	Author   string
}

type GitBlameQuery added in v3.25.0

type GitBlameQuery struct {
	Repository struct {
		Object map[string]struct {
			Ranges []struct {
				StartingLine uint64
				EndingLine   uint64
				Age          uint64
				Commit       struct {
					Author struct {
						User struct {
							Login string
						}
					}
				}
			}
		}
	}
}

type GithubAppClient added in v3.19.0

type GithubAppClient struct {
	*github.Client
}

func NewGithubAppClient added in v3.19.0

func NewGithubAppClient(gitHubAppID int64, gitHubAppPrivateKey []byte) (*GithubAppClient, error)

func (*GithubAppClient) CreateInstallationToken added in v3.19.0

func (c *GithubAppClient) CreateInstallationToken(ctx context.Context, id int64, opts *github.InstallationTokenOptions) (*github.InstallationToken, error)

CreateInstallationToken creates a new installation token for the github app. For more details see https://docs.github.com/en/rest/apps/apps#create-an-installation-access-token-for-an-app

func (*GithubAppClient) GetInstallations added in v3.19.0

func (c *GithubAppClient) GetInstallations(ctx context.Context) ([]*github.Installation, error)

GetInstallations returns all installations for the github app. For more details see https://docs.github.com/en/rest/apps/apps#list-installations-for-the-authenticated-app

type GithubClient

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

func NewGithubClient

func NewGithubClient(clientREST *github.Client, clientGQL *githubv4.Client, rawClientGQL *graphql.Client) *GithubClient

func NewGithubClientFromToken

func NewGithubClientFromToken(ctx context.Context, token string) *GithubClient

func (*GithubClient) AddAssignees

func (c *GithubClient) AddAssignees(ctx context.Context, owner string, repo string, number int, assignees []string) (*github.Issue, *github.Response, error)

func (*GithubClient) AddLabels

func (c *GithubClient) AddLabels(ctx context.Context, owner string, repo string, number int, labels []string) ([]*github.Label, *github.Response, error)

func (*GithubClient) ComputeGitBlameRank added in v3.25.0

func (c *GithubClient) ComputeGitBlameRank(gitBlame *GitBlame) []GitBlameAuthorRank

func (*GithubClient) CreateComment

func (c *GithubClient) CreateComment(ctx context.Context, owner string, repo string, number int, comment *github.IssueComment) (*github.IssueComment, *github.Response, error)

func (*GithubClient) CreateCommitStatus added in v3.24.0

func (c *GithubClient) CreateCommitStatus(ctx context.Context, owner string, repo string, headSHA string, opt *CreateCommitStatusOptions) (*CommitStatus, error)

func (*GithubClient) CreateLabel

func (c *GithubClient) CreateLabel(ctx context.Context, owner string, repo string, label *github.Label) (*github.Label, *github.Response, error)

func (*GithubClient) DeleteComment

func (c *GithubClient) DeleteComment(ctx context.Context, owner string, repo string, commentId int64) (*github.Response, error)

func (*GithubClient) DeleteReference added in v3.11.0

func (c *GithubClient) DeleteReference(ctx context.Context, owner, repo, ref string) error

func (*GithubClient) DownloadContents

func (c *GithubClient) DownloadContents(ctx context.Context, filePath string, branch *github.PullRequestBranch) ([]byte, error)

func (*GithubClient) EditComment

func (c *GithubClient) EditComment(ctx context.Context, owner string, repo string, commentId int64, comment *github.IssueComment) (*github.IssueComment, *github.Response, error)

func (*GithubClient) EditIssue added in v3.3.0

func (c *GithubClient) EditIssue(ctx context.Context, owner string, repo string, number int, issue *github.IssueRequest) (*github.Issue, *github.Response, error)

func (*GithubClient) EditLabel added in v3.7.0

func (c *GithubClient) EditLabel(ctx context.Context, owner string, repo string, name string, label *github.Label) (*github.Label, *github.Response, error)

func (*GithubClient) EditPullRequest

func (c *GithubClient) EditPullRequest(ctx context.Context, owner string, repo string, number int, pull *github.PullRequest) (*github.PullRequest, *github.Response, error)

func (*GithubClient) GetApprovalsCount added in v3.18.0

func (c *GithubClient) GetApprovalsCount(ctx context.Context, owner, repo string, number int) (int, error)

func (*GithubClient) GetAuthenticatedUserLogin added in v3.25.0

func (c *GithubClient) GetAuthenticatedUserLogin() (string, error)

func (*GithubClient) GetCheckRunsForRef added in v3.15.0

func (c *GithubClient) GetCheckRunsForRef(ctx context.Context, owner string, repo string, number int, ref string, opts *github.ListCheckRunsOptions) ([]*github.CheckRun, error)

func (*GithubClient) GetClientGraphQL

func (c *GithubClient) GetClientGraphQL() *githubv4.Client

func (*GithubClient) GetClientREST

func (c *GithubClient) GetClientREST() *github.Client

FIXME: Remove these to hide the implementation details.

func (*GithubClient) GetComments added in v3.3.0

func (c *GithubClient) GetComments(ctx context.Context, owner string, repo string, number int, opts *github.IssueListCommentsOptions) ([]*github.IssueComment, error)

func (*GithubClient) GetDefaultRepositoryBranch added in v3.3.0

func (c *GithubClient) GetDefaultRepositoryBranch(ctx context.Context, owner string, repo string) (string, error)

func (*GithubClient) GetFirstCommitAndReviewDate added in v3.13.0

func (c *GithubClient) GetFirstCommitAndReviewDate(ctx context.Context, owner, repo string, number int) (*time.Time, *time.Time, error)

func (*GithubClient) GetGitBlame added in v3.25.0

func (c *GithubClient) GetGitBlame(ctx context.Context, owner, name, commitSHA string, filePaths []string) (*GitBlame, error)

func (*GithubClient) GetHeadBehindBy added in v3.26.0

func (c *GithubClient) GetHeadBehindBy(ctx context.Context, owner, repo, prOwner, headBranch string, number int) (int, error)

func (*GithubClient) GetIssue added in v3.3.0

func (c *GithubClient) GetIssue(ctx context.Context, owner, repo string, number int) (*github.Issue, *github.Response, error)

func (*GithubClient) GetIssueTimeline added in v3.3.0

func (c *GithubClient) GetIssueTimeline(ctx context.Context, owner string, repo string, number int) ([]*github.Timeline, error)

func (*GithubClient) GetIssuesAvailableAssignees

func (c *GithubClient) GetIssuesAvailableAssignees(ctx context.Context, owner string, repo string) ([]*github.User, error)

func (*GithubClient) GetLabel

func (c *GithubClient) GetLabel(ctx context.Context, owner string, repo string, name string) (*github.Label, *github.Response, error)

func (*GithubClient) GetLastCommitSHA added in v3.16.0

func (c *GithubClient) GetLastCommitSHA(ctx context.Context, owner, repo string, number int) (string, error)

func (*GithubClient) GetLinkedProjectsForIssue added in v3.16.1

func (c *GithubClient) GetLinkedProjectsForIssue(ctx context.Context, owner, repo string, number int, retryCount int) ([]GQLProjectV2Item, error)

func (*GithubClient) GetLinkedProjectsForPullRequest added in v3.16.1

func (c *GithubClient) GetLinkedProjectsForPullRequest(ctx context.Context, owner, repo string, number int, retryCount int) ([]GQLProjectV2Item, error)

func (*GithubClient) GetOpenPullRequestsAsReviewer added in v3.25.0

func (c *GithubClient) GetOpenPullRequestsAsReviewer(ctx context.Context, owner string, repo string, usernames []string) (map[string]int, error)

func (*GithubClient) GetProjectFieldsByProjectNumber

func (c *GithubClient) GetProjectFieldsByProjectNumber(ctx context.Context, owner, repo string, projectNumber uint64, retryCount int) ([]FieldNode, error)

func (*GithubClient) GetProjectV2ByName

func (c *GithubClient) GetProjectV2ByName(ctx context.Context, owner, repo, name string) (*ProjectV2, error)

func (*GithubClient) GetPullRequest

func (c *GithubClient) GetPullRequest(ctx context.Context, owner string, repo string, number int) (*github.PullRequest, *github.Response, error)

func (*GithubClient) GetPullRequestClosingIssuesCount added in v3.3.0

func (c *GithubClient) GetPullRequestClosingIssuesCount(ctx context.Context, owner string, repo string, number int) (int, error)

func (*GithubClient) GetPullRequestCommits

func (c *GithubClient) GetPullRequestCommits(ctx context.Context, owner string, repo string, number int) ([]*github.RepositoryCommit, error)

func (*GithubClient) GetPullRequestFiles

func (c *GithubClient) GetPullRequestFiles(ctx context.Context, owner string, repo string, number int) ([]*github.CommitFile, error)

func (*GithubClient) GetPullRequestLastPushDate added in v3.5.0

func (c *GithubClient) GetPullRequestLastPushDate(ctx context.Context, owner string, repo string, number int) (time.Time, error)

func (*GithubClient) GetPullRequestReviewers

func (c *GithubClient) GetPullRequestReviewers(ctx context.Context, owner string, repo string, number int, opts *github.ListOptions) (*github.Reviewers, error)

func (*GithubClient) GetPullRequestReviews

func (c *GithubClient) GetPullRequestReviews(ctx context.Context, owner string, repo string, number int) ([]*github.PullRequestReview, error)

func (*GithubClient) GetPullRequests

func (c *GithubClient) GetPullRequests(ctx context.Context, owner string, repo string) ([]*github.PullRequest, error)

func (*GithubClient) GetRawClientGraphQL added in v3.25.0

func (c *GithubClient) GetRawClientGraphQL() *graphql.Client

func (*GithubClient) GetRepoCollaborators

func (c *GithubClient) GetRepoCollaborators(ctx context.Context, owner string, repo string) ([]*github.User, error)

func (*GithubClient) GetRepositoryBranch

func (c *GithubClient) GetRepositoryBranch(ctx context.Context, owner string, repo string, branch string, followRedirects bool) (*github.Branch, *github.Response, error)

func (*GithubClient) GetReviewThreads

func (c *GithubClient) GetReviewThreads(ctx context.Context, owner string, repo string, number int, retryCount int) ([]GQLReviewThread, error)

func (*GithubClient) GetToken added in v3.23.0

func (c *GithubClient) GetToken() string

func (*GithubClient) IsFileBinary added in v3.16.0

func (c *GithubClient) IsFileBinary(ctx context.Context, owner, repo, branch, file string) (bool, error)

func (*GithubClient) ListCheckRunsForRef

func (c *GithubClient) ListCheckRunsForRef(ctx context.Context, owner string, repo string, ref string, opts *github.ListCheckRunsOptions) (*github.ListCheckRunsResults, *github.Response, error)

func (*GithubClient) ListIssuesByRepo

func (c *GithubClient) ListIssuesByRepo(ctx context.Context, owner string, repo string, opts *github.IssueListByRepoOptions) ([]*github.Issue, *github.Response, error)

func (*GithubClient) ListOrganizationMembers

func (c *GithubClient) ListOrganizationMembers(ctx context.Context, org string, opts *github.ListMembersOptions) ([]*github.User, *github.Response, error)

func (*GithubClient) ListTeamMembersBySlug

func (c *GithubClient) ListTeamMembersBySlug(ctx context.Context, org string, slug string, opts *github.TeamListTeamMembersOptions) ([]*github.User, *github.Response, error)

func (*GithubClient) Merge

func (c *GithubClient) Merge(ctx context.Context, owner string, repo string, number int, commitMessage string, options *github.PullRequestOptions) (*github.PullRequestMergeResult, *github.Response, error)

func (*GithubClient) RefExists added in v3.25.0

func (c *GithubClient) RefExists(ctx context.Context, owner, repo, ref string) (bool, error)

func (*GithubClient) RemoveLabelForIssue

func (c *GithubClient) RemoveLabelForIssue(ctx context.Context, owner string, repo string, number int, label string) (*github.Response, error)

func (*GithubClient) RequestReviewers

func (c *GithubClient) RequestReviewers(ctx context.Context, owner string, repo string, number int, reviewers github.ReviewersRequest) (*github.PullRequest, *github.Response, error)

func (*GithubClient) Review added in v3.10.0

func (*GithubClient) SliceGitBlame added in v3.25.0

func (c *GithubClient) SliceGitBlame(blame *GitBlame, filePath string, slices []FileSliceLimits) (*GitBlame, error)

func (*GithubClient) TriggerWorkflowByFileName added in v3.18.0

func (c *GithubClient) TriggerWorkflowByFileName(ctx context.Context, owner, repo, branch, workflowFileName string) (*github.Response, error)

type IssueLinkedProjectsQuery added in v3.16.1

type IssueLinkedProjectsQuery struct {
	Repository struct {
		Issue struct {
			ProjectItems *struct {
				Nodes    []GQLProjectV2Item
				PageInfo struct {
					EndCursor   githubv4.String
					HasNextPage bool
				}
			} `graphql:"projectItems(first: 10, after: $projectItemsCursor)"`
		} `graphql:"issue(number: $issueNumber)"`
	} `graphql:"repository(owner: $repositoryOwner, name: $repositoryName)"`
}

type LastFiftyOpenedPullRequestsQuery added in v3.25.0

type LastFiftyOpenedPullRequestsQuery struct {
	Repository struct {
		PullRequests struct {
			Nodes []PullRequestsQuery
		} `graphql:"pullRequests(states: OPEN, last: 50)"`
	} `graphql:"repository(owner: $owner, name: $name)"`
}

type LastPushQuery added in v3.5.0

type LastPushQuery struct {
	Repository struct {
		PullRequest struct {
			TimelineItems struct {
				Nodes []struct {
					Typename                string `graphql:"__typename"`
					HeadRefForcePushedEvent struct {
						CreatedAt *time.Time
					} `graphql:"... on HeadRefForcePushedEvent"`
					PullRequestCommit struct {
						Commit struct {
							PushedDate    *time.Time
							CommittedDate *time.Time
						}
					} `graphql:"... on PullRequestCommit"`
				}
			} `graphql:"timelineItems(last: 1, itemTypes: [HEAD_REF_FORCE_PUSHED_EVENT, PULL_REQUEST_COMMIT])"`
		} `graphql:"pullRequest(number: $pullRequestNumber)"`
	} `graphql:"repository(owner: $repositoryOwner, name: $repositoryName)"`
}

type NumberFieldValue added in v3.19.0

type NumberFieldValue struct {
	Number githubv4.Float `json:"number"`
}

type PageInfo

type PageInfo struct {
	HasNextPage bool
	EndCursor   string
}

type ProjectV2

type ProjectV2 struct {
	ID     string
	Number uint64
	Title  string
}

type PullRequestLinkedProjectsQuery added in v3.16.1

type PullRequestLinkedProjectsQuery struct {
	Repository struct {
		PullRequest struct {
			ProjectItems *struct {
				Nodes    []GQLProjectV2Item
				PageInfo struct {
					EndCursor   githubv4.String
					HasNextPage bool
				}
			} `graphql:"projectItems(first: 10, after: $projectItemsCursor)"`
		} `graphql:"pullRequest(number: $issueNumber)"`
	} `graphql:"repository(owner: $repositoryOwner, name: $repositoryName)"`
}

type PullRequestsQuery added in v3.25.0

type PullRequestsQuery struct {
	ReviewRequests struct {
		Nodes []struct {
			RequestedReviewer struct {
				TypeName string `graphql:"__typename"`
				AsUser   struct {
					Login githubv4.String
				} `graphql:"... on User"`
			}
		}
	} `graphql:"reviewRequests(first: 50)"`
	Reviews struct {
		Nodes []struct {
			Author struct {
				Login githubv4.String
			}
		}
	} `graphql:"reviews(first: 50)"`
}

type ReviewThreadsQuery

type ReviewThreadsQuery struct {
	Repository struct {
		PullRequest struct {
			ReviewThreads struct {
				Nodes    []GQLReviewThread
				PageInfo struct {
					EndCursor   githubv4.String
					HasNextPage bool
				}
			} `graphql:"reviewThreads(first: 10, after: $reviewThreadsCursor)"`
		} `graphql:"pullRequest(number: $pullRequestNumber)"`
	} `graphql:"repository(owner: $repositoryOwner, name: $repositoryName)"`
}

type SingleSelectFieldDetails added in v3.19.0

type SingleSelectFieldDetails struct {
	ID      string
	Name    string
	Options []struct {
		ID   string
		Name string
	}
}

type SingleSelectFieldValue added in v3.19.0

type SingleSelectFieldValue struct {
	SingleSelectOptionId string `json:"singleSelectOptionId"`
}

type TextFieldValue added in v3.19.0

type TextFieldValue struct {
	Text string `json:"text"`
}

type UpdateProjectV2ItemFieldValueInput added in v3.19.0

type UpdateProjectV2ItemFieldValueInput struct {
	ItemID    string     `json:"itemId"`
	Value     FieldValue `json:"value"`
	ProjectID string     `json:"projectId"`
	FieldID   string     `json:"fieldId"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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