-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new git "count-contributors" command. (#91)
- Loading branch information
1 parent
4aca7e8
commit 17e4c19
Showing
9 changed files
with
2,378 additions
and
7 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
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
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,5 @@ | ||
package git | ||
|
||
func GetContContributorsDescription() string { | ||
return "List all GIT providers' contributing developers." | ||
} |
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,109 @@ | ||
package cli | ||
|
||
import ( | ||
"github.com/jfrog/froggit-go/vcsutils" | ||
"github.com/jfrog/jfrog-cli-core/v2/common/progressbar" | ||
"github.com/jfrog/jfrog-cli-core/v2/plugins/components" | ||
flags "github.com/jfrog/jfrog-cli-security/cli/docs" | ||
gitDocs "github.com/jfrog/jfrog-cli-security/cli/docs/git" | ||
"github.com/jfrog/jfrog-cli-security/commands/git" | ||
"github.com/jfrog/jfrog-client-go/utils/errorutils" | ||
"os" | ||
) | ||
|
||
func getGitNameSpaceCommands() []components.Command { | ||
return []components.Command{ | ||
{ | ||
Name: "count-contributors", | ||
Aliases: []string{"cc"}, | ||
Flags: flags.GetCommandFlags(flags.GitCountContributors), | ||
Description: gitDocs.GetContContributorsDescription(), | ||
Hidden: true, | ||
Action: GitCountContributorsCmd, | ||
}, | ||
} | ||
} | ||
|
||
func GetCountContributorsParams(c *components.Context) (*git.CountContributorsParams, error) { | ||
params := git.CountContributorsParams{} | ||
// Mandatory flags | ||
scmTypes := git.NewScmType() | ||
// ScmType | ||
scmType := c.GetStringFlagValue(flags.ScmType) | ||
if scmType == "" { | ||
return nil, errorutils.CheckErrorf("The --%s option is mandatory", flags.ScmType) | ||
} else { | ||
if scmTypeVal, ok := scmTypes.ScmTypeMap[scmType]; ok { | ||
params.ScmType = scmTypeVal | ||
} else { | ||
return nil, errorutils.CheckErrorf("Unsupported SCM type: %s, Possible values are: %v", scmType, scmTypes.GetValidScmTypeString()) | ||
} | ||
} | ||
// Token | ||
params.Token = c.GetStringFlagValue(flags.Token) | ||
if params.Token == "" { | ||
var envVarToken string | ||
switch params.ScmType { | ||
case vcsutils.BitbucketServer: | ||
envVarToken = os.Getenv(git.BitbucketTokenEnvVar) | ||
case vcsutils.GitLab: | ||
envVarToken = os.Getenv(git.GitlabTokenEnvVar) | ||
case vcsutils.GitHub: | ||
envVarToken = os.Getenv(git.GithubTokenEnvVar) | ||
default: | ||
return nil, errorutils.CheckErrorf("Unsupported SCM type: %s, Possible values are: %v", scmType, scmTypes.GetValidScmTypeString()) | ||
} | ||
if envVarToken != "" { | ||
params.Token = envVarToken | ||
} else { | ||
envVarToken = os.Getenv(git.GenericGitTokenEnvVar) | ||
if envVarToken != "" { | ||
params.Token = envVarToken | ||
} else { | ||
return nil, errorutils.CheckErrorf("Providing a token is mandatory. should use --%s flag, the token enviromment variable %s, or coresponding provider enviromment variable %s.", flags.Token, git.GenericGitTokenEnvVar, scmTypes.GetOptionalScmTypeTokenEnvVars()) | ||
} | ||
} | ||
} | ||
// Owner | ||
params.Owner = c.GetStringFlagValue(flags.Owner) | ||
if params.Owner == "" { | ||
return nil, errorutils.CheckErrorf("The --%s option is mandatory", flags.Owner) | ||
} | ||
// ScmApiUrl | ||
params.ScmApiUrl = c.GetStringFlagValue(flags.ScmApiUrl) | ||
if params.ScmApiUrl == "" { | ||
return nil, errorutils.CheckErrorf("The --%s option is mandatory", flags.ScmApiUrl) | ||
} | ||
|
||
// Optional flags | ||
// Repository name | ||
params.Repository = c.GetStringFlagValue(flags.RepoName) | ||
// Months | ||
if !c.IsFlagSet(flags.Months) { | ||
params.MonthsNum = git.DefaultContContributorsMonths | ||
} else { | ||
months, err := c.GetIntFlagValue(flags.Months) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if months <= 0 { | ||
return nil, errorutils.CheckErrorf("Invalid value for '--%s=%d'. If set, should be positive number.", flags.Months, months) | ||
} | ||
params.MonthsNum = months | ||
} | ||
// DetailedSummery | ||
params.DetailedSummery = c.GetBoolFlagValue(flags.DetailedSummary) | ||
return ¶ms, nil | ||
} | ||
|
||
func GitCountContributorsCmd(c *components.Context) error { | ||
gitContrParams, err := GetCountContributorsParams(c) | ||
if err != nil { | ||
return err | ||
} | ||
gitContributionCommand, err := git.NewCountContributorsCommand(gitContrParams) | ||
if err != nil { | ||
return err | ||
} | ||
return progressbar.ExecWithProgress(gitContributionCommand) | ||
} |
Oops, something went wrong.