This repository has been archived by the owner on Nov 22, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(repo): Add command to get contributors
- Loading branch information
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |