mirror of
https://github.com/outbackdingo/ghorg.git
synced 2026-01-27 10:19:03 +00:00
Add exit code on clone issues (#215)
This commit is contained in:
@@ -3,10 +3,11 @@ All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
||||
|
||||
## [1.8.0] - unreleased
|
||||
## [1.8.0] - 6/25/22
|
||||
### Added
|
||||
- Exit 1 when any issue messages are produced; thanks @i3v
|
||||
- GHORG_EXIT_CODE_ON_CLONE_INFOS to allow for control of exit code when any info messages are produced
|
||||
- GHORG_EXIT_CODE_ON_CLONE_ISSUES to allow for control of exit code when any issue messages are produced
|
||||
- Remotes updated count to clone stats
|
||||
### Changed
|
||||
### Deprecated
|
||||
|
||||
22
cmd/clone.go
22
cmd/clone.go
@@ -63,13 +63,18 @@ func cloneFunc(cmd *cobra.Command, argz []string) {
|
||||
}
|
||||
|
||||
if cmd.Flags().Changed("concurrency") {
|
||||
g := cmd.Flag("concurrency").Value.String()
|
||||
os.Setenv("GHORG_CONCURRENCY", g)
|
||||
f := cmd.Flag("concurrency").Value.String()
|
||||
os.Setenv("GHORG_CONCURRENCY", f)
|
||||
}
|
||||
|
||||
if cmd.Flags().Changed("exit-code-on-clone-infos") {
|
||||
g := cmd.Flag("exit-code-on-clone-infos").Value.String()
|
||||
os.Setenv("GHORG_EXIT_CODE_ON_CLONE_INFOS", g)
|
||||
f := cmd.Flag("exit-code-on-clone-infos").Value.String()
|
||||
os.Setenv("GHORG_EXIT_CODE_ON_CLONE_INFOS", f)
|
||||
}
|
||||
|
||||
if cmd.Flags().Changed("exit-code-on-clone-issues") {
|
||||
f := cmd.Flag("exit-code-on-clone-issues").Value.String()
|
||||
os.Setenv("GHORG_EXIT_CODE_ON_CLONE_ISSUES", f)
|
||||
}
|
||||
|
||||
if cmd.Flags().Changed("topics") {
|
||||
@@ -525,7 +530,6 @@ func CloneAllRepos(git git.Gitter, cloneTargets []scm.Repo) {
|
||||
}
|
||||
|
||||
action := "cloning"
|
||||
|
||||
if repoExistsLocally(repo) {
|
||||
if os.Getenv("GHORG_BACKUP") == "true" {
|
||||
err := git.UpdateRemote(repo)
|
||||
@@ -686,7 +690,13 @@ func CloneAllRepos(git git.Gitter, cloneTargets []scm.Repo) {
|
||||
}
|
||||
|
||||
if len(cloneErrors) > 0 {
|
||||
os.Exit(1)
|
||||
exitCode, err := strconv.Atoi(os.Getenv("GHORG_EXIT_CODE_ON_CLONE_ISSUES"))
|
||||
if err != nil {
|
||||
colorlog.PrintError("Could not convert GHORG_EXIT_CODE_ON_CLONE_ISSUES from string to integer")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
os.Exit(exitCode)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ var (
|
||||
baseURL string
|
||||
concurrency string
|
||||
exitCodeOnCloneInfos string
|
||||
exitCodeOnCloneIssues string
|
||||
outputDir string
|
||||
topics string
|
||||
skipArchived bool
|
||||
@@ -125,6 +126,8 @@ func getOrSetDefaults(envVar string) {
|
||||
os.Setenv(envVar, "false")
|
||||
case "GHORG_EXIT_CODE_ON_CLONE_INFOS":
|
||||
os.Setenv(envVar, "0")
|
||||
case "GHORG_EXIT_CODE_ON_CLONE_ISSUES":
|
||||
os.Setenv(envVar, "1")
|
||||
}
|
||||
} else {
|
||||
s := viper.GetString(envVar)
|
||||
@@ -194,6 +197,7 @@ func InitConfig() {
|
||||
getOrSetDefaults("GHORG_BACKUP")
|
||||
getOrSetDefaults("GHORG_CONCURRENCY")
|
||||
getOrSetDefaults("GHORG_EXIT_CODE_ON_CLONE_INFOS")
|
||||
getOrSetDefaults("GHORG_EXIT_CODE_ON_CLONE_ISSUES")
|
||||
// Optionally set
|
||||
getOrSetDefaults("GHORG_GITHUB_TOKEN")
|
||||
getOrSetDefaults("GHORG_COLOR")
|
||||
@@ -261,7 +265,8 @@ func init() {
|
||||
cloneCmd.Flags().StringVarP(&excludeMatchRegex, "exclude-match-regex", "", "", "GHORG_EXCLUDE_MATCH_REGEX - Exclude cloning repos that match name to regex provided")
|
||||
cloneCmd.Flags().StringVarP(&gitlabGroupExcludeMatchRegex, "gitlab-group-exclude-match-regex", "", "", "GHORG_GITLAB_GROUP_EXCLUDE_MATCH_REGEX - Exclude cloning gitlab groups that match name to regex provided")
|
||||
cloneCmd.Flags().StringVarP(&ghorgIgnorePath, "ghorgignore-path", "", "", "GHORG_IGNORE_PATH - If you want to set a path other than $HOME/.config/ghorg/ghorgignore for your ghorgignore")
|
||||
cloneCmd.Flags().StringVarP(&exitCodeOnCloneInfos, "exit-code-on-clone-infos", "", "", "GHORG_EXIT_CODE_ON_CLONE_INFOS - Allows you to control the exit code when ghorg runs into a problem cloning a repo from the remote (default 0)")
|
||||
cloneCmd.Flags().StringVarP(&exitCodeOnCloneInfos, "exit-code-on-clone-infos", "", "", "GHORG_EXIT_CODE_ON_CLONE_INFOS - Allows you to control the exit code when ghorg runs into a problem (info level message) cloning a repo from the remote. Info messages will appear after a clone is complete, similar to success messages. (default 0)")
|
||||
cloneCmd.Flags().StringVarP(&exitCodeOnCloneIssues, "exit-code-on-clone-issues", "", "", "GHORG_EXIT_CODE_ON_CLONE_ISSUES - Allows you to control the exit code when ghorg runs into a problem (issue level message) cloning a repo from the remote. Issue messages will appear after a clone is complete, similar to success messages (default 1)")
|
||||
rootCmd.AddCommand(lsCmd, versionCmd, cloneCmd)
|
||||
}
|
||||
|
||||
|
||||
@@ -171,11 +171,16 @@ GHORG_IGNORE_PATH:
|
||||
# flag (--quiet)
|
||||
GHORG_QUIET: false
|
||||
|
||||
# Allows you to control the exit code when ghorg runs into a problem cloning a repo from the remote.
|
||||
# For automation you may want to exit 1 if any repo fails to clone.
|
||||
# Allows you to control the exit code when ghorg runs into a problem (info level message) cloning a repo from the remote.
|
||||
# Info messages will appear after a clone is complete, similar to success messages
|
||||
# flag (--exit-code-on-clone-infos)
|
||||
GHORG_EXIT_CODE_ON_CLONE_INFOS: 0
|
||||
|
||||
# Allows you to control the exit code when ghorg runs into a problem (issue level message) cloning a repo from the remote.
|
||||
# Issue messages will appear after a clone is complete, similar to success messages.
|
||||
# flag (--exit-code-on-clone-issues)
|
||||
GHORG_EXIT_CODE_ON_CLONE_ISSUES: 1
|
||||
|
||||
# Specifies the location of your ghorg conf.yaml, allowing you to have many configuration files, or none at all
|
||||
# default: ghorg looks in $HOME/.config/ghorg/conf.yaml, if not set in that location nor as a commandline flag, ghorg will use all default values
|
||||
# NOTE: this cannot be set in the configuration file and only available in ghorg v1.7.0+
|
||||
|
||||
Reference in New Issue
Block a user