Skip to content

Commit 6d0b694

Browse files
authored
Merge branch 'master' into add/reclone-cmds
2 parents f38fb28 + 683c5ec commit 6d0b694

File tree

5 files changed

+15
-1
lines changed

5 files changed

+15
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
88
- Reclone name and description to reclone output
99
- GHORG_PRESERVE_SCM_HOSTNAME, note that this feature changes the directory struture that gitlab all-users and all-groups clone into; thanks @rrrix
1010
- GHORG_PRUNE_UNTOUCHED, to prune repos that users make no changes in; thanks @MaxG87
11+
- GHORG_GITHUB_TOKEN_FROM_GITHUB_APP to handle github app tokens; thanks @PaarthShah
1112
- Command reclone-server
1213
- Command reclone-cron
1314
### Changed

cmd/clone.go

+4
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ func cloneFunc(cmd *cobra.Command, argz []string) {
5858
os.Setenv("GHORG_BRANCH", cmd.Flag("branch").Value.String())
5959
}
6060

61+
if cmd.Flags().Changed("github-token-from-github-app") {
62+
os.Setenv("GHORG_GITHUB_TOKEN_FROM_GITHUB_APP", cmd.Flag("github-token-from-github-app").Value.String())
63+
}
64+
6165
if cmd.Flags().Changed("github-app-pem-path") {
6266
os.Setenv("GHORG_GITHUB_APP_PEM_PATH", cmd.Flag("github-app-pem-path").Value.String())
6367
}

cmd/root.go

+5
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ var (
6767
ghorgReCloneQuiet bool
6868
ghorgReCloneList bool
6969
ghorgReCloneEnvConfigOnly bool
70+
githubTokenFromGithubApp bool
7071
noToken bool
7172
quietMode bool
7273
noDirSize bool
@@ -217,6 +218,8 @@ func getOrSetDefaults(envVar string) {
217218
os.Setenv(envVar, "0")
218219
case "GHORG_EXIT_CODE_ON_CLONE_ISSUES":
219220
os.Setenv(envVar, "1")
221+
case "GHORG_GITHUB_TOKEN_FROM_GITHUB_APP":
222+
os.Setenv(envVar, "false")
220223
}
221224
} else {
222225
s := viper.GetString(envVar)
@@ -309,6 +312,7 @@ func InitConfig() {
309312
getOrSetDefaults("GHORG_TARGET_REPOS_PATH")
310313
getOrSetDefaults("GHORG_CLONE_DEPTH")
311314
getOrSetDefaults("GHORG_GITHUB_TOKEN")
315+
getOrSetDefaults("GHORG_GITHUB_TOKEN_FROM_GITHUB_APP")
312316
getOrSetDefaults("GHORG_GITHUB_FILTER_LANGUAGE")
313317
getOrSetDefaults("GHORG_COLOR")
314318
getOrSetDefaults("GHORG_TOPICS")
@@ -396,6 +400,7 @@ func init() {
396400
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)")
397401
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)")
398402
cloneCmd.Flags().StringVarP(&gitFilter, "git-filter", "", "", "GHORG_GIT_FILTER - Allows you to pass arguments to git's filter flag. Useful for filtering out binary objects from repos with --git-filter=blob:none, this requires git version 2.19 or greater.")
403+
cloneCmd.Flags().BoolVarP(&githubTokenFromGithubApp, "github-token-from-github-app", "", false, "GHORG_GITHUB_TOKEN_FROM_GITHUB_APP - Indicate that the Github token should be treated as an app token. Needed if you already obtained a github app token outside the context of ghorg.")
399404
cloneCmd.Flags().StringVarP(&githubAppPemPath, "github-app-pem-path", "", "", "GHORG_GITHUB_APP_PEM_PATH - Path to your GitHub App PEM file, for authenticating with GitHub App.")
400405
cloneCmd.Flags().StringVarP(&githubAppInstallationID, "github-app-installation-id", "", "", "GHORG_GITHUB_APP_INSTALLATION_ID - GitHub App Installation ID, for authenticating with GitHub App.")
401406
cloneCmd.Flags().StringVarP(&githubFilterLanguage, "github-filter-language", "", "", "GHORG_GITHUB_FILTER_LANGUAGE - Filter repos by a language. Can be a comma separated value with no spaces.")

sample-conf.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@ GHORG_STATS_ENABLED: false
202202
# flag (--token, -t) eg: --token=bGVhdmUgYSBjb21tZW50IG9uIGlzc3VlIDY2 or --token=~/path/to/file/containing/token
203203
GHORG_GITHUB_TOKEN:
204204

205+
# Indicate that the Github token should be treated as an app token. Needed if you already obtained a github app token outside the context of ghorg.
206+
# flag (--github-token-from-github-app)
207+
GHORG_GITHUB_TOKEN_FROM_GITHUB_APP: false
208+
205209
# Path to your GitHub App PEM file, for authenticating with GitHub App
206210
# e.g. /home/user/foo/ghorg-app.pem
207211
# flag (--github-app-pem-path)

scm/github.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ func (c Github) filter(allRepos []*github.Repository) []Repo {
281281
// Then if https clone method is used the clone url will be https://username:token@github.com/org/repo.git
282282
// The username is now needed when using the new fine-grained tokens for github
283283
func (c Github) SetTokensUsername() {
284-
if os.Getenv("GHORG_GITHUB_APP_PEM_PATH") != "" {
284+
if os.Getenv("GHORG_GITHUB_TOKEN_FROM_GITHUB_APP") == "true" || os.Getenv("GHORG_GITHUB_APP_PEM_PATH") != "" {
285285
tokenUsername = "x-access-token"
286286
return
287287
}

0 commit comments

Comments
 (0)