model

package
v0.0.0-...-2f0a4f1 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2023 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RewardIssueCommentType   IssueCommentType = "reward"
	EligibleIssueCommentType IssueCommentType = "eligible"
	UnknownCommentType       IssueCommentType = "unknown"

	EligibleCommentHeaderLegacy    = "🤖 Assignees for Issue"
	EligibleCommentHeaderBeginning = "🤖 Assignees for issue"

	ErrorRewardCommentHeader = "### Famed could not generate a reward suggestion."
	RewardCommentTableHeader = "| Contributor | Time | Reward |\n| ----------- | ----------- | ----------- |"
)

Variables

View Source
var (
	ErrUnhandledEventType            = errors.New("the event is not handled")
	ErrEventUnAssignedMissingData    = errors.New("the (un)assigned event is missing the (un)assigned user")
	ErrEventNotFamedLabeled          = errors.New("the event is missing the famed label")
	ErrRateLimitMissingData          = errors.New("the rate limit is missing data promised by the GitHub API")
	ErrInstallationMissingData       = errors.New("the installation is missing data promised by the GitHub API")
	ErrRepoMissingData               = errors.New("the repo is missing data promised by the GitHub API")
	ErrIssueMissingData              = errors.New("the issue is missing data promised by the GitHub API")
	ErrUserMissingData               = errors.New("the user is missing data promised by the GitHub API")
	ErrIssueCommentMissingData       = errors.New("the issue comment is missing data promised by the GitHub API")
	ErrIssueMissingSeverityLabel     = errors.New("the issue is missing it's severity label")
	ErrIssueMultipleSeverityLabels   = errors.New("the issue has multiple severity labels")
	ErrEventMissingData              = errors.New("the event is missing data promised by the GitHub API")
	ErrPullRequestMissingData        = errors.New("the pull request is missing data promised by the GitHub API")
	ErrRefMissingData                = errors.New("the reference is missing data promised by the GitHub API")
	ErrLabelMissingData              = errors.New("the label is missing data promised by the GitHub API")
	ErrBranchMissingData             = errors.New("the branch is missing data promised by the GitHub API")
	ErrFileContentMissingData        = errors.New("the file content is missing data promised by the GitHub API")
	ErrFileContentUnexpectedEncoding = errors.New("the file content has an unexpected encoding")

	ErrIssueRequestIsMissingID = errors.New("the issue request is missing an ID")
)

Functions

func NewBranch

func NewBranch(branch *github.Branch) (string, error)

func NewCommitHash

func NewCommitHash(ref *github.Reference) (string, error)

Types

type EnrichedIssue

type EnrichedIssue struct {
	Issue
	PullRequest *string
	Events      []IssueEvent
	Comments    []IssueComment
}

func NewEnrichIssue

func NewEnrichIssue(issue Issue, pullRequest *string, events []IssueEvent, comments []IssueComment) EnrichedIssue

type File

type File struct {
	Content string
	SHA     string
}

func NewFile

func NewFile(fileContent *github.RepositoryContent) (File, error)

type Installation

type Installation struct {
	ID      int64
	Account User
}

func NewInstallation

func NewInstallation(installation *github.Installation) (Installation, error)

type InstallationEvent

type InstallationEvent struct {
	Action       string
	Repositories []Repository
	Installation
}

func NewInstallationEvent

func NewInstallationEvent(event *github.InstallationEvent) (InstallationEvent, error)

type InstallationRepositoriesEvent

type InstallationRepositoriesEvent struct {
	Action            string
	Installation      RepositoriesInstallation
	RepositoriesAdded []Repository
}

type Issue

type Issue struct {
	ID           int64
	Number       int
	HTMLURL      string
	Title        string
	State        IssueState
	CreatedAt    time.Time
	ClosedAt     *time.Time
	Assignees    []User
	Severities   []IssueSeverity
	Migrated     bool
	RedTeam      []User
	BountyPoints *int
	// Body and IssueMetadata only present in installation issues and scanners issues.
	Body     *string
	Metadata *IssueMetadata
}

func NewIssue

func NewIssue(issue *github.Issue, owner, repoName string) (Issue, error)

func (*Issue) Severity

func (i *Issue) Severity() (IssueSeverity, error)

Severity returns the issue severity. If 0 or more than one severity are present it returns an error.

type IssueComment

type IssueComment struct {
	ID int64
	User
	Body     string
	Metadata *IssueCommentMetadata
}

IssueComment represents a GitHub comment.

func NewComment

func NewComment(comment *github.IssueComment) (IssueComment, error)

NewComment returns a new IssueComment. If expected data is not available an error is returned.

type IssueCommentMetadata

type IssueCommentMetadata struct {
	Type    IssueCommentType `json:"type"`
	Version string           `json:"version"`
}

func NewIssueCommentMetadata

