diff --git a/TODO b/TODO index 1620fef..20388bb 100644 --- a/TODO +++ b/TODO @@ -8,7 +8,6 @@ TODO Notes: - Will need to get/store timezone of user (use https://bitbucket.org/pellepim/jstimezonedetect, use it with time.Location.LoadLocation) -- To get digests for non-user owned organizations, will need to list the organizations and their repositories - To make a raw HTTP request with the github package: httpReq, _ := githubClient.NewRequest("GET", "user/teams", nil) var jsonResp interface{} diff --git a/app/githop.go b/app/githop.go index 2d8d11a..177a0c8 100644 --- a/app/githop.go +++ b/app/githop.go @@ -11,6 +11,7 @@ import ( "net/http" "net/http/httputil" "net/url" + "sort" "strings" "time" @@ -31,6 +32,13 @@ type RepoDigest struct { Commits []github.RepositoryCommit } +// sort.Interface implementation for sorting RepoDigests. +type ByRepoFullName []*RepoDigest + +func (a ByRepoFullName) Len() int { return len(a) } +func (a ByRepoFullName) Swap(i, j int) { a[i], a[j] = a[j], a[i] } +func (a ByRepoFullName) Less(i, j int) bool { return *a[i].Repo.FullName < *a[j].Repo.FullName } + type Digest struct { User *github.User StartTime time.Time @@ -70,6 +78,7 @@ func (digest *Digest) Fetch(repos []github.Repository, githubClient *github.Clie digest.RepoDigests = append(digest.RepoDigests, r.repoDigest) } } + sort.Sort(ByRepoFullName(digest.RepoDigests)) return nil } @@ -144,7 +153,7 @@ func indexHandler(w http.ResponseWriter, r *http.Request) { http.Error(w, err.Error(), http.StatusInternalServerError) return } - newRepos := make([]github.Repository, len(repos) + len(orgRepos)) + newRepos := make([]github.Repository, len(repos)+len(orgRepos)) copy(newRepos, repos) copy(newRepos[len(repos):], orgRepos) repos = newRepos