github

package
v1.4.10 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultBaseURL = "https://api.github.com"

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

ghAPI is an implementation of the SCMClient interface for GitHub Actions.

func NewClient

func NewClient(repo string, opts ...ClientOption) (*Client, error)

githubClient returns a new GitHub client for the given repository. If the GITHUB_TOKEN is set, it will be used for authentication.

func (*Client) CreateIssueComment

func (c *Client) CreateIssueComment(ctx context.Context, prID int, comment string) error

func (*Client) CreateReviewComment

func (c *Client) CreateReviewComment(ctx context.Context, prID int, s *PullRequestComment) error

func (*Client) IssueComments

func (c *Client) IssueComments(ctx context.Context, prID int) ([]IssueComment, error)

func (*Client) ListPullRequestFiles

func (c *Client) ListPullRequestFiles(ctx context.Context, prID int) ([]string, error)

ListPullRequestFiles return paths of the files in the trigger event pull request.

func (*Client) OpeningPullRequest

func (c *Client) OpeningPullRequest(ctx context.Context, branch string) (*PullRequest, error)

OpeningPullRequest returns the latest open pull request for the given branch.

func (*Client) ReviewComments

func (c *Client) ReviewComments(ctx context.Context, prID int) ([]PullRequestComment, error)

listReviewComments for the trigger event pull request.

func (*Client) UpdateIssueComment

func (c *Client) UpdateIssueComment(ctx context.Context, id int, comment string) error

updateIssueComment updates issue comment with the given id.

func (*Client) UpdateReviewComment

func (c *Client) UpdateReviewComment(ctx context.Context, id int, body string) error

updateReviewComment updates the review comment with the given id.

type ClientOption

type ClientOption func(*Client) error

ClientOption is the option when creating a new client.

func WithBaseURL

func WithBaseURL(url string) ClientOption

WithBaseURL returns a ClientOption that sets the base URL for the client.

func WithToken

func WithToken(t *oauth2.Token) ClientOption

WithToken returns a ClientOption that sets the token for the client.

type IssueComment

type IssueComment struct {
	ID   int    `json:"id"`
	Body string `json:"body"`
}

type PullRequest

type PullRequest struct {
	Number int
	URL    string
	Body   string
	Commit string
}

type PullRequestComment

type PullRequestComment struct {
	ID        int    `json:"id,omitempty"`
	Body      string `json:"body"`
	Path      string `json:"path"`
	CommitID  string `json:"commit_id,omitempty"`
	StartLine int    `json:"start_line,omitempty"`
	Line      int    `json:"line,omitempty"`
}

type TriggerEvent

type TriggerEvent struct {
	PullRequest struct {
		Number int    `mapstructure:"number"`
		Body   string `mapstructure:"body"`
		URL    string `mapstructure:"html_url"`
		Head   struct {
			SHA string `mapstructure:"sha"`
		} `mapstructure:"head"`
	} `mapstructure:"pull_request"`
	Repository struct {
		URL string `mapstructure:"html_url"`
	} `mapstructure:"repository"`
}

TriggerEvent is the structure of the GitHub trigger event.

func ExtractEvent

func ExtractEvent(raw map[string]any) (*TriggerEvent, error)

ExtractEvent extracts the trigger event data from the raw event.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