Skip to content

Commit 6623b30

Browse files
committed
POC of forking repos
Signed-off-by: Christian Hernandez <[email protected]>
1 parent c7d31b3 commit 6623b30

File tree

6 files changed

+133
-12
lines changed

6 files changed

+133
-12
lines changed

cmd/init.go

+24-5
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ package cmd
1818
import (
1919
"fmt"
2020

21+
"github.com/gitops-bridge-dev/gitops-bridge-cli/pkg/gobgh"
2122
"github.com/gitops-bridge-dev/gitops-bridge-cli/pkg/utils"
2223
"github.com/spf13/cobra"
24+
"github.com/spf13/viper"
2325
)
2426

2527
// initCmd represents the init command
@@ -28,11 +30,23 @@ var initCmd = &cobra.Command{
2830
Short: "Bootstrap your GitOps Bridge repository",
2931
Long: `Using the init command you can bootstrap your GitOps Bridge repository.`,
3032
Run: func(cmd *cobra.Command, args []string) {
31-
addonRepo, err := cmd.Flags().GetString("addon")
32-
utils.CheckError(err)
33-
34-
// Placeholder
35-
fmt.Println(addonRepo)
33+
// Get variables
34+
addonRepo := viper.GetString("addon")
35+
githubToken := viper.GetString("github-token")
36+
37+
// Verify the add on repo provided
38+
if err := utils.VerifyAddOnRepo(addonRepo); err != nil {
39+
Log.Fatal(err)
40+
}
41+
42+
// Fork the repos for the user
43+
for _, r := range []string{addonRepo, GobRepo} {
44+
if f, err := gobgh.ForkRepo(githubToken, GobOrgName, r); err != nil {
45+
Log.Fatal(err)
46+
} else {
47+
fmt.Println(f)
48+
}
49+
}
3650
},
3751
}
3852

@@ -41,4 +55,9 @@ func init() {
4155

4256
// addon is the name of the add on repo to be used
4357
initCmd.PersistentFlags().String("addon", "", "The addon repo to be used")
58+
initCmd.PersistentFlags().String("github-token", "", "GitHub token to be used")
59+
60+
// Bind the flags to viper
61+
viper.BindPFlag("addon", initCmd.PersistentFlags().Lookup("addon"))
62+
viper.BindPFlag("github-token", initCmd.PersistentFlags().Lookup("github-token"))
4463
}

cmd/root.go

+18
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,24 @@ package cmd
1818
import (
1919
"fmt"
2020
"os"
21+
"strings"
2122

23+
"github.com/sirupsen/logrus"
2224
"github.com/spf13/cobra"
2325
"github.com/spf13/viper"
2426
)
2527

2628
var cfgFile string
29+
var Log *logrus.Logger = logrus.New()
30+
31+
// Define constants
32+
const (
33+
GobGitRepo string = "https://github.com"
34+
GobOrgName string = "gitops-bridge-dev"
35+
GobURI string = GobGitRepo + "/" + GobOrgName
36+
GobRepo string = "gitops-bridge"
37+
GobRepoURI string = GobURI + "/" + GobRepo
38+
)
2739

