Skip to content

Commit

Permalink
Add reclone list flag (#323)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrie30 authored Jul 14, 2023
1 parent 4eba463 commit 575b04d
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 17 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
19 changes: 18 additions & 1 deletion cmd/reclone.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ var (
fetchAll bool
ghorgReCloneVerbose bool
ghorgReCloneQuiet bool
ghorgReCloneList bool
noToken bool
quietMode bool
args []string
Expand Down Expand Up @@ -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)
}
Expand Down
5 changes: 4 additions & 1 deletion sample-reclone.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"

0 comments on commit 575b04d

Please sign in to comment.