From b7ab5bcf2ef9bac881d94a23aa2ae7f26fd8e8f3 Mon Sep 17 00:00:00 2001 From: Jay Gabriels Date: Wed, 11 Aug 2021 07:49:17 -0700 Subject: [PATCH] Update config init to read in config file (#141) * Update config init to read in config file --- .github/workflows/go.yml | 4 ++-- README.md | 1 + configs/configs.go | 5 +++-- scripts/github_integration_tests.sh | 19 ++++++++++++++----- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 2bab30a..6142d63 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -16,6 +16,8 @@ jobs: id: go - name: Check out code into the Go module directory uses: actions/checkout@v1 + - name: Test + run: go test -v ./... - name: Set configuration file run: | echo $HOME @@ -26,8 +28,6 @@ jobs: go get -v -t -d ./... - name: Build run: go build -v -o ghorg . - - name: Test - run: go test -v ./... - name: Run GitHub Integration Tests run: scripts/github_integration_tests.sh env: diff --git a/README.md b/README.md index aa0e79d..7435069 100644 --- a/README.md +++ b/README.md @@ -116,6 +116,7 @@ $ security find-internet-password -s gitlab.com | grep "acct" | awk -F\" '{ pri ## Filtering Repos - To filter repos by regex use `--match-regex` flag - To filter out any archived repos while cloning use the `--skip-archived` flag (not bitbucket) +- To filter out any forked repos while cloning use the `--skip-forks` flag - To ignore specific repos create a `ghorgignore` file inside `$HOME/.config/ghorg`. Each line in this file is considered a substring and will be compared against each repos clone url. If the clone url contains a substring in the `ghorgignore` it will be excluded from cloning. To prevent accidentally excluding a repo, you should make each line as specific as possible, eg. `https://github.com/gabrie30/ghorg.git` or `git@github.com:gabrie30/ghorg.git` depending on how you clone. This is useful for permanently igorning certain repos. diff --git a/configs/configs.go b/configs/configs.go index d7aa3a7..0e51611 100644 --- a/configs/configs.go +++ b/configs/configs.go @@ -67,11 +67,12 @@ func printGhorgConfMissing() { } func initConfig() { - ghorgDir := GhorgDir() viper.SetConfigType("yaml") - viper.AddConfigPath(ghorgDir) + viper.AddConfigPath(GhorgDir()) viper.SetConfigName("conf") + viper.ReadInConfig() + // Set With Default values getOrSetDefaults("GHORG_ABSOLUTE_PATH_TO_CLONE_TO") getOrSetDefaults("GHORG_BRANCH") diff --git a/scripts/github_integration_tests.sh b/scripts/github_integration_tests.sh index 59a49a4..7708149 100755 --- a/scripts/github_integration_tests.sh +++ b/scripts/github_integration_tests.sh @@ -10,13 +10,18 @@ GITHUB_ORG=underdeveloped ghorg version +# hack to allow sed to be ran on both mac and ubuntu +sed "s/GHORG_OUTPUT_DIR:/GHORG_OUTPUT_DIR: testing_conf_is_set/g" $HOME/.config/ghorg/conf.yaml >updated_conf.yaml && \ +mv $HOME/.config/ghorg/conf.yaml $HOME/.config/ghorg/conf-bak.yaml && \ +mv updated_conf.yaml $HOME/.config/ghorg/conf.yaml + ghorg clone $GITHUB_ORG --token=$GITHUB_TOKEN -if [ -e $HOME/ghorg/$GITHUB_ORG ] +if [ -e $HOME/ghorg/testing_conf_is_set ] then - echo "Pass: github org clone" + echo "Pass: github org clone using conf.yaml" else - echo "Fail: github org clone" + echo "Fail: github org clone using conf.yaml" exit 1 fi @@ -24,8 +29,12 @@ ghorg clone $GITHUB_ORG --token=$GITHUB_TOKEN --path=/tmp --output-dir=testing_o if [ -e /tmp/testing_output_dir ] then - echo "Pass: github org clone custom output directories" + echo "Pass: github org clone, commandline flags take overwrite conf.yaml" else - echo "Fail: github org clone custom output directories" + echo "Fail: github org clone, commandline flags take overwrite conf.yaml" exit 1 fi + +# Move back to original conf but keep updated_conf if we want to use it again +mv $HOME/.config/ghorg/conf.yaml $HOME/.config/ghorg/updated_conf.yaml +mv $HOME/.config/ghorg/conf-bak.yaml $HOME/.config/ghorg/conf.yaml