Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

Commit

Permalink
feat(repo): Add command to get contributors
Browse files Browse the repository at this point in the history
  • Loading branch information
profclems committed Aug 10, 2020
1 parent 1d1fd4e commit 84a67bb
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions commands/repo_contributors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package commands

import (
"fmt"
"github.com/MakeNowJust/heredoc"
"github.com/gookit/color"
"github.com/spf13/cobra"
"github.com/xanzy/go-gitlab"
"glab/internal/git"
)

var repoContributorsCmd = &cobra.Command{
Use: "contributors <command> [flags]",
Short: `Get an archive of the repository.`,
Example: heredoc.Doc(`
$ glab repo archive profclems/glab
$ glab repo archive // Downloads zip file of current repository
$ glab repo clone profclems/glab mydirectory // Clones repo into mydirectory
$ glab repo clone profclems/glab --format=zip // Finds repo for current user and download in zip format
`),
Long: heredoc.Doc(`
Clone supports these shorthands
- repo
- namespace/repo
- namespace/group/repo
`),
Aliases: []string{"users"},
Run: func (cmd *cobra.Command, args []string) {
gitlabClient, repo := git.InitGitlabClient()
l := &gitlab.ListContributorsOptions{}
users, _, err := gitlabClient.Repositories.Contributors(repo, l)
if err != nil {
er(err)
}
fmt.Printf("Showing users %d of %d on %s\n\n", len(users), len(users), git.GetRepo())
for _, user := range users {
color.Printf("%s <gray><%s></> - %d commits - <red>%d deletions</> - <green>%d additions</>\n", user.Name, user.Email, user.Commits, user.Deletions, user.Additions)
}
},
}

func init() {
repoContributorsCmd.Flags().StringP("order", "f", "zip", "Return contributors ordered by name, email, or commits (orders by commit date) fields. Default is commits")
repoContributorsCmd.Flags().StringP("sort", "s", "", "Return contributors sorted in asc or desc order. Default is asc")
repoCmd.AddCommand(repoContributorsCmd)
}

0 comments on commit 84a67bb

Please sign in to comment.