github

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package github provides the functionality to send requests to the GitHub API.

Index

Constants

View Source
const (
	Closed = "closed"
	Open   = "open"
	Any    = "any"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

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

Config is the config values for the GitHub client.

type GitHub

type GitHub interface {
	//  ListRepositories lists all repositories and returns details about the repositories.
	ListRepositories(ctx context.Context, owner string, opts *github.RepositoryListByOrgOptions) ([]*Repository, error)

	// ListIssues lists all issues and returns their numbers in a repository matching the given criteria.
	ListIssues(ctx context.Context, owner, repo string, opts *github.IssueListByRepoOptions) ([]*Issue, error)

	// CreateIssue creates an issue.
	CreateIssue(ctx context.Context, owner, repo, title, body string, assignees, labels []string) (*Issue, error)

	// CloseIssue closes an issue.
	CloseIssue(ctx context.Context, owner, repo string, number int) error

	// CreateIssueComment creates a comment for an issue or pull request.
	CreateIssueComment(ctx context.Context, owner, repo string, number int, body string) (*IssueComment, error)

	// UpdateIssueComment updates an issue or pull request comment.
	UpdateIssueComment(ctx context.Context, owner, repo string, id int64, body string) error

	// DeleteIssueComment deletes an issue or pull request comment.
	DeleteIssueComment(ctx context.Context, owner, repo string, id int64) error

	// ListIssueComments lists existing comments for an issue or pull request.
	ListIssueComments(ctx context.Context, owner, repo string, number int, opts *github.IssueListCommentsOptions) (*IssueCommentResponse, error)

	// ListPullRequestsForCommit lists the pull requests associated with a commit.
	ListPullRequestsForCommit(ctx context.Context, owner, repo, sha string, opts *github.PullRequestListOptions) (*PullRequestResponse, error)

	// RepoUserPermissionLevel gets the repository permission level for a user. The possible permissions values
	// are admin, write, read, none.
	RepoUserPermissionLevel(ctx context.Context, owner, repo, user string) (string, error)
}

GitHub provides the minimum interface for sending requests to the GitHub API.

type GitHubClient

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

GitHubClient implements the GitHub interface.

func NewClient

func NewClient(ctx context.Context, token string, opts ...Option) *GitHubClient

NewClient creates a new GitHub client.

func (*GitHubClient) CloseIssue

func (g *GitHubClient) CloseIssue(ctx context.Context, owner, repo string, number int) error

CloseIssue closes an issue.

func (*GitHubClient) CreateIssue

func (g *GitHubClient) CreateIssue(ctx context.Context, owner, repo, title, body string, assignees, labels []string) (*Issue, error)

CreateIssue creates an issue.

func (*GitHubClient) CreateIssueComment

func (g *GitHubClient) CreateIssueComment(ctx context.Context, owner, repo string, number int, body string) (*IssueComment, error)

CreateIssueComment creates a comment for an issue or pull request.

func (*GitHubClient) DeleteIssueComment

func (g *GitHubClient) DeleteIssueComment(ctx context.Context, owner, repo string, id int64) error

DeleteIssueComment deletes an issue or pull request comment.

func (*GitHubClient) ListIssueComments

func (g *GitHubClient) ListIssueComments(ctx context.Context, owner, repo string, number int, opts *github.IssueListCommentsOptions) (*IssueCommentResponse, error)

ListIssueComments lists existing comments for an issue or pull request.

func (*GitHubClient) ListIssues

func (g *GitHubClient) ListIssues(ctx context.Context, owner, repo string, opts *github.IssueListByRepoOptions) ([]*Issue, error)

ListIssues lists all issues and returns their numbers in a repository matching the given criteria.

func (*GitHubClient) ListPullRequestsForCommit

func (g *GitHubClient) ListPullRequestsForCommit(ctx context.Context, owner, repo, sha string, opts *github.PullRequestListOptions) (*PullRequestResponse, error)

ListPullRequestsForCommit lists the pull requests associated with a commit.

func (*GitHubClient) ListRepositories

func (g *GitHubClient) ListRepositories(ctx context.Context, owner string, opts *github.RepositoryListByOrgOptions) ([]*Repository, error)

ListRepositories lists all repositories and returns details about the repositories.

func (*GitHubClient) RepoUserPermissionLevel

func (g *GitHubClient) RepoUserPermissionLevel(ctx context.Context, owner, repo, user string) (string, error)

RepoUserPermissionLevel gets the repository permission level for a user. The possible permissions values are admin, write, read, none.

func (*GitHubClient) UpdateIssueComment

func (g *GitHubClient) UpdateIssueComment(ctx context.Context, owner, repo string, id int64, body string) error

UpdateIssueComment updates an issue or pull request comment.

type Issue

type Issue struct {
	Number int
}

Issue is the GitHub Issue.

type IssueComment

type IssueComment struct {
	ID   int64
	Body string
}

type IssueCommentResponse

type IssueCommentResponse struct {
	Comments   []*IssueComment
	Pagination *Pagination
}

type MockGitHubClient

type MockGitHubClient struct {
	Reqs []*Request

	ListRepositoriesErr          error
	ListIssuesErr                error
	CreateIssueErr               error
	CloseIssueErr                error
	CreateIssueCommentsErr       error
	UpdateIssueCommentsErr       error
	DeleteIssueCommentsErr       error
	ListIssueCommentsErr         error
	ListIssueCommentResponse     *IssueCommentResponse
	ListPullRequestsForCommitErr error
	RepoPermissionLevelErr       error
	RepoPermissionLevel          string
	// contains filtered or unexported fields
}

func (*MockGitHubClient) CloseIssue

func (m *MockGitHubClient) CloseIssue(ctx context.Context, owner, repo string, number int) error

func (*MockGitHubClient) CreateIssue

func (m *MockGitHubClient) CreateIssue(ctx context.Context, owner, repo, title, body string, assignees, labels []string) (*Issue, error)

func (*MockGitHubClient) CreateIssueComment

func (m *MockGitHubClient) CreateIssueComment(ctx context.Context, owner, repo string, number int, body string) (*IssueComment, error)

func (*MockGitHubClient) DeleteIssueComment

func (m *MockGitHubClient) DeleteIssueComment(ctx context.Context, owner, repo string, id int64) error

func (*MockGitHubClient) ListIssueComments

func (m *MockGitHubClient) ListIssueComments(ctx context.Context, owner, repo string, number int, opts *github.IssueListCommentsOptions) (*IssueCommentResponse, error)

func (*MockGitHubClient) ListIssues

func (m *MockGitHubClient) ListIssues(ctx context.Context, owner, repo string, opts *github.IssueListByRepoOptions) ([]*Issue, error)

func (*MockGitHubClient) ListPullRequestsForCommit

func (m *MockGitHubClient) ListPullRequestsForCommit(ctx context.Context, owner, repo, sha string, opts *github.PullRequestListOptions) (*PullRequestResponse, error)

func (*MockGitHubClient) ListRepositories

func (m *MockGitHubClient) ListRepositories(ctx context.Context, owner string, opts *github.RepositoryListByOrgOptions) ([]*Repository, error)

func (*MockGitHubClient) RepoUserPermissionLevel

func (m *MockGitHubClient) RepoUserPermissionLevel(ctx context.Context, owner, repo, user string) (string, error)

func (*MockGitHubClient) UpdateIssueComment

func (m *MockGitHubClient) UpdateIssueComment(ctx context.Context, owner, repo string, id int64, body string) error

type Option

type Option func(*Config) *Config

Option is an optional config value for the GitHubClient.

func WithRetryInitialDelay

func WithRetryInitialDelay(initialRetryDelay time.Duration) Option

WithRetryInitialDelay configures the initial delay time before sending a retry for the GitHub Client.

func WithRetryMaxAttempts

func WithRetryMaxAttempts(maxRetries uint64) Option

WithRetryMaxAttempts configures the maximum number of retry attempts for the GitHub Client.

func WithRetryMaxDelay

func WithRetryMaxDelay(maxRetryDelay time.Duration) Option

WithRetryMaxDelay configures the maximum delay time before sending a retry for the GitHub Client.

type Pagination

type Pagination struct {
	NextPage int
}

Pagination is the paging details for a list response.

type PullRequest

type PullRequest struct {
	ID     int64
	Number int
}

type PullRequestResponse

type PullRequestResponse struct {
	PullRequests []*PullRequest
	Pagination   *Pagination
}

type Repository

type Repository struct {
	ID       int64
	Owner    string
	Name     string
	FullName string
	Topics   []string
}

Repository is the GitHub Repository.

type Request

type Request struct {
	Name   string
	Params []any
}

Jump to

Keyboard shortcuts

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