diff --git a/core/section/github/commits.go b/core/section/github/commits.go index f91cb871..f425fb67 100644 --- a/core/section/github/commits.go +++ b/core/section/github/commits.go @@ -33,6 +33,7 @@ type githubCommit struct { Date string `json:"date"` BinDate time.Time `json:"-"` // only used for sorting ShowDate bool `json:"ShowDate"` + Login string `json:"login"` Name string `json:"name"` Avatar string `json:"avatar"` ShowUser bool `json:"ShowUser"` @@ -42,6 +43,7 @@ type githubCommit struct { type githubAuthorStats struct { Author string `json:"author"` + Login string `json:"login"` Avatar string `json:"avatar"` CommitCount int `json:"commitCount"` Repos []string `json:"repos"` @@ -119,6 +121,8 @@ func getCommits(client *gogithub.Client, config *githubConfig) ([]githubCommit, } sort.Sort(branchByID(config.Lists)) + config.UserNames = make(map[string]string) + authorStats := make(map[string]githubAuthorStats) 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 { u = *v.HTMLURL } - // update of author commits - al, aa := "", githubGravatar + // author commits + al, an, aa := "", "", githubGravatar if v.Author != nil { if v.Author.Login != nil { 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 { aa = *v.Author.AvatarURL } } - l := al // use author not committer - a := aa // ditto + l := al // use author login overall = append(overall, githubCommit{ Owner: orb.Owner, Repo: orb.Repo, Branch: orb.Name, - Name: l, + Name: an, + Login: l, Message: m, Date: d, BinDate: bd, - Avatar: a, + Avatar: aa, URL: template.URL(u), }) @@ -209,8 +218,9 @@ func getCommits(client *gogithub.Client, config *githubConfig) ([]githubCommit, contribBranch[l][thisBranch] = struct{}{} cum := authorStats[l] - cum.Author = l - cum.Avatar = a + cum.Login = l + cum.Author = an + cum.Avatar = aa cum.CommitCount++ // TODO review, this code removed as too slow //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)) for _, v := range authorStats { - repos := contribBranch[v.Author] + repos := contribBranch[v.Login] v.Repos = make([]string, 0, len(repos)) for r := range repos { v.Repos = append(v.Repos, r) @@ -283,7 +293,8 @@ func renderCommits(payload *githubRender, c *githubConfig) error { for i := range payload.Issues { var author int 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 goto found } diff --git a/core/section/github/issues.go b/core/section/github/issues.go index b3647885..9afcdb8a 100644 --- a/core/section/github/issues.go +++ b/core/section/github/issues.go @@ -85,6 +85,7 @@ func (s sharedLabelsSort) Less(i, j int) bool { return s[i].Name < s[j].Name } const ( tagIssuesData = "issuesData" issuesTimeFormat = "January 2 2006, 15:04" + unassignedIssue = "(unassigned)" ) func init() { @@ -133,7 +134,7 @@ func getIssues(client *gogithub.Client, config *githubConfig) ([]githubIssue, er } for _, v := range guff { - n := "(unassigned)" + n := unassignedIssue av := githubGravatar ptr := v.Assignee if ptr != nil { diff --git a/core/section/github/model.go b/core/section/github/model.go index 7e45be4d..56133b9e 100644 --- a/core/section/github/model.go +++ b/core/section/github/model.go @@ -83,20 +83,21 @@ type githubLabel struct { } type githubConfig struct { - Token string `json:"-"` // NOTE very important that the secret Token is not leaked to the client side, so "-" - UserID string `json:"userId"` - PageID string `json:"pageId"` - Owner string `json:"owner_name"` - BranchSince string `json:"branchSince,omitempty"` - SincePtr *time.Time `json:"-"` - Since string `json:"-"` - BranchLines int `json:"branchLines,omitempty,string"` - OwnerInfo githubOwner `json:"owner"` - ClientID string `json:"clientId"` - CallbackURL string `json:"callbackUrl"` - Lists []githubBranch `json:"lists,omitempty"` - ReportOrder []string `json:"-"` - DateMessage string `json:"-"` + Token string `json:"-"` // NOTE very important that the secret Token is not leaked to the client side, so "-" + UserID string `json:"userId"` + PageID string `json:"pageId"` + Owner string `json:"owner_name"` + BranchSince string `json:"branchSince,omitempty"` + SincePtr *time.Time `json:"-"` + Since string `json:"-"` + BranchLines int `json:"branchLines,omitempty,string"` + OwnerInfo githubOwner `json:"owner"` + ClientID string `json:"clientId"` + CallbackURL string `json:"callbackUrl"` + Lists []githubBranch `json:"lists,omitempty"` + ReportOrder []string `json:"-"` + DateMessage string `json:"-"` + UserNames map[string]string `json:"UserNames"` } func (c *githubConfig) Clean() {