Esempio n. 1
0
// TopRepositories returns the most mentioned repositories by language.
func (s *Store) TopRepositories() (m map[string]*Repository, err error) {
	m = make(map[string]*Repository)

	err = s.db.View(func(tx *bolt.Tx) error {
		c := tx.Bucket([]byte("repositories")).Cursor()
		for k, v := c.First(); k != nil; k, v = c.Next() {
			// Decode repository.
			var r internal.Repository
			if err := proto.Unmarshal(v, &r); err != nil {
				return err
			}

			// Retrieve repository language.
			lang := r.GetLanguage()

			// Ignore marked repositories or repositories that have a lower message count.
			if r.GetNotified() {
				continue
			} else if m[lang] != nil && len(r.GetMessages()) <= len(m[lang].Messages) {
				continue
			}

			// Override repo.
			m[lang] = decodeRepository(&r)
		}
		return nil
	})
	return
}
Esempio n. 2
0
// decodeRepository decodes pb into an application type.
func decodeRepository(pb *internal.Repository) *Repository {
	r := &Repository{
		ID:          pb.GetID(),
		Description: pb.GetDescription(),
		Language:    pb.GetLanguage(),
		Notified:    pb.GetNotified(),
		Messages:    make([]*Message, len(pb.Messages)),
	}

	for i, m := range pb.GetMessages() {
		r.Messages[i] = decodeMessage(m)
	}

	return r
}