Skip to content

Commit

Permalink
feat(contributor): display more author data in a table (maintainer-or…
Browse files Browse the repository at this point in the history
…g#38)

* feat(contributor): display more author data in a table

* Close maintainer-org#37
* Based on forked repo used across SaltStack Formulas organisation, e.g.:
  - https://github.com/saltstack-formulas/template-formula/blob/master/AUTHORS.md

* style(contributor): display `descending` in emphasised text

* refactor(helper): update `Footer` to reformat layout

* Prevent issue with heading appearing in "Table of Contents" when
  automatically converting to display on "Read the Docs" (or similar)
* Other minor reformatting
  • Loading branch information
myii authored and gaocegege committed May 25, 2019
1 parent a9db5d0 commit 06db118
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
19 changes: 17 additions & 2 deletions cmd/contributor.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,12 @@ func contributorRun() error {

// authorHeader returns the header to be written into AUTHORS.md.
func authorHeader() string {
return "# Authors\n\nThis list is sorted by the number of commits per contributor in descending order.\n\n"
return "# Authors\n\nThis list is sorted by the number of commits per contributor in _descending_ order.\n\n"
}

// authorTableHeader returns the table header to be written into AUTHORS.md.
func authorTableHeader() string {
return "Avatar|Contributor|Contributions\n:-:|---|:-:\n"
}

func composeByOrder(contributors []*github.Contributor) error {
Expand All @@ -136,8 +141,18 @@ func writeToFile(contributors []*github.Contributor) error {
if _, err := f.WriteString(authorHeader()); err != nil {
return err
}
if _, err := f.WriteString(authorTableHeader()); err != nil {
return err
}
for _, contributor := range contributors {
if _, err := f.WriteString(fmt.Sprintf("* [@%s](%s)", *contributor.Login, *contributor.HTMLURL)); err != nil {
if _, err := f.WriteString(fmt.Sprintf(
"<img class='float-left rounded-1' src='%s' width='36' height='36' alt='@%s'>|[@%s](%s)|%d",
*contributor.AvatarURL,
*contributor.Login,
*contributor.Login,
*contributor.HTMLURL,
*contributor.Contributions,
)); err != nil {
return err
}
if _, err := f.WriteString("\n"); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
func Footer() string {
// Refer https://golang.org/src/time/format.go.
dateFormatStr := "2006-01-02"
formatStr := "\n###### Auto generated by [gaocegege/maintainer]" +
"(https://github.com/gaocegege/maintainer) on %s\n"
formatStr := "\n---\n\nAuto-generated by [gaocegege/maintainer]" +
"(https://github.com/gaocegege/maintainer) on %s.\n"

date := time.Now().Format(dateFormatStr)
return fmt.Sprintf(formatStr, date)
Expand Down

0 comments on commit 06db118

Please sign in to comment.