shared

package
v2.49.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 15 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// Run statuses
	Queued     Status = "queued"
	Completed  Status = "completed"
	InProgress Status = "in_progress"
	Requested  Status = "requested"
	Waiting    Status = "waiting"

	// Run conclusions
	ActionRequired Conclusion = "action_required"
	Cancelled      Conclusion = "cancelled"
	Failure        Conclusion = "failure"
	Neutral        Conclusion = "neutral"
	Skipped        Conclusion = "skipped"
	Stale          Conclusion = "stale"
	StartupFailure Conclusion = "startup_failure"
	Success        Conclusion = "success"
	TimedOut       Conclusion = "timed_out"

	AnnotationFailure Level = "failure"
	AnnotationWarning Level = "warning"
)

Variables

View Source
var AllStatuses = []string{
	"queued",
	"completed",
	"in_progress",
	"requested",
	"waiting",
	"action_required",
	"cancelled",
	"failure",
	"neutral",
	"skipped",
	"stale",
	"startup_failure",
	"success",
	"timed_out",
}
View Source
var FailedJobAnnotations []Annotation = []Annotation{
	{
		JobName:   "sad job",
		Message:   "the job is sad",
		Path:      "blaze.py",
		Level:     "failure",
		StartLine: 420,
	},
}
View Source
var RunFields = []string{
	"name",
	"displayTitle",
	"headBranch",
	"headSha",
	"createdAt",
	"updatedAt",
	"startedAt",
	"status",
	"conclusion",
	"event",
	"number",
	"databaseId",
	"workflowDatabaseId",
	"workflowName",
	"url",
}
View Source
var SingleRunFields = append(RunFields, "jobs")
View Source
var TestRunStartTime, _ = time.Parse("2006-01-02 15:04:05", "2021-02-23 04:51:00")
View Source
var TestWorkflow workflowShared.Workflow = workflowShared.Workflow{
	Name: "CI",
	ID:   123,
}
View Source
var WorkflowRuns []Run = []Run{
	TestRun(2, InProgress, ""),
	SuccessfulRun,
	FailedRun,
}

Functions

func AnnotationSymbol

func AnnotationSymbol(cs *iostreams.ColorScheme, a Annotation) string

func IsFailureState

func IsFailureState(c Conclusion) bool

func PullRequestForRun

func PullRequestForRun(client *api.Client, repo ghrepo.Interface, run Run) (int, error)

func RenderAnnotations

func RenderAnnotations(cs *iostreams.ColorScheme, annotations []Annotation) string

func RenderJobs

func RenderJobs(cs *iostreams.ColorScheme, jobs []Job, verbose bool) string

func RenderRunHeader

func RenderRunHeader(cs *iostreams.ColorScheme, run Run, ago, prNumber string, attempt uint64) string

func SelectRun added in v2.27.0

func SelectRun(p Prompter, cs *iostreams.ColorScheme, runs []Run) (string, error)

SelectRun prompts the user to select a run from a list of runs by using the recommended prompter interface

func Symbol

func Symbol(cs *iostreams.ColorScheme, status Status, conclusion Conclusion) (string, colorFunc)

Types

type Annotation

type Annotation struct {
	JobName   string
	Message   string
	Path      string
	Level     Level `json:"annotation_level"`
	StartLine int   `json:"start_line"`
}

func GetAnnotations

func GetAnnotations(client *api.Client, repo ghrepo.Interface, job Job) ([]Annotation, error)

type Artifact

type Artifact struct {
	Name        string `json:"name"`
	Size        uint64 `json:"size_in_bytes"`
	DownloadURL string `json:"archive_download_url"`
	Expired     bool   `json:"expired"`
}

func ListArtifacts

func ListArtifacts(httpClient *http.Client, repo ghrepo.Interface, runID string) ([]Artifact, error)

type CheckRun

type CheckRun struct {
	ID int64
}

type Commit

type Commit struct {
	Message string
}

type Conclusion

type Conclusion string

type FilterOptions added in v2.5.0

type FilterOptions struct {
	Branch     string
	Actor      string
	WorkflowID int64
	// avoid loading workflow name separately and use the provided one
	WorkflowName string
	Status       string
	Event        string
	Created      string
	Commit       string
}

type Job

