client

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IssueType       = "ISSUE"
	PullRequestType = "PULL_REQUEST"
)

The fields need to be none pointer types to unmarshal. Hence, we need to check types of the returned items.

Variables

This section is empty.

Functions

This section is empty.

Types

type Caretaker

type Caretaker struct {
	Options
	// contains filtered or unexported fields
}

Caretaker defines the main Caretaker capabilities.

func NewCaretaker

func NewCaretaker(log logger.Logger, gc GraphQLClient, opts Options) *Caretaker

NewCaretaker creates a new Caretaker with an available GitHub GraphQL client.

func (*Caretaker) AddLabel

func (c *Caretaker) AddLabel(ctx context.Context, label string, id githubv4.ID) error

func (*Caretaker) AddReaction added in v0.2.0

func (c *Caretaker) AddReaction(ctx context.Context, objectID githubv4.ID, reaction githubv4.ReactionContent) error

func (*Caretaker) AssignIssueToProject

func (c *Caretaker) AssignIssueToProject(ctx context.Context, issueNumber, projectNumber int) error

func (*Caretaker) AssignUserToAssignable added in v0.2.0

func (c *Caretaker) AssignUserToAssignable(ctx context.Context, userID, objectID githubv4.ID) error

func (*Caretaker) Issue added in v0.1.1

func (c *Caretaker) Issue(ctx context.Context, issueNumber int) (Issue, error)

func (*Caretaker) LeaveComment

func (c *Caretaker) LeaveComment(ctx context.Context, prID githubv4.ID, comment string) error

func (*Caretaker) ProjectItems added in v0.6.0

func (c *Caretaker) ProjectItems(ctx context.Context, projectNumber int) ([]ProjectV2ItemWithIssueContent, error)

func (*Caretaker) PullRequest

func (c *Caretaker) PullRequest(ctx context.Context, prNumber int) (PullRequest, error)

func (*Caretaker) PullRequests

func (c *Caretaker) PullRequests(ctx context.Context) ([]PullRequest, error)

func (*Caretaker) RemoveLabel

func (c *Caretaker) RemoveLabel(ctx context.Context, label string, id githubv4.ID) error

func (*Caretaker) UpdateIssueStatus

func (c *Caretaker) UpdateIssueStatus(
	ctx context.Context,
	issue GenericIssue,
	statusName githubv4.String,
	projectNumber int,
) (bool, error)

func (*Caretaker) User added in v0.2.0

func (c *Caretaker) User(ctx context.Context, name string) (User, error)

type Client

type Client interface {
	AddLabel(ctx context.Context, label string, id githubv4.ID) error
	RemoveLabel(ctx context.Context, label string, id githubv4.ID) error
	AssignIssueToProject(ctx context.Context, issueNumber, projectNumber int) error // Consider combining these two
	AssignUserToAssignable(ctx context.Context, userID, objectID githubv4.ID) error
	AddReaction(ctx context.Context, objectID githubv4.ID, reaction githubv4.ReactionContent) error
	LeaveComment(ctx context.Context, prID githubv4.ID, comment string) error
	PullRequests(ctx context.Context) ([]PullRequest, error)
	PullRequest(ctx context.Context, prNumber int) (PullRequest, error)
	Issue(ctx context.Context, issueNumber int) (Issue, error)
	ProjectItems(
		ctx context.Context,
		projectNumber int,
	) ([]ProjectV2ItemWithIssueContent, error)
	UpdateIssueStatus(ctx context.Context, issue GenericIssue, statusName githubv4.String, projectNumber int) (bool, error)
	User(ctx context.Context, username string) (User, error)
}

Client defines the capabilities of Caretaker.

type Comment added in v0.2.0

type Comment struct {
	ID          githubv4.ID
	Body        githubv4.String
	BodyText    githubv4.String
	Issue       Issue
	PullRequest PullRequest
}

Comment https://docs.github.com/en/graphql/reference/objects#issuecomment

type GenericIssue added in v0.8.0

type GenericIssue interface {
	GetTitle() githubv4.String
	GetID() githubv4.ID
	GetNumber() githubv4.Int
	GetProjectsV2() ProjectsV2
	GetProjectItems() ProjectItems
	IsClosed() bool
}

type GraphQLClient

type GraphQLClient interface {
	Query(ctx context.Context, q any, variables map[string]any) error
	Mutate(ctx context.Context, m any, input githubv4.Input, variables map[string]any) error
}

GraphQLClient hides the GitHub GraphQL library.

type Issue

type Issue struct {
	ID           githubv4.ID
	Closed       githubv4.Boolean
	Title        githubv4.String
	Number       githubv4.Int
	ProjectsV2   ProjectsV2   `graphql:"projectsV2(first: 10)"`
	ProjectItems ProjectItems `graphql:"projectItems(first: 20)"`
}

Issue https://docs.github.com/en/graphql/reference/objects#issue

func (Issue) GetID added in v0.8.0

func (i Issue) GetID() githubv4.ID

