Create a DigestCommit struct for extracting interesting/display data for commits.

For just used for convenience storage of properties and a display SHA, but will
also be used for message/title extraction.
This commit is contained in:
Mihai Parparita 2014-08-02 23:11:30 -07:00
parent 243cfb06e6
commit d1982e9d7f
2 changed files with 25 additions and 5 deletions

View file

@ -1,15 +1,24 @@
package githop package githop
import ( import (
"fmt"
"sort" "sort"
"time" "time"
"github.com/google/go-github/github" "github.com/google/go-github/github"
) )
type DigestCommit struct {
DisplaySHA string
URL string
Message *string
Date *time.Time
RepositoryCommit *github.RepositoryCommit
}
type RepoDigest struct { type RepoDigest struct {
Repo *github.Repository Repo *github.Repository
Commits []github.RepositoryCommit Commits []DigestCommit
} }
// sort.Interface implementation for sorting RepoDigests. // sort.Interface implementation for sorting RepoDigests.
@ -95,7 +104,18 @@ func (digest *Digest) fetch(repos []github.Repository, githubClient *github.Clie
if err != nil { if err != nil {
ch <- &RepoDigestResponse{nil, err} ch <- &RepoDigestResponse{nil, err}
} else { } else {
ch <- &RepoDigestResponse{&RepoDigest{&repo, commits}, nil} digestCommits := make([]DigestCommit, 0, len(commits))
for i, _ := range commits {
commit := &commits[i]
digestCommits = append(digestCommits, DigestCommit{
DisplaySHA: (*commit.SHA)[:7],
URL: fmt.Sprintf("https://github.com/%s/commit/%s", *repo.FullName, *commit.SHA),
Message: commit.Commit.Message,
Date: commit.Commit.Author.Date,
RepositoryCommit: commit,
})
}
ch <- &RepoDigestResponse{&RepoDigest{&repo, digestCommits}, nil}
} }
}(repo) }(repo)
} }

View file

@ -14,10 +14,10 @@
<div> <div>
{{range .Commits }} {{range .Commits }}
<div> <div>
<pre>{{.Commit.Message}}</pre> <pre>{{.Message}}</pre>
<div> <div>
<a href="https://github.com/{{$repoDigest.Repo.FullName}}/commit/{{.SHA}}">{{.SHA}}</a> <a href="{{.URL}}">{{.DisplaySHA}}</a>
<i>{{.Commit.Author.Date}}</i> <i>{{.Date}}</i>
</div> </div>
</div> </div>
{{end}} {{end}}