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

Add issue creator real names

This commit is contained in:
Elliott Stoneham 2016-09-05 14:51:10 +01:00
parent 049ff73825
commit b419bd2d52
4 changed files with 34 additions and 21 deletions

View file

@ -171,26 +171,7 @@ func getCommits(client *gogithub.Client, config *githubConfig) ([]githubCommit,
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
}
}
an = getUserName(client, config, al)
}
if v.Author.AvatarURL != nil {
@ -315,6 +296,8 @@ func renderCommits(payload *githubRender, c *githubConfig) error {
payload.HasAuthorStats = len(payload.AuthorStats) > 0
sort.Sort(asToSort(payload.AuthorStats))
payload.NumContributors = len(payload.AuthorStats) - 1
return nil
}

View file

@ -28,6 +28,7 @@ type githubIssue struct {
Message string `json:"message"`
URL template.URL `json:"url"`
Name string `json:"name"`
Creator string `json:"creator"`
Avatar string `json:"avatar"`
Labels template.HTML `json:"labels"`
LabelNames []string `json:"labelNames"`
@ -152,6 +153,7 @@ func getIssues(client *gogithub.Client, config *githubConfig) ([]githubIssue, er
l, ln, lc := wrapLabels(v.Labels)
ret = append(ret, githubIssue{
Name: n,
Creator: getUserName(client, config, *v.User.Login),
Avatar: av,
Message: *v.Title,
Date: v.CreatedAt.Format(issuesTimeFormat),

View file

@ -73,7 +73,7 @@ const (
<td style="width:40%;">
<h6>{{$data.Repo}}</h6> <br>
<span class="date-meta">opened on {{$data.Date}} by {{$data.Name}}</span>
<span class="date-meta">{{$data.Creator}} opened on {{$data.Date}}</span>
</td>
</tr>
{{end}}

View file

@ -45,6 +45,7 @@ type githubRender struct {
ClosedPRs int `json:"closedPRs"`
AuthorStats []githubAuthorStats `json:"authorStats"`
HasAuthorStats bool `json:"hasAuthorStats"`
NumContributors int `json:"numContributors"`
}
type report struct {
@ -139,6 +140,11 @@ func (c *githubConfig) Clean() {
if lastItem < len(c.Lists) {
c.Lists[lastItem].Comma = false
}
if c.UserNames == nil {
c.UserNames = make(map[string]string)
}
}
type githubCallbackT struct {
@ -156,3 +162,25 @@ func repoName(branchName string) string {
}
return pieces[0]
}
func getUserName(client *gogithub.Client, config *githubConfig, login string) (fullName string) {
an := login
if content, found := config.UserNames[login]; found {
if len(content) > 0 {
an = content
}
} else {
usr, _, err := client.Users.Get(login)
if err == nil {
if usr.Name != nil {
if len(*usr.Name) > 0 {
config.UserNames[login] = *usr.Name
an = *usr.Name
}
}
} else {
config.UserNames[login] = login // don't look again for a missing name
}
}
return an
}