cmd

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package cmd implements a command line interface for summarizing GitHub pull request metrics.

Index

Constants

View Source
const (
	// Extension version. Displayed when `--version` flag is used.
	Version = "1.1.0"
	// Default number of days in the past to look for pull requests
	// within a repository.
	DefaultDaysBack = 10
	// Default date format to use when displaying dates.
	DefaultDateFormat = "2006-01-02"
)
View Source
const (
	// Default representation of an empty table cell.
	DefaultEmptyCell = "--"
	// Default number of search results per query.
	DefaultResultCount = 100
	// Pull request review approved state.
	ReviewApprovedState = "APPROVED"
)

Variables

View Source
var RootCmd = &cobra.Command{
	Use:   "gh-metrics",
	Short: "gh-metrics: provide summary pull request metrics",
	Run: func(cmd *cobra.Command, args []string) {
		owner, _ := cmd.Flags().GetString("owner")
		repository, _ := cmd.Flags().GetString("repo")
		startDate, _ := cmd.Flags().GetString("start")
		endDate, _ := cmd.Flags().GetString("end")
		onlyWeekdays, _ := cmd.Flags().GetBool("only-weekdays")
		csvFormat, _ := cmd.Flags().GetBool("csv")

		version, _ := cmd.Flags().GetBool("version")
		if version {
			fmt.Println("gh-metrics", Version)
			os.Exit(0)
		}

		var workdayFunc cal.WorkdayFn
		if onlyWeekdays {
			workdayFunc = WorkdayOnlyWeekdays
		} else {
			workdayFunc = WorkdayAllDays
		}

		calendar := &cal.BusinessCalendar{
			WorkdayFunc:      workdayFunc,
			WorkdayStartFunc: WorkdayStart,
			WorkdayEndFunc:   WorkdayEnd,
		}

		ui := &UI{
			Owner:      owner,
			Repository: repository,
			StartDate:  startDate,
			EndDate:    endDate,
			CSVFormat:  csvFormat,
			Calendar:   calendar,
		}

		fmt.Println(ui.PrintMetrics())
	},
}

Functions

func Execute

func Execute()

func WorkdayAllDays added in v0.3.0

func WorkdayAllDays(d time.Time) bool

WorkdayAllDays returns true regardless of the given day, as currently all days are considered workdays.

func WorkdayEnd added in v0.3.0

func WorkdayEnd(d time.Time) time.Time

WorkdayEnd determines the end of a workday by returning the same day, but at the last second.

func WorkdayOnlyWeekdays added in v0.3.0

func WorkdayOnlyWeekdays(d time.Time) bool

WorkdayOnlyWeekdays returns true if the given day is a weekday, otherwise returns false.

func WorkdayStart added in v0.3.0

func WorkdayStart(d time.Time) time.Time

WorkdayStart determines the beginning of a workday by returning the same day, but at the first second.

Types

type Author added in v1.0.0

type Author struct {
	Login string
}

type Comments

type Comments struct {
	TotalCount int
}

type Commit added in v0.3.0

type Commit struct {
	CommittedDate string
}

type CommitNodes added in v0.3.0

type CommitNodes []struct {
	Commit Commit
}

type Commits

type Commits struct {
	TotalCount int
	Nodes      CommitNodes
}

type MetricsGQLQuery

type MetricsGQLQuery struct {
	Search struct {
		PageInfo PageInfo
		Nodes    []struct {
			PullRequest struct {
				Author        Author
				Additions     int
				Deletions     int
				Number        int
				CreatedAt     string
				ChangedFiles  int
				IsDraft       bool
				MergedAt      string
				Participants  Participants
				Comments      Comments
				Reviews       Reviews       `graphql:"reviews(first: 50, states: [APPROVED, CHANGES_REQUESTED, COMMENTED])"`
				Commits       Commits       `graphql:"commits(first: 1)"`
				TimelineItems TimelineItems `graphql:"timelineItems(first: 1, itemTypes: [READY_FOR_REVIEW_EVENT])"`
			} `graphql:"... on PullRequest"`
		}
	} `graphql:"search(query: $query, type: ISSUE, last: $resultCount, after: $afterCursor)"`
}

type PageInfo added in v1.1.0

type PageInfo struct {
	HasNextPage bool
	EndCursor   string
}

type Participants

type Participants struct {
	TotalCount int
}

type ReadyForReviewEvent added in v1.0.0

type ReadyForReviewEvent struct {
	CreatedAt string
}

type ReviewNodes added in v0.3.0

type ReviewNodes []struct {
	Author    Author
	CreatedAt string
	State     string
}

type Reviews

type Reviews struct {
	TotalCount int
	Nodes      ReviewNodes
}

type TimelineItemNodes added in v1.0.0

type TimelineItemNodes []struct {
	ReadyForReviewEvent ReadyForReviewEvent `graphql:"... on ReadyForReviewEvent"`
}

type TimelineItems added in v1.0.0

type TimelineItems struct {
	TotalCount int
	Nodes      TimelineItemNodes
}

type UI added in v0.3.0

type UI struct {
	Owner      string
	Repository string
	StartDate  string
	EndDate    string
	CSVFormat  bool
	Calendar   *cal.BusinessCalendar
}

func (*UI) PrintMetrics added in v0.3.0

func (ui *UI) PrintMetrics() string

PrintMetrics returns a string representation of the metrics summary for a set of pull requests determined by the supplied date range, using DefaultResultCount.

Jump to

Keyboard shortcuts

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