From d1982e9d7f206cddd57a29b7c910f29c6382aefa Mon Sep 17 00:00:00 2001 From: Mihai Parparita Date: Sat, 2 Aug 2014 23:11:30 -0700 Subject: [PATCH] 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. --- app/digest.go | 24 ++++++++++++++++++++++-- app/templates/digest.html | 6 +++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/app/digest.go b/app/digest.go index da20332..194a1c7 100644 --- a/app/digest.go +++ b/app/digest.go @@ -1,15 +1,24 @@ package githop import ( + "fmt" "sort" "time" "github.com/google/go-github/github" ) +type DigestCommit struct { + DisplaySHA string + URL string + Message *string + Date *time.Time + RepositoryCommit *github.RepositoryCommit +} + type RepoDigest struct { Repo *github.Repository - Commits []github.RepositoryCommit + Commits []DigestCommit } // sort.Interface implementation for sorting RepoDigests. @@ -95,7 +104,18 @@ func (digest *Digest) fetch(repos []github.Repository, githubClient *github.Clie if err != nil { ch <- &RepoDigestResponse{nil, err} } 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) } diff --git a/app/templates/digest.html b/app/templates/digest.html index cc2df44..255de05 100644 --- a/app/templates/digest.html +++ b/app/templates/digest.html @@ -14,10 +14,10 @@
{{range .Commits }}
-
{{.Commit.Message}}
+
{{.Message}}
- {{.SHA}} - {{.Commit.Author.Date}} + {{.DisplaySHA}} + {{.Date}}
{{end}}