type Job struct {
	ID          int64
	Status      Status
	Conclusion  Conclusion
	Name        string
	Steps       Steps
	StartedAt   time.Time `json:"started_at"`
	CompletedAt time.Time `json:"completed_at"`
	URL         string    `json:"html_url"`
	RunID       int64     `json:"run_id"`
}
var FailedJob Job = Job{
	ID:          20,
	Status:      Completed,
	Conclusion:  Failure,
	Name:        "sad job",
	StartedAt:   TestRunStartTime,
	CompletedAt: TestRunStartTime.Add(time.Minute*4 + time.Second*34),
	URL:         "https://github.com/jobs/20",
	RunID:       1234,
	Steps: []Step{
		{
			Name:       "barf the quux",
			Status:     Completed,
			Conclusion: Success,
			Number:     1,
		},
		{
			Name:       "quux the barf",
			Status:     Completed,
			Conclusion: Failure,
			Number:     2,
		},
	},
}
var SuccessfulJob Job = Job{
	ID:          10,
	Status:      Completed,
	Conclusion:  Success,
	Name:        "cool job",
	StartedAt:   TestRunStartTime,
	CompletedAt: TestRunStartTime.Add(time.Minute*4 + time.Second*34),
	URL:         "https://github.com/jobs/10",
	RunID:       3,
	Steps: []Step{
		{
			Name:       "fob the barz",
			Status:     Completed,
			Conclusion: Success,
			Number:     1,
		},
		{
			Name:       "barz the fob",
			Status:     Completed,
			Conclusion: Success,
			Number:     2,
		},
	},
}

func GetJob added in v2.6.0

func GetJob(client *api.Client, repo ghrepo.Interface, jobID string) (*Job, error)

func GetJobs

func GetJobs(client *api.Client, repo ghrepo.Interface, run *Run, attempt uint64) ([]Job, error)

type JobsPayload

type JobsPayload struct {
	TotalCount int `json:"total_count"`
	Jobs       []Job
}

type Level

type Level string

type Prompter added in v2.30.0

type Prompter interface {
	Select(string, string, []string) (int, error)
}

type Repo

type Repo struct {
	Owner struct {
		Login string
	}
	Name string
}

type Run

type Run struct {
	Name         string    `json:"name"` // the semantics of this field are unclear
	DisplayTitle string    `json:"display_title"`
	CreatedAt    time.Time `json:"created_at"`
	UpdatedAt    time.Time `json:"updated_at"`
	StartedAt    time.Time `json:"run_started_at"`
	Status       Status
	Conclusion   Conclusion
	Event        string
	ID           int64

	WorkflowID     int64  `json:"workflow_id"`
	Number         int64  `json:"run_number"`
	Attempts       uint64 `json:"run_attempt"`
	HeadBranch     string `json:"head_branch"`
	JobsURL        string `json:"jobs_url"`
	HeadCommit     Commit `json:"head_commit"`
	HeadSha        string `json:"head_sha"`
	URL            string `json:"html_url"`
	HeadRepository Repo   `json:"head_repository"`
	Jobs           []Job  `json:"-"` // populated by GetJobs
	// contains filtered or unexported fields
}
var FailedRun Run = TestRun(1234, Completed, Failure)
var SuccessfulRun Run = TestRun(3, Completed, Success)

func GetRun

func GetRun(client *api.Client, repo ghrepo.Interface, runID string, attempt uint64) (*Run, error)

func GetRunsWithFilter

func GetRunsWithFilter(client *api.Client, repo ghrepo.Interface, opts *FilterOptions, limit int, f func(Run) bool) ([]Run, error)

GetRunsWithFilter fetches 50 runs from the API and filters them in-memory

func TestRun

func TestRun(id int64, s Status, c Conclusion) Run

func TestRunWithCommit added in v2.16.0

func TestRunWithCommit(id int64, s Status, c Conclusion, commit string) Run

func (*Run) Duration added in v2.14.3

func (r *Run) Duration(now time.Time) time.Duration

func (*Run) ExportData added in v2.4.0

func (r *Run) ExportData(fields []string) map[string]interface{}

func (*Run) StartedTime added in v2.14.3

func (r *Run) StartedTime() time.Time

func (Run) Title added in v2.16.0

func (r Run) Title() string

Title is the display title for a run, falling back to the commit subject if unavailable

func (Run) WorkflowName added in v2.16.0

func (r Run) WorkflowName() string

WorkflowName returns the human-readable name of the workflow that this run belongs to. TODO: consider lazy-loading the underlying API data to avoid extra API calls unless necessary

type RunsPayload

type RunsPayload struct {
	TotalCount   int   `json:"total_count"`
	WorkflowRuns []Run `json:"workflow_runs"`
}

func GetRuns

func GetRuns(client *api.Client, repo ghrepo.Interface, opts *FilterOptions, limit int) (*RunsPayload, error)

type Status

type Status string

type Step

type Step struct {
	Name       string
	Status     Status
	Conclusion Conclusion
	Number     int
	Log        *zip.File
}

type Steps

type Steps []Step

func (Steps) Len

func (s Steps) Len() int

func (Steps) Less

func (s Steps) Less(i, j int) bool

func (Steps) Swap

func (s Steps) Swap(i, j int)

type TestExporter added in v2.34.0

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

func MakeTestExporter added in v2.34.0

func MakeTestExporter(fields []string, wh func(io *iostreams.IOStreams, data interface{}) error) *TestExporter

func (*TestExporter) Fields added in v2.34.0

func (t *TestExporter) Fields() []string

func (*TestExporter) Write added in v2.34.0

func (t *TestExporter) Write(io *iostreams.IOStreams, data interface{}) error

Jump to

Keyboard shortcuts

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