github

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChannelMembers added in v1.1.0

func ChannelMembers(ctx workflow.Context, pr PullRequest) []string

ChannelMembers returns a list of opted-in Slack user IDs who are PR authors/reviewers/followers. The output is guaranteed to be sorted, without repetitions, and not contain (unresolved) teams or bots.

func ImpersonateUserInMsg added in v1.1.0

func ImpersonateUserInMsg(ctx workflow.Context, url, channelID string, user User, msg string, diff []byte) error

func ImpersonateUserInReply added in v1.1.0

func ImpersonateUserInReply(ctx workflow.Context, url, parentURL string, user User, msg string, diff []byte) error

func ImpersonationToMention added in v1.1.0

func ImpersonationToMention(msg string) string

ImpersonationToMention converts a message that was meant to be used in ImpersonateUserInMsg or ImpersonateUserInReply into a message that can be used in MentionUserInMsg or MentionUserInReply, by adjusting the prefix.

This is potentially relevant only for file and inline comments: if the message includes a file (i.e. contains a Slack file permalink), we can't impersonate the user, because the Slack API won't allow us to update or delete the message later.

func InitPRData added in v1.1.0

func InitPRData(ctx workflow.Context, event PullRequestEvent, channelID string)

InitPRData saves the initial state of a new PR: mainly a 2-way ID mapping for syncs between GitHub and Slack. If there are errors, they are logged but ignored, as we can try to recreate the data later.

func LoginsToSlackIDs added in v1.1.0

func LoginsToSlackIDs(ctx workflow.Context, logins []string) []string

func MentionUserInMsg added in v1.1.0

func MentionUserInMsg(ctx workflow.Context, channelID string, user User, msg string)

func MentionUserInReply added in v1.1.0

func MentionUserInReply(ctx workflow.Context, parentURL string, user User, msg string) error

func ReviewerMentions added in v1.1.0

func ReviewerMentions(ctx workflow.Context, action, role string, reviewers []User) string

ReviewerMentions returns a Slack message mentioning 1 or more added or removed reviewers.

func SetChannelBookmarks added in v1.1.0

func SetChannelBookmarks(ctx workflow.Context, channelID, prURL string, pr PullRequest)

func SlackDisplayName added in v1.1.0

func SlackDisplayName(ctx workflow.Context, user User) string

SlackDisplayName returns the Slack display name corresponding to the given GitHub user, linked to their Slack profile if possible. We use this instead of users.GitHubIDToSlackRef in cases where we want to mention the user without actually spamming them with echoes of their own actions.

func UpdateChannelBookmarks added in v1.1.0

func UpdateChannelBookmarks(ctx workflow.Context, pr PullRequest, channelID string)

UpdateChannelBookmarks updates the bookmarks in the PR's Slack channel, based on the latest PR event. This is a deferred call that doesn't return an error, because handling the event itself is more important.

Types

type AutoMerge

type AutoMerge struct {
	EnabledBy     User   `json:"enabled_by"`
	MergeMethod   string `json:"merge_method"`
	CommitTitle   string `json:"commit_title"`
	CommitMessage string `json:"commit_message"`
}

type Branch

type Branch struct {
	Label string     `json:"label"`
	Ref   string     `json:"ref"`
	SHA   string     `json:"sha"`
	Repo  Repository `json:"repo"`
	User  User       `json:"user"`
}

type ChangeBase added in v0.2.0

type ChangeBase struct {
	Ref ChangeFrom `json:"ref"`
	SHA ChangeFrom `json:"sha"`
}

type ChangeFrom added in v0.2.0

type ChangeFrom struct {
	From string `json:"from"`
}

type Changes

type Changes struct {
	Title *ChangeFrom `json:"title,omitempty"`
	Body  *ChangeFrom `json:"body,omitempty"`
	Base  *ChangeBase `json:"base,omitempty"`
}

type Installation

type Installation struct {
	ID int64 `json:"id"`
}

