1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-22 22:59:43 +02:00

Use full names in Github commit reporting

This commit is contained in:
Elliott Stoneham 2016-09-05 12:50:18 +01:00
parent e737d278b9
commit b652bc53f1
3 changed files with 54 additions and 41 deletions

View file

@ -33,6 +33,7 @@ type githubCommit struct {
Date string `json:"date"` Date string `json:"date"`
BinDate time.Time `json:"-"` // only used for sorting BinDate time.Time `json:"-"` // only used for sorting
ShowDate bool `json:"ShowDate"` ShowDate bool `json:"ShowDate"`
Login string `json:"login"`
Name string `json:"name"` Name string `json:"name"`
Avatar string `json:"avatar"` Avatar string `json:"avatar"`
ShowUser bool `json:"ShowUser"` ShowUser bool `json:"ShowUser"`
@ -42,6 +43,7 @@ type githubCommit struct {
type githubAuthorStats struct { type githubAuthorStats struct {
Author string `json:"author"` Author string `json:"author"`
Login string `json:"login"`
Avatar string `json:"avatar"` Avatar string `json:"avatar"`
CommitCount int `json:"commitCount"` CommitCount int `json:"commitCount"`
Repos []string `json:"repos"` Repos []string `json:"repos"`
@ -119,6 +121,8 @@ func getCommits(client *gogithub.Client, config *githubConfig) ([]githubCommit,
} }
sort.Sort(branchByID(config.Lists)) sort.Sort(branchByID(config.Lists))
config.UserNames = make(map[string]string)
authorStats := make(map[string]githubAuthorStats) authorStats := make(map[string]githubAuthorStats)
contribBranch := make(map[string]map[string]struct{}) contribBranch := make(map[string]map[string]struct{})
@ -158,48 +162,53 @@ func getCommits(client *gogithub.Client, config *githubConfig) ([]githubCommit,
} }
} }
// TODO(elliott5) remove this comment when it is clear we should not use committer
/*
var a, l string
if v.Committer != nil {
if v.Committer.Login != nil {
l = *v.Committer.Login
}
if v.Committer.AvatarURL != nil {
a = *v.Committer.AvatarURL
}
}
if a == "" {
a = githubGravatar
}
*/
if v.HTMLURL != nil { if v.HTMLURL != nil {
u = *v.HTMLURL u = *v.HTMLURL
} }
// update of author commits // author commits
al, aa := "", githubGravatar al, an, aa := "", "", githubGravatar
if v.Author != nil { if v.Author != nil {
if v.Author.Login != nil { if v.Author.Login != nil {
al = *v.Author.Login al = *v.Author.Login
an = al
if content, found := config.UserNames[al]; found {
if len(content) > 0 {
an = content
} }
} else {
usr, _, err := client.Users.Get(al)
if err == nil {
if usr.Name != nil {
if len(*usr.Name) > 0 {
config.UserNames[al] = *usr.Name
an = *usr.Name
}
}
} else {
config.UserNames[al] = al // don't look again for a missing name
}
}
}
if v.Author.AvatarURL != nil { if v.Author.AvatarURL != nil {
aa = *v.Author.AvatarURL aa = *v.Author.AvatarURL
} }
} }
l := al // use author not committer l := al // use author login
a := aa // ditto
overall = append(overall, githubCommit{ overall = append(overall, githubCommit{
Owner: orb.Owner, Owner: orb.Owner,
Repo: orb.Repo, Repo: orb.Repo,
Branch: orb.Name, Branch: orb.Name,
Name: l, Name: an,
Login: l,
Message: m, Message: m,
Date: d, Date: d,
BinDate: bd, BinDate: bd,
Avatar: a, Avatar: aa,
URL: template.URL(u), URL: template.URL(u),
}) })
@ -209,8 +218,9 @@ func getCommits(client *gogithub.Client, config *githubConfig) ([]githubCommit,
contribBranch[l][thisBranch] = struct{}{} contribBranch[l][thisBranch] = struct{}{}
cum := authorStats[l] cum := authorStats[l]
cum.Author = l cum.Login = l
cum.Avatar = a cum.Author = an
cum.Avatar = aa
cum.CommitCount++ cum.CommitCount++
// TODO review, this code removed as too slow // TODO review, this code removed as too slow
//cmt, _, err := client.Repositories.GetCommit(orb.Owner, orb.Repo, *v.SHA) //cmt, _, err := client.Repositories.GetCommit(orb.Owner, orb.Repo, *v.SHA)
@ -250,7 +260,7 @@ func getCommits(client *gogithub.Client, config *githubConfig) ([]githubCommit,
retStats := make([]githubAuthorStats, 0, len(authorStats)) retStats := make([]githubAuthorStats, 0, len(authorStats))
for _, v := range authorStats { for _, v := range authorStats {
repos := contribBranch[v.Author] repos := contribBranch[v.Login]
v.Repos = make([]string, 0, len(repos)) v.Repos = make([]string, 0, len(repos))
for r := range repos { for r := range repos {
v.Repos = append(v.Repos, r) v.Repos = append(v.Repos, r)
@ -283,7 +293,8 @@ func renderCommits(payload *githubRender, c *githubConfig) error {
for i := range payload.Issues { for i := range payload.Issues {
var author int var author int
for a := range payload.AuthorStats { for a := range payload.AuthorStats {
if payload.AuthorStats[a].Author == payload.Issues[i].Name { if payload.AuthorStats[a].Login == payload.Issues[i].Name ||
(payload.AuthorStats[a].Login == "" && payload.Issues[i].Name == unassignedIssue) {
author = a author = a
goto found goto found
} }

View file

@ -85,6 +85,7 @@ func (s sharedLabelsSort) Less(i, j int) bool { return s[i].Name < s[j].Name }
const ( const (
tagIssuesData = "issuesData" tagIssuesData = "issuesData"
issuesTimeFormat = "January 2 2006, 15:04" issuesTimeFormat = "January 2 2006, 15:04"
unassignedIssue = "(unassigned)"
) )
func init() { func init() {
@ -133,7 +134,7 @@ func getIssues(client *gogithub.Client, config *githubConfig) ([]githubIssue, er
} }
for _, v := range guff { for _, v := range guff {
n := "(unassigned)" n := unassignedIssue
av := githubGravatar av := githubGravatar
ptr := v.Assignee ptr := v.Assignee
if ptr != nil { if ptr != nil {

View file

@ -97,6 +97,7 @@ type githubConfig struct {
Lists []githubBranch `json:"lists,omitempty"` Lists []githubBranch `json:"lists,omitempty"`
ReportOrder []string `json:"-"` ReportOrder []string `json:"-"`
DateMessage string `json:"-"` DateMessage string `json:"-"`
UserNames map[string]string `json:"UserNames"`
} }
func (c *githubConfig) Clean() { func (c *githubConfig) Clean() {