Move DigestCommit construction to a separate function.

This commit is contained in:
Mihai Parparita 2014-08-03 15:46:25 -07:00
parent d1982e9d7f
commit 6c63be0cfb

View file

@ -9,13 +9,23 @@ import (
) )
type DigestCommit struct { type DigestCommit struct {
DisplaySHA string DisplaySHA string
URL string URL string
Message *string Message *string
Date *time.Time Date *time.Time
RepositoryCommit *github.RepositoryCommit RepositoryCommit *github.RepositoryCommit
} }
func newDigestCommit(commit *github.RepositoryCommit, repo *github.Repository) DigestCommit {
return 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,
}
}
type RepoDigest struct { type RepoDigest struct {
Repo *github.Repository Repo *github.Repository
Commits []DigestCommit Commits []DigestCommit
@ -65,7 +75,7 @@ func newDigest(githubClient *github.Client) (*Digest, error) {
now := time.Now() now := time.Now()
digestStartTime := time.Date(now.Year()-1, now.Month(), now.Day(), 0, 0, 0, 0, now.Location()) digestStartTime := time.Date(now.Year()-1, now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
digestEndTime := digestStartTime.AddDate(0, 0, 1) digestEndTime := digestStartTime.AddDate(0, 0, 7)
// Only look at repos that may have activity in the digest interval. // Only look at repos that may have activity in the digest interval.
var digestRepos []github.Repository var digestRepos []github.Repository
@ -106,14 +116,7 @@ func (digest *Digest) fetch(repos []github.Repository, githubClient *github.Clie
} else { } else {
digestCommits := make([]DigestCommit, 0, len(commits)) digestCommits := make([]DigestCommit, 0, len(commits))
for i, _ := range commits { for i, _ := range commits {
commit := &commits[i] digestCommits = append(digestCommits, newDigestCommit(&commits[i], &repo))
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} ch <- &RepoDigestResponse{&RepoDigest{&repo, digestCommits}, nil}
} }