type IssueComment added in v1.1.0

type IssueComment struct {
	ID      int    `json:"id"`
	HTMLURL string `json:"html_url"`
	User    User   `json:"user"`

	Body      string     `json:"body"`
	Reactions *Reactions `json:"reactions,omitempty"`

	CreatedAt string `json:"created_at"`
	UpdatedAt string `json:"updated_at"`
}

IssueComment is based on: https://docs.github.com/en/rest/issues/comments?apiVersion=2022-11-28#get-an-issue-comment

type IssueCommentEvent

type IssueCommentEvent struct {
	Action  string       `json:"action"`
	Issue   Issue        `json:"issue"`
	Comment IssueComment `json:"comment"`
	Sender  User         `json:"sender"`

	Changes *Changes `json:"changes,omitempty"`
}

IssueCommentEvent is based on: https://docs.github.com/en/webhooks/webhook-events-and-payloads#issue_comment

type Organization

type Organization struct {
	ID    int64  `json:"id"`
	Login string `json:"login"`
}

type PullComment added in v1.1.0

type PullComment struct {
	ID                  int    `json:"id"`
	PullRequestReviewID int    `json:"pull_request_review_id"`
	InReplyTo           *int   `json:"in_reply_to_id,omitempty"`
	HTMLURL             string `json:"html_url"`
	User                User   `json:"user"`

	CommitID         string `json:"commit_id"`
	OriginalCommitID string `json:"original_commit_id"`
	Path             string `json:"path"`

	Body        string     `json:"body"`
	DiffHunk    string     `json:"diff_hunk"`
	SubjectType string     `json:"subject_type,omitempty"`
	Reactions   *Reactions `json:"reactions,omitempty"`

	StartLine         *int    `json:"start_line,omitempty"`
	OriginalStartLine *int    `json:"original_start_line,omitempty"`
	StartSide         *string `json:"start_side,omitempty"`
	Line              *int    `json:"line,omitempty"`
	OriginalLine      *int    `json:"original_line,omitempty"`
	Side              *string `json:"side,omitempty"`

	CreatedAt string `json:"created_at"`
	UpdatedAt string `json:"updated_at"`
}

PullComment is based on: https://docs.github.com/en/rest/pulls/comments?apiVersion=2022-11-28#get-a-review-comment-for-a-pull-request

type PullRequest

type PullRequest struct {
	ID     int64 `json:"id"`
	Number int   `json:"number"`

	HTMLURL  string `json:"html_url"`
	DiffURL  string `json:"diff_url"`
	PatchURL string `json:"patch_url"`

	Title string  `json:"title"`
	Body  *string `json:"body"`
	State string  `json:"state"`

	User               User   `json:"user"`
	Assignee           *User  `json:"assignee"`
	Assignees          []User `json:"assignees"`
	RequestedReviewers []User `json:"requested_reviewers"`
	RequestedTeams     []Team `json:"requested_teams"`

	Head Branch `json:"head"`
	Base Branch `json:"base"`

	CreatedAt      string     `json:"created_at"`
	UpdatedAt      string     `json:"updated_at"`
	ClosedAt       *string    `json:"closed_at"`
	MergedAt       *string    `json:"merged_at"`
	MergedBy       *User      `json:"merged_by"`
	MergeCommitSHA *string    `json:"merge_commit_sha"`
	AutoMerge      *AutoMerge `json:"auto_merge"`

	ActiveLockReason *string `json:"active_lock_reason"`
	Draft            bool    `json:"draft"`
	Locked           bool    `json:"locked"`
	Merged           bool    `json:"merged"`
	Mergeable        *bool   `json:"mergeable"`
	Rebaseable       *bool   `json:"rebaseable"`
	MergeableState   string  `json:"mergeable_state"`
	Comments         int     `json:"comments"`
	ReviewComments   int     `json:"review_comments"`
	Commits          int     `json:"commits"`
	Additions        int     `json:"additions"`
	Deletions        int     `json:"deletions"`
	ChangedFiles     int     `json:"changed_files"`
}