2840
// rootCmd represents the base command when called without any subcommands
2941
var rootCmd = &cobra.Command{
@@ -65,6 +77,12 @@ func initConfig() {
6577
viper.SetConfigName(".gobctl")
6678
}
6779

80+
// Add prefix for your CLI. This will turn into "GOB_" for environment variables that you can use.
81+
viper.SetEnvPrefix("GOB")
82+
83+
// Convert dashes to underscores for environment variables.
84+
viper.SetEnvKeyReplacer(strings.NewReplacer(`-`, `_`))
85+
6886
viper.AutomaticEnv() // read in environment variables that match
6987

7088
// If a config file is found, read it in. Only displaying an error if there was a problem reading the file.

go.mod

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,16 @@ module github.com/gitops-bridge-dev/gitops-bridge-cli
22

33
go 1.21.3
44

5+
require (
6+
github.com/google/go-github/v56 v56.0.0
7+
github.com/sirupsen/logrus v1.9.3
8+
github.com/spf13/cobra v1.8.0
9+
github.com/spf13/viper v1.17.0
10+
)
11+
512
require (
613
github.com/fsnotify/fsnotify v1.6.0 // indirect
14+
github.com/google/go-querystring v1.1.0 // indirect
715
github.com/hashicorp/hcl v1.0.0 // indirect
816
github.com/inconshreveable/mousetrap v1.1.0 // indirect
917
github.com/magiconair/properties v1.8.7 // indirect
@@ -14,9 +22,7 @@ require (
1422
github.com/sourcegraph/conc v0.3.0 // indirect
1523
github.com/spf13/afero v1.10.0 // indirect
1624
github.com/spf13/cast v1.5.1 // indirect
17-
github.com/spf13/cobra v1.8.0 // indirect
1825
github.com/spf13/pflag v1.0.5 // indirect
19-
github.com/spf13/viper v1.17.0 // indirect
2026
github.com/subosito/gotenv v1.6.0 // indirect
2127
go.uber.org/atomic v1.9.0 // indirect
2228
go.uber.org/multierr v1.9.0 // indirect

go.sum

+24
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,16 @@ github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnht
4949
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
5050
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5151
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
52+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
53+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5254
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
5355
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
5456
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
5557
github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po=
5658
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
5759
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
60+
github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY=
61+
github.com/frankban/quicktest v1.14.4/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
5862
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
5963
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
6064
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
@@ -96,6 +100,12 @@ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
96100
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
97101
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
98102
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
103+
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
104+
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
105+
github.com/google/go-github/v56 v56.0.0 h1:TysL7dMa/r7wsQi44BjqlwaHvwlFlqkK8CtBWCX3gb4=
106+
github.com/google/go-github/v56 v56.0.0/go.mod h1:D8cdcX98YWJvi7TLo7zM4/h8ZTx6u6fwGEkCdisopo0=
107+
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
108+
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
99109
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
100110
github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
101111
github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
@@ -127,8 +137,12 @@ github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/X
127137
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
128138
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
129139
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
140+
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
141+
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
130142
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
131143
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
144+
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
145+
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
132146
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
133147
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
134148
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
@@ -138,13 +152,19 @@ github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdU
138152
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
139153
github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
140154
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
155+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
156+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
141157
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
142158
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
159+
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
160+
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
143161
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
144162
github.com/sagikazarmark/locafero v0.3.0 h1:zT7VEGWC2DTflmccN/5T1etyKvxSxpHsjb9cJvm4SvQ=
145163
github.com/sagikazarmark/locafero v0.3.0/go.mod h1:w+v7UsPNFwzF1cHuOajOOzoq4U7v/ig1mpRjqV+Bu1U=
146164
github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=
147165
github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ=
166+
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
167+
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
148168
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
149169
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
150170
github.com/spf13/afero v1.10.0 h1:EaGW2JJh15aKOejeuJ+wpFSHnbd7GE6Wvp3TsNhb6LY=
@@ -166,6 +186,7 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5
166186
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
167187
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
168188
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
189+
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
169190
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
170191
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
171192
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
@@ -311,6 +332,7 @@ golang.org/x/sys v0.0.0-20210225134936-a50acf3fe073/go.mod h1:h1NjWce9XRLGQEsW7w
311332
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
312333
golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
313334
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
335+
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
314336
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
315337
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
316338
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
@@ -469,6 +491,8 @@ google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGj
469491
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
470492
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
471493
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
494+
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
495+
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
472496
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
473497
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
474498
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=

pkg/gobgh/gobgh.go

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
Copyright © 2023 GitOps Bridge Project https://github.com/gitops-bridge-dev
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package gobgh
18+
19+
// import the go-github library
20+
import (
21+
"context"
22+
23+
"github.com/google/go-github/v56/github"
24+
)
25+
26+
// ForkRepo forks the repo
27+
func ForkRepo(token, org, repo string) (string, error) {
28+
ctx := context.Background()
29+
client := github.NewClient(nil).WithAuthToken(token)
30+
31+
// Fork the repo
32+
// TODO: Add support for forking into a specific organization/user and if it should be private or not
33+
fork, res, err := client.Repositories.CreateFork(ctx, org, repo, nil)
34+
35+
// Status code 202 is technically a success
36+
if err != nil && res.StatusCode != 202 {
37+
return "", err
38+
}
39+
40+
// Check if the fork was successfully created
41+
_, _, err = client.Repositories.Get(ctx, *fork.GetOwner().Login, repo)
42+
if err != nil {
43+
return "", err
44+
}
45+
46+
return fork.GetHTMLURL(), nil
47+
}

pkg/utils/utils.go

+12-5
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,18 @@ limitations under the License.
1616

1717
package utils
1818

19-
import "log"
19+
import "errors"
2020

21-
// CheckError checks if the error is nil or not
22-
func CheckError(e error) {
23-
if e != nil {
24-
log.Fatal(e)
21+
// VerifyAddOnRepo verifies the add on repo
22+
func VerifyAddOnRepo(s string) error {
23+
// Switch statement to check the add on repo
24+
switch s {
25+
case "gitops-bridge-argocd-control-plane-template":
26+
return nil
27+
case "":
28+
return errors.New("please provide an addon repo")
29+
default:
30+
// return an error if the add on repo is not valid
31+
return errors.New("invalid addon repo")
2532
}
2633
}

0 commit comments

Comments
 (0)