github.com/elliott5/community@v0.14.1-0.20160709191136-823126fb026a/documize/section/github/sort.go (about)

     1  // Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
     2  //
     3  // This software (Documize Community Edition) is licensed under
     4  // GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
     5  //
     6  // You can operate outside the AGPL restrictions by purchasing
     7  // Documize Enterprise Edition and obtaining a commercial license
     8  // by contacting <sales@documize.com>.
     9  //
    10  // https://documize.com
    11  
    12  package github
    13  
    14  import "sort"
    15  
    16  // sort repos in order that that should be presented.
    17  type reposToSort []githubRepo
    18  
    19  func (s reposToSort) Len() int      { return len(s) }
    20  func (s reposToSort) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
    21  func (s reposToSort) Less(i, j int) bool {
    22  	return s[i].Name < s[j].Name
    23  }
    24  
    25  func sortRepos(in []githubRepo) []githubRepo {
    26  	sts := reposToSort(in)
    27  	sort.Sort(sts)
    28  	return []githubRepo(sts)
    29  }
    30  
    31  // sort owners in order that that should be presented.
    32  type ownersToSort []githubOwner
    33  
    34  func (s ownersToSort) Len() int      { return len(s) }
    35  func (s ownersToSort) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
    36  func (s ownersToSort) Less(i, j int) bool {
    37  	return s[i].Name < s[j].Name
    38  }
    39  
    40  func sortOwners(in []githubOwner) []githubOwner {
    41  	sts := ownersToSort(in)
    42  	sort.Sort(sts)
    43  	return []githubOwner(sts)
    44  }