func NewIssueCommentMetadata(commentType IssueCommentType, version string) IssueCommentMetadata

func ParseIssueCommentMetadata

func ParseIssueCommentMetadata(body string) (IssueCommentMetadata, error)

func (IssueCommentMetadata) String

func (i IssueCommentMetadata) String() (string, error)

type IssueCommentType

type IssueCommentType string

type IssueEvent

type IssueEvent struct {
	ID        int64
	Event     string
	Assignee  *User
	CreatedAt time.Time
}

func NewIssueEvent

func NewIssueEvent(event *github.IssueEvent) (IssueEvent, error)

type IssueEventAction

type IssueEventAction string
const (
	// IssueEventActionClosed represents a GitHub event action triggered when the Actor closed the issue.
	// If the issue was closed by commit message, CommitID holds the SHA1 hash of the commit.
	IssueEventActionClosed IssueEventAction = "closed"
	// IssueEventActionMerged represents a GitHub event action triggered when the Actor merged into master a branch containing a commit mentioning the issue.
	// CommitID holds the SHA1 of the merge commit.
	IssueEventActionMerged IssueEventAction = "merged"
	// IssueEventActionReferenced represents a GitHub event action triggered when the Actor committed to master a commit mentioning the issue in its commit message.
	// CommitID holds the SHA1 of the commit.
	IssueEventActionReferenced IssueEventAction = "referenced"
	// IssueEventActionReopened represents a GitHub event action triggered when the Actor reopened the issue.
	IssueEventActionReopened IssueEventAction = "reopened"
	// IssueEventActionUnlocked represents a GitHub event action triggered when the Actor unlocked the issue.
	IssueEventActionUnlocked IssueEventAction = "unlocked"
	// IssueEventActionLocked represents a GitHub event action triggered when the Actor locked the issue.
	// LockReason holds the reason of locking the issue (if provided while locking).
	IssueEventActionLocked IssueEventAction = "locked"
	// IssueEventActionRenamed represents a GitHub event action triggered when the Actor changed the issue title from Rename.
	// From to Rename.To.
	IssueEventActionRenamed IssueEventAction = "renamed"
	// IssueEventActionMentioned represents a GitHub event action triggered when someone unspecified @mentioned the Actor [sic] in an issue comment body.
	IssueEventActionMentioned IssueEventAction = "mentioned"
	// IssueEventActionAssigned represents a GitHub event action triggered when the Assigner assigned the issue to or removed the assignment from the Assignee.
	IssueEventActionAssigned   IssueEventAction = "assigned"
	IssueEventActionUnassigned IssueEventAction = "unassigned"
	// IssueEventActionLabeled & IssueEventActionUnlabeled represents a GitHub event action triggered when the Actor added or removed the Label from the issue.
	IssueEventActionLabeled   IssueEventAction = "labeled"
	IssueEventActionUnlabeled IssueEventAction = "unlabeled"
	// IssueEventActionMilestoned & IssueEventActionDemilestoned represents a GitHub event action triggered when the Actor added or removed the issue from the Milestone.
	IssueEventActionMilestoned   IssueEventAction = "milestoned"
	IssueEventActionDemilestoned IssueEventAction = "demilestoned"
	// IssueEventActionSubscribed & IssueEventActionUnsubscribed represents a GitHub event action triggered when the Actor subscribed to or unsubscribed from notifications for an issue.
	IssueEventActionSubscribed   IssueEventAction = "subscribed"
	IssueEventActionUnsubscribed IssueEventAction = "unsubscribed"
	// IssueEventActionHeadRefDeleted & IssueEventActionHeadRefRestored represents a GitHub event action triggered when the pull request’s branch was deleted or restored.
	IssueEventActionHeadRefDeleted  IssueEventAction = "head_ref_deleted"
	IssueEventActionHeadRefRestored IssueEventAction = "head_ref_restored"
	// IssueEventActionReviewDismissed represents a GitHub event action triggered when the review was dismissed and `DismissedReview` will be populated below.
	IssueEventActionReviewDismissed IssueEventAction = "review_dismissed"
	// IssueEventActionReviewRequested represents a GitHub event action triggered when the Actor requested or removed the request for a review.
	// RequestedReviewer and ReviewRequester will be populated below.
	IssueEventActionReviewRequested IssueEventAction = "review_requested"

	// IssueEventUnFamed represents an internal Famed event triggered when the famed label is removed from an issue.
	IssueEventUnFamed IssueEventAction = "unfamed"
)

type IssueMetadata

type IssueMetadata struct {
	// ID represents an identifier for Famed issues it can be any string but should be unique per repository.
	ID      *string   `json:"id,omitempty"`
	Type    IssueType `json:"type"`
	Version string    `json:"version"`
}

IssueMetadata represent a Issue's metadata.