func (Issue) GetNumber added in v0.8.0

func (i Issue) GetNumber() githubv4.Int

func (Issue) GetProjectItems added in v0.8.0

func (i Issue) GetProjectItems() ProjectItems

func (Issue) GetProjectsV2 added in v0.8.0

func (i Issue) GetProjectsV2() ProjectsV2

func (Issue) GetTitle added in v0.8.0

func (i Issue) GetTitle() githubv4.String

func (Issue) IsClosed added in v0.8.0

func (i Issue) IsClosed() bool

type Options

type Options struct {
	Repo           string
	Owner          string
	IsOrganization bool
	MoveClosed     bool
}

Options are for Caretaker's functionality.

type PageInfo added in v0.6.1

type PageInfo struct {
	EndCursor   githubv4.String
	HasNextPage githubv4.Boolean
}

type ProjectItems added in v0.8.0

type ProjectItems struct {
	TotalCount githubv4.Int
	Nodes      []ProjectV2Item
}

type ProjectV2

type ProjectV2 struct {
	Title  githubv4.String
	ID     githubv4.String
	Number githubv4.Int
	Field  struct {
		ProjectV2SingleSelectField struct {
			ID      githubv4.String
			Options []struct {
				ID   githubv4.String
				Name githubv4.String
			}
		} `graphql:"... on ProjectV2SingleSelectField"`
	} `graphql:"field(name: \"Status\")"` // gather the selection options for the Status field
}

ProjectV2 https://docs.github.com/en/graphql/reference/objects#projectv2

type ProjectV2Item

type ProjectV2Item struct {
	ID               githubv4.String
	Project          ProjectV2
	FieldValueByName struct {
		ProjectV2SingleSelectField struct {
			Name githubv4.String
		} `graphql:"... on ProjectV2ItemFieldSingleSelectValue"`
	} `graphql:"fieldValueByName(name: \"Status\")"`
}

ProjectV2Item https://docs.github.com/en/graphql/reference/objects#projectv2item

type ProjectV2ItemWithIssueContent added in v0.6.0

type ProjectV2ItemWithIssueContent struct {
	ID        githubv4.String
	Project   ProjectV2
	Type      githubv4.String
	UpdatedAt githubv4.Date
	Content   struct {
		Issue       Issue       `graphql:"... on Issue"`
		PullRequest PullRequest `graphql:"... on PullRequest"`
	}
	FieldValueByName struct {
		ProjectV2SingleSelectField struct {
			Name githubv4.String
		} `graphql:"... on ProjectV2ItemFieldSingleSelectValue"`
	} `graphql:"fieldValueByName(name: \"Status\")"`
}

ProjectV2ItemWithIssueContent https://docs.github.com/en/graphql/reference/objects#projectv2item

type ProjectsV2 added in v0.8.0

type ProjectsV2 struct {
	Nodes []ProjectV2
}

type PullRequest

type PullRequest struct {
	ID        githubv4.ID
	Number    githubv4.Int
	UpdatedAt githubv4.Date
	Closed    githubv4.Boolean
	Title     githubv4.String
	Labels    struct {
		Nodes []struct {
			Name githubv4.String
		}
	} `graphql:"labels(first: 50)"` // We can't use Label with name because that fails if the label is not there
	ClosingIssuesReferences struct {
		Nodes    []Issue
		PageInfo struct {
			EndCursor   githubv4.String
			HasNextPage bool
		} // should not be needed because we don't reference hundreds of issues per pull request.
	} `graphql:"closingIssuesReferences(first: 10)"`
	ProjectsV2   ProjectsV2   `graphql:"projectsV2(first: 10)"`
	ProjectItems ProjectItems `graphql:"projectItems(first: 20)"`
}

PullRequest https://docs.github.com/en/graphql/reference/objects#pullrequest

func (PullRequest) GetID added in v0.8.0

func (p PullRequest) GetID() githubv4.ID

func (PullRequest) GetNumber added in v0.8.0

func (p PullRequest) GetNumber() githubv4.Int

func (PullRequest) GetProjectItems added in v0.8.0

func (p PullRequest) GetProjectItems() ProjectItems

func (PullRequest) GetProjectsV2 added in v0.8.0

func (p PullRequest) GetProjectsV2() ProjectsV2

func (PullRequest) GetTitle added in v0.8.0

func (p PullRequest) GetTitle() githubv4.String

func (PullRequest) IsClosed added in v0.8.0

func (p PullRequest) IsClosed() bool

type Repository

type Repository struct {
	PullRequests struct {
		PageInfo struct {
			EndCursor   githubv4.String
			HasNextPage bool
		} // should not be needed as we don't have more than 100 OPEN PRs.
		Nodes []PullRequest
	} `graphql:"pullRequests(first: 100, states: OPEN)"`
}

Repository https://docs.github.com/en/graphql/reference/objects#repository

type User added in v0.2.0

type User struct {
	ID githubv4.ID
}

User https://docs.github.com/en/graphql/reference/objects#user

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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