Add reclone list flag (#323)

This commit is contained in:
gabrie30
2023-07-14 10:04:12 -07:00
committed by GitHub
parent 4eba463d5c
commit 575b04dd3c
5 changed files with 42 additions and 11 deletions

View File

@@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
## [1.9.7] - unreleased
### Added
- Reclone list flag
### Changed
### Deprecated
### Removed

View File

@@ -261,15 +261,7 @@ git checkout master
The `ghorg reclone` command is a way to store all your `ghorg clone` commands in one configuration file and makes calling long or multiple `ghorg clone` commands easier.
Once your [reclone.yaml](https://github.com/gabrie30/ghorg/blob/master/sample-reclone.yaml) configuration is set you can call `ghorg reclone` to clone each entry individually or clone all at once.
To use, add a [reclone.yaml](https://github.com/gabrie30/ghorg/blob/master/sample-reclone.yaml) to your `$HOME/.config/ghorg` directory. You can use the following command to set it for you with examples to use as a template
```
curl https://raw.githubusercontent.com/gabrie30/ghorg/master/sample-reclone.yaml > $HOME/.config/ghorg/reclone.yaml
```
After updating your `reclone.yaml` you can run
Once your [reclone.yaml](https://github.com/gabrie30/ghorg/blob/master/sample-reclone.yaml) configuration is set you can call `ghorg reclone` to clone each entry individually or clone all at once, see examples below.
```
# To clone all the entries in your reclone.yaml omit any arguments
@@ -281,10 +273,26 @@ ghorg reclone
ghorg reclone kubernetes-sig-staging kubernetes-sig
```
```
# To view all your reclone commands
# NOTE: This command prints tokens to stdout
ghorg reclone --list
```
<p align="center">
<img width="648" alt="ghorg reclone example" src="https://user-images.githubusercontent.com/1512282/183263986-50e56b86-12b9-479b-9c52-b1c74129228c.png">
</p>
#### Setup
Add a [reclone.yaml](https://github.com/gabrie30/ghorg/blob/master/sample-reclone.yaml) to your `$HOME/.config/ghorg` directory. You can use the following command to set it for you with examples to use as a template
```
curl https://raw.githubusercontent.com/gabrie30/ghorg/master/sample-reclone.yaml > $HOME/.config/ghorg/reclone.yaml
```
Update file with the commands you wish to run.
## Troubleshooting
- If you are having trouble cloning repos. Try to clone one of the repos locally e.g. manually running `git clone https://github.com/your_private_org/your_private_repo.git` if this does not work, ghorg will also not work. Your git client must first be setup to clone the target repos. If you normally clone using an ssh key use the `--protocol=ssh` flag with ghorg. This will fetch the ssh clone urls instead of the https clone urls.

View File

@@ -22,7 +22,8 @@ var reCloneCmd = &cobra.Command{
}
type ReClone struct {
Cmd string `yaml:"cmd"`
Cmd string `yaml:"cmd"`
Description string `yaml:"description"`
}
func isVerboseReClone() bool {
@@ -61,6 +62,22 @@ func reCloneFunc(cmd *cobra.Command, argz []string) {
colorlog.PrintErrorAndExit(fmt.Sprintf("ERROR: unmarshaling reclone.yaml, error:%v", err))
}
if cmd.Flags().Changed("list") {
colorlog.PrintInfo("**************************************************************")
colorlog.PrintInfo("**** Available reclone commands and optional descriptions ****")
colorlog.PrintInfo("**************************************************************")
fmt.Println("")
for key, value := range mapOfReClones {
colorlog.PrintInfo(fmt.Sprintf("- %s", key))
if value.Description != "" {
colorlog.PrintSubtleInfo(fmt.Sprintf(" description: %s", value.Description))
}
colorlog.PrintSubtleInfo(fmt.Sprintf(" cmd: %s", value.Cmd))
fmt.Println("")
}
os.Exit(0)
}
if !isVerboseReClone() && !isQuietReClone() {
asciiTime()
}

View File

@@ -59,6 +59,7 @@ var (
fetchAll bool
ghorgReCloneVerbose bool
ghorgReCloneQuiet bool
ghorgReCloneList bool
noToken bool
quietMode bool
args []string
@@ -316,6 +317,7 @@ func init() {
reCloneCmd.Flags().StringVarP(&ghorgReClonePath, "reclone-path", "", "", "GHORG_RECLONE_PATH - If you want to set a path other than $HOME/.config/ghorg/reclone.yaml for your reclone configuration")
reCloneCmd.Flags().BoolVar(&ghorgReCloneVerbose, "verbose", false, "GHORG_RECLONE_VERBOSE - Verbose logging output")
reCloneCmd.Flags().BoolVar(&ghorgReCloneQuiet, "quiet", false, "GHORG_RECLONE_QUIET - Quiet logging output")
reCloneCmd.Flags().BoolVar(&ghorgReCloneList, "list", false, "Prints reclone commands and optional descriptions to stdout then will exit 0. Does not obsfucate tokens, and is only available as a commandline argument")
rootCmd.AddCommand(lsCmd, versionCmd, cloneCmd, reCloneCmd)
}

View File

@@ -5,12 +5,13 @@
# Example format below. You can reclone, one, multiple or all at once e.g.
# ghorg reclone (will call all clone cmd's)
# ghorg reclone gitlab-examples kubernetes-sig (will call both clone cmds)
# Note: tokens used in cmd's will be sanitized before being logged to stdout
# Note: tokens used in cmd's will be sanitized before being logged to stdout except when running `ghorg reclone --list`
# See https://github.com/gabrie30/ghorg#reclone-command for more information
# Example of basic structure
# name-of-reclone:
# cmd: "ghorg clone command here"
# description: "Optional description that will be printed to stdout when running `ghorg reclone --list`"
# Example for gitlab; update with your gitlab cloud token
gitlab-examples:
@@ -21,5 +22,7 @@ kubernetes:
cmd: "ghorg clone kubernetes --token=XXXXXXX"
kubernetes-sig:
cmd: "ghorg clone kubernetes --token=XXXXXXX --match-regex=^sig- --output-dir=kubernetes-sig-only"
description: "Clones the kubernetes org and only repos that match the regex ^sig- and puts them in a new directory called kubernetes-sig-only"
kubernetes-sig-staging:
cmd: "ghorg clone kubernetes --token=XXXXXXX --topics=k8s-sig-staging --output-dir=kubernetes-sig-staging"
description: "Clones the kubernetes org and only repos that have the topic k8s-sig-staging and puts them in a new directory called kubernetes-sig-staging"