Add GHORG_NO_TOKEN (#299)

This commit is contained in:
gabrie30
2023-04-09 12:40:37 -07:00
committed by GitHub
parent 1f37d597c0
commit 3e126e751d
6 changed files with 38 additions and 11 deletions

View File

@@ -3,6 +3,16 @@ 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.9.5] - unreleased
### Added
- GHORG_NO_TOKEN to allow cloning no token present; thanks @6543
### Changed
### Deprecated
### Removed
### Fixed
### Security
## [1.9.4] - 2/26/23
### Added
### Changed

View File

@@ -166,6 +166,10 @@ func cloneFunc(cmd *cobra.Command, argz []string) {
os.Setenv("GHORG_QUIET", "true")
}
if cmd.Flags().Changed("no-token") {
os.Setenv("GHORG_NO_TOKEN", "true")
}
if cmd.Flags().Changed("preserve-dir") {
os.Setenv("GHORG_PRESERVE_DIRECTORY_STRUCTURE", "true")
}

View File

@@ -30,6 +30,15 @@ var (
outputDir string
topics string
gitFilter string
targetCloneSource string
matchPrefix string
excludeMatchPrefix string
matchRegex string
excludeMatchRegex string
config string
gitlabGroupExcludeMatchRegex string
ghorgIgnorePath string
ghorgReClonePath string
includeSubmodules bool
skipArchived bool
skipForks bool
@@ -45,19 +54,11 @@ var (
fetchAll bool
ghorgReCloneVerbose bool
ghorgReCloneQuiet bool
noToken bool
quietMode bool
args []string
cloneErrors []string
cloneInfos []string
targetCloneSource string
matchPrefix string
excludeMatchPrefix string
matchRegex string
excludeMatchRegex string
config string
gitlabGroupExcludeMatchRegex string
ghorgIgnorePath string
ghorgReClonePath string
quietMode bool
)
// rootCmd represents the base command when called without any subcommands
@@ -128,6 +129,8 @@ func getOrSetDefaults(envVar string) {
os.Setenv(envVar, "false")
case "GHORG_BACKUP":
os.Setenv(envVar, "false")
case "GHORG_NO_TOKEN":
os.Setenv(envVar, "false")
case "GHORG_RECLONE_VERBOSE":
os.Setenv(envVar, "false")
case "GHORG_RECLONE_QUIET":
@@ -204,6 +207,7 @@ func InitConfig() {
getOrSetDefaults("GHORG_SKIP_ARCHIVED")
getOrSetDefaults("GHORG_SKIP_FORKS")
getOrSetDefaults("GHORG_NO_CLEAN")
getOrSetDefaults("GHORG_NO_TOKEN")
getOrSetDefaults("GHORG_FETCH_ALL")
getOrSetDefaults("GHORG_PRUNE")
getOrSetDefaults("GHORG_PRUNE_NO_CONFIRM")
@@ -277,6 +281,7 @@ func init() {
cloneCmd.Flags().BoolVar(&insecureGiteaClient, "insecure-gitea-client", false, "GHORG_INSECURE_GITEA_CLIENT - Must be set to clone from a Gitea instance using http")
cloneCmd.Flags().BoolVar(&cloneWiki, "clone-wiki", false, "GHORG_CLONE_WIKI - Additionally clone the wiki page for repo")
cloneCmd.Flags().BoolVar(&skipForks, "skip-forks", false, "GHORG_SKIP_FORKS - Skips repo if its a fork, github/gitlab/gitea only")
cloneCmd.Flags().BoolVar(&noToken, "no-token", false, "GHORG_NO_TOKEN - Allows you to run ghorg with no token (GHORG_<SCM>_TOKEN), SCM server needs to specify no auth required for api calls")
cloneCmd.Flags().BoolVar(&preserveDir, "preserve-dir", false, "GHORG_PRESERVE_DIRECTORY_STRUCTURE - Clones repos in a directory structure that matches gitlab namespaces eg company/unit/subunit/app would clone into ghorg/unit/subunit/app, gitlab only")
cloneCmd.Flags().BoolVar(&backup, "backup", false, "GHORG_BACKUP - Backup mode, clone as mirror, no working copy (ignores branch parameter)")
cloneCmd.Flags().BoolVar(&quietMode, "quiet", false, "GHORG_QUIET - Emit critical output only")

View File

@@ -6,7 +6,7 @@ import (
"github.com/spf13/cobra"
)
const ghorgVersion = "v1.9.4"
const ghorgVersion = "v1.9.5"
var versionCmd = &cobra.Command{
Use: "version",

View File

@@ -237,6 +237,10 @@ func getOrSetGiteaToken() {
// VerifyTokenSet checks to make sure env is set for the correct scm provider
func VerifyTokenSet() error {
if os.Getenv("GHORG_NO_TOKEN") == "true" {
return nil
}
scmProvider := os.Getenv("GHORG_SCM_TYPE")
if scmProvider == "github" && os.Getenv("GHORG_GITHUB_TOKEN") == "" {

View File

@@ -137,6 +137,10 @@ GHORG_EXIT_CODE_ON_CLONE_INFOS: 0
# flag (--exit-code-on-clone-issues)
GHORG_EXIT_CODE_ON_CLONE_ISSUES: 1
# Allows you to run ghorg with no token (GHORG_<SCM>_TOKEN), SCM server needs to specify no auth required for api calls
# flag (--no-token)
GHORG_NO_TOKEN: false
# 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. Its supported through CLI flag and ENV var only.