PullRequest is based on:

type PullRequestEvent

type PullRequestEvent struct {
	Action      string      `json:"action"`
	Number      int         `json:"number"`
	PullRequest PullRequest `json:"pull_request"`
	Sender      User        `json:"sender"`

	Assignee          *User `json:"assignee,omitempty"`
	RequestedReviewer *User `json:"requested_reviewer,omitempty"`
	RequestedTeam     *Team `json:"requested_team,omitempty"`

	Changes *Changes `json:"changes,omitempty"`
	Before  *string  `json:"before,omitempty"`
	After   *string  `json:"after,omitempty"`
}

PullRequestEvent is based on: https://docs.github.com/en/webhooks/webhook-events-and-payloads#pull_request

type PullRequestReviewCommentEvent

type PullRequestReviewCommentEvent struct {
	Action      string      `json:"action"`
	PullRequest PullRequest `json:"pull_request"`
	Comment     PullComment `json:"comment"`
	Sender      User        `json:"sender"`

	Changes *Changes `json:"changes,omitempty"`
}

PullRequestReviewCommentEvent is based on: https://docs.github.com/en/webhooks/webhook-events-and-payloads#pull_request_review_comment

type PullRequestReviewEvent

type PullRequestReviewEvent struct {
	Action      string      `json:"action"`
	PullRequest PullRequest `json:"pull_request"`
	Review      Review      `json:"review"`
	Sender      User        `json:"sender"`

	Changes *Changes `json:"changes,omitempty"`
}

PullRequestReviewEvent is based on: https://docs.github.com/en/webhooks/webhook-events-and-payloads#pull_request_review

type PullRequestReviewThreadEvent

type PullRequestReviewThreadEvent struct {
	Action      string      `json:"action"`
	PullRequest PullRequest `json:"pull_request"`
	Thread      Thread      `json:"thread"`
	Sender      User        `json:"sender"`
}

PullRequestReviewThreadEvent is based on: https://docs.github.com/en/webhooks/webhook-events-and-payloads#pull_request_review_thread

type Reactions added in v1.1.0

type Reactions struct {
	URL string `json:"url"`

	TotalCount int `json:"total_count"`
	PlusOne    int `json:"+1"`
	MinusOne   int `json:"-1"`
	Laugh      int `json:"laugh"`
	Confused   int `json:"confused"`
	Heart      int `json:"heart"`
	Hooray     int `json:"hooray"`
	Eyes       int `json:"eyes"`
	Rocket     int `json:"rocket"`
}

type Repository

type Repository struct {
	ID       int64  `json:"id"`
	Name     string `json:"name"`
	FullName string `json:"full_name"`
	HTMLURL  string `json:"html_url"`
}

type Review

type Review struct {
	ID      int    `json:"id"`
	HTMLURL string `json:"html_url"`
	User    *User  `json:"user"`

	Body  string `json:"body"`
	State string `json:"state"`

	SubmittedAt string `json:"submitted_at"`
	UpdatedAt   string `json:"updated_at,omitempty"`
	CommitID    string `json:"commit_id"`
}

Review is based on: https://docs.github.com/en/webhooks/webhook-events-and-payloads#pull_request_review https://docs.github.com/en/rest/pulls/reviews?apiVersion=2022-11-28#get-a-review-for-a-pull-request

type Team

type Team struct {
	ID          int64   `json:"id"`
	Slug        string  `json:"slug"`
	Name        string  `json:"name"`
	Description *string `json:"description"`
	HTMLURL     string  `json:"html_url"`
}

type User

type User struct {
	ID        int64  `json:"id"`
	Login     string `json:"login"`
	HTMLURL   string `json:"html_url"`
	Type      string `json:"type"`
	SiteAdmin bool   `json:"site_admin"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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