func NewIssueMetadata

func NewIssueMetadata(ID string, commentType IssueType, version string) IssueMetadata

NewIssueMetadata creates a new IssueMetadata struct.

func ParseIssueMetadata

func ParseIssueMetadata(text string) (IssueMetadata, error)

ParseIssueMetadata return the IssueMetadata parsed from a string.

func (IssueMetadata) HasID

func (i IssueMetadata) HasID() bool

HasID return true if the issue metadata has an ID.

func (IssueMetadata) IDEquals

func (i IssueMetadata) IDEquals(ID string) bool

IDEquals return true if the given string is equal to the IssueMetadata ID.

func (IssueMetadata) String

func (i IssueMetadata) String() (string, error)

String return the string representation of the IssueMetadata.

type IssueRequest

type IssueRequest struct {
	Title    string
	Body     string
	Labels   []string
	State    IssueState
	Metadata IssueMetadata
}

func NewIssueRequest

func NewIssueRequest(title, body string, labels []string, state IssueState, metadata IssueMetadata) IssueRequest

func (*IssueRequest) GitHubIssueRequestWithLabels

func (i *IssueRequest) GitHubIssueRequestWithLabels(labels []string) (*github.IssueRequest, error)

type IssueSeverity

type IssueSeverity string
const (
	// Info represents a CVSS of 0.
	Info IssueSeverity = "info"
	// Low represents a CVSS of 0.1-3.9.
	Low IssueSeverity = "low"
	// Medium represents a CVSS of 4.0-6.9.
	Medium IssueSeverity = "medium"
	// High represents a CVSS of 7.0-8.9.
	High IssueSeverity = "high"
	// Critical represents a CVSS of 9.0-10.0.
	Critical IssueSeverity = "critical"
)

type IssueState

type IssueState string
const (
	IssueStateAll    IssueState = "all"
	IssueStateOpened IssueState = "open"
	IssueStateClosed IssueState = "closed"
)

type IssueType

type IssueType string

IssueType represents the issue's type.

const (
	// InstallationIssueType represents an installation issue's type.
	InstallationIssueType IssueType = "installation"
	ScannerIssueType      IssueType = "scanners"
)

type IssuesEvent

type IssuesEvent struct {
	Action string
	Repo   Repository
	Issue
}

func NewIssuesEvent

func NewIssuesEvent(event *github.IssuesEvent, famedLabel string) (IssuesEvent, error)

NewIssuesEvent validates issue events received through the webhook. The changes implied by the event in the case of (un)assigned are mapped to the issue to provide an after event issue state, this is done because of a suspected bug in the GitHub API.

type Label

type Label struct {
	Name        string
	Color       string
	Description string
}

func NewLabel

func NewLabel(label *github.Label) (Label, error)

type MarketplacePurchaseEvent

type MarketplacePurchaseEvent struct{}

type PullRequest

type PullRequest struct {
	HTMLURL   string
	CreatedAt time.Time
	State     PullRequestState
	Metadata  *PullRequestMetadata
}

func NewPullRequest

func NewPullRequest(pullRequest *github.PullRequest) (PullRequest, error)

type PullRequestMetadata

type PullRequestMetadata struct {
	Type    PullRequestType `json:"type"`
	Version string          `json:"version"`
}

func NewPullRequestMetadata

func NewPullRequestMetadata(commentType PullRequestType, version string) PullRequestMetadata

func ParsePullRequestMetadata

func ParsePullRequestMetadata(text string) (PullRequestMetadata, error)

func (PullRequestMetadata) String

func (i PullRequestMetadata) String() (string, error)

type PullRequestState

type PullRequestState string
const (
	PullRequestStateOpen   PullRequestState = "open"
	PullRequestStateClosed PullRequestState = "closed"
	PullRequestStateAll    PullRequestState = "all"
)

type PullRequestType

type PullRequestType string
const (
	InstallationPullRequestType PullRequestType = "installation"
)

type Rate

type Rate struct {
	Limit     int       `json:"limit"`
	Remaining int       `json:"remaining"`
	Reset     time.Time `json:"reset"`
}

type RateLimits

type RateLimits struct {
	Core   Rate `json:"core"`
	Search Rate `json:"search"`
}

func NewRateLimit

func NewRateLimit(rateLimits *github.RateLimits) (RateLimits, error)

type RepositoriesInstallation

type RepositoriesInstallation struct {
	Account User
}

type Repository

type Repository struct {
	Name          string
	Owner         User
	HTMLURL       string
	DefaultBranch string
}

func NewRepo

func NewRepo(repo *github.Repository) (Repository, error)

type User

type User struct {
	Login     string
	AvatarURL string
	HTMLURL   string
}

func NewUser

func NewUser(user *github.User) (User, error)

Jump to

Keyboard shortcuts

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