contribution

package
v0.0.0-...-69a7eb6 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CSVColumn

type CSVColumn struct {
	PullRequest string
	Approve     string
	Comment     string
}

func (CSVColumn) Row

func (c CSVColumn) Row() []string

type CSVRow

type CSVRow struct {
	CreatedAt    string
	Owner        string
	Repository   string
	Total        CSVColumn
	Contributors map[string]CSVColumn
}

func (CSVRow) Row

func (c CSVRow) Row(contributors []string) []string

type Contributor

type Contributor struct {
	Name        string
	CreatedAt   string
	PullRequest int
	Approve     int
	Comment     int
}

type ContributorKey

type ContributorKey struct {
	Name      string
	CreatedAt string
}

func (ContributorKey) MarshalText

func (k ContributorKey) MarshalText() ([]byte, error)

type Contributors

type Contributors map[ContributorKey]*Contributor

func (Contributors) Get

func (c Contributors) Get(name string, pr *github.PullRequest) *Contributor

type Owner

type Owner struct {
	Name         string
	Start        time.Time
	End          time.Time
	Repositories []*Repository
	Contributors map[string]struct{}
}

func NewOwner

func NewOwner(name string, start, end time.Time) *Owner

func (*Owner) AddRepository

func (o *Owner) AddRepository(repo *Repository)

func (*Owner) CSV

func (o *Owner) CSV() (string, error)
Example
o := NewOwner("foo", time.Now(), time.Now())

name := func(s string) *string {
	return &s
}

bob := gogithub.User{
	Login: name("bob"),
}

alice := gogithub.User{
	Login: name("alice"),
}

fred := gogithub.User{
	Login: name("fred"),
}

barney := gogithub.User{
	Login: name("barney"),
}

approved := "APPROVED"

utc, _ := time.LoadLocation("UTC")
now := time.Date(2020, 6, 17, 0, 0, 0, 0, utc)

lastMonth := time.Date(2020, 5, 17, 0, 0, 0, 0, utc)

bar := NewRepository("bar", []*github.Contribution{
	{
		PullRequest: &gogithub.PullRequest{
			CreatedAt: &now,
			User:      &bob,
		},
		Reviews: []*gogithub.PullRequestReview{
			{
				User:  &alice,
				State: &approved,
			},
		},
		Comments: []*gogithub.PullRequestComment{
			{
				User: &fred,
			},
			{
				User: &barney,
			},
		},
		IssueComments: []*gogithub.IssueComment{
			{
				User: &fred,
			},
		},
	},
	{
		PullRequest: &gogithub.PullRequest{
			CreatedAt: &now,
			User:      &barney,
		},
		Reviews: []*gogithub.PullRequestReview{
			{
				User:  &bob,
				State: &approved,
			},
		},
		Comments: []*gogithub.PullRequestComment{
			{
				User: &fred,
			},
			{
				User: &barney,
			},
		},
	},
	{
		PullRequest: &gogithub.PullRequest{
			CreatedAt: &lastMonth,
			User:      &alice,
		},
		Reviews: []*gogithub.PullRequestReview{
			{
				User:  &bob,
				State: &approved,
			},
		},
	},
})

o.AddRepository(bar)

csv, err := o.CSV()
if err != nil {
	fmt.Println(err)
}

fmt.Println(csv)
Output:

created_at,owner,repository,pull_request,approve,comment,alice.pull_request,alice.approve,alice.comment,barney.pull_request,barney.approve,barney.comment,bob.pull_request,bob.approve,bob.comment,fred.pull_request,fred.approve,fred.comment
2020-05,foo,bar,1,1,0,1,0,0,,,,0,1,0,,,
2020-06,foo,bar,2,2,5,0,1,0,1,0,2,1,1,0,0,0,3

func (*Owner) JSON

func (o *Owner) JSON() (string, error)

type Repository

type Repository struct {
	Name         string
	PullRequest  int
	Contributors Contributors
}

func NewRepository

func NewRepository(name string, contrib []*github.Contribution) *Repository

func (*Repository) Rows

func (r *Repository) Rows(owner string, contributorsName []string) []CSVRow

Jump to

Keyboard shortcuts

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