Skip to content

Commit bdae23f

Browse files
committed
Fix the plugins repo issue
1 parent 6c626e2 commit bdae23f

File tree

6 files changed

+19
-16
lines changed

6 files changed

+19
-16
lines changed

go.mod

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@ module github.com/linuxsuren/go-cli-plugin
33
go 1.15
44

55
require (
6-
github.com/golang/mock v1.4.4
76
github.com/gosuri/uilive v0.0.3 // indirect
87
github.com/gosuri/uiprogress v0.0.1
9-
github.com/linuxsuren/cobra-extension v0.0.1 // indirect
8+
github.com/linuxsuren/cobra-extension v0.0.1
109
github.com/mattn/go-isatty v0.0.12 // indirect
1110
github.com/mitchellh/go-homedir v1.1.0
12-
github.com/onsi/ginkgo v1.14.2
13-
github.com/onsi/gomega v1.10.3
1411
github.com/pkg/errors v0.9.1
1512
github.com/spf13/cobra v1.1.1
1613
github.com/stretchr/testify v1.6.1 // indirect

pkg/cmd/fetch.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ import (
1616

1717
// NewConfigPluginFetchCmd create a command for fetching plugin metadata
1818
func NewConfigPluginFetchCmd(pluginOrg, pluginRepo string) (cmd *cobra.Command) {
19-
pluginFetchCmd := jcliPluginFetchCmd{
20-
PluginOrg: pluginOrg,
21-
PluginRepo: pluginRepo,
19+
pluginFetchCmd := &jcliPluginFetchCmd{
20+
PluginOrg: pluginOrg,
21+
PluginRepoName: pluginRepo,
2222
}
2323

2424
cmd = &cobra.Command{
@@ -34,7 +34,7 @@ but you can change it by giving a command parameter.`, pluginFetchCmd.PluginOrg,
3434
// add flags
3535
flags := cmd.Flags()
3636
flags.StringVarP(&pluginFetchCmd.PluginRepo, "plugin-repo", "",
37-
fmt.Sprintf("https://github.com/%s/%s", pluginFetchCmd.PluginOrg, pluginFetchCmd.PluginRepo),
37+
fmt.Sprintf("https://github.com/%s/%s", pluginFetchCmd.PluginOrg, pluginFetchCmd.PluginRepoName),
3838
"The plugin git repository URL")
3939
flags.BoolVarP(&pluginFetchCmd.Reset, "reset", "", true,
4040
"If you want to reset the git local repo when pulling it")
@@ -56,11 +56,12 @@ func (c *jcliPluginFetchCmd) Run(cmd *cobra.Command, args []string) (err error)
5656
return
5757
}
5858

59-
pluginRepo := fmt.Sprintf("%s/.%s/plugins-repo", userHome, c.PluginRepo)
59+
pluginRepoCache := fmt.Sprintf("%s/.jenkins-cli/plugins-repo", userHome)
6060
c.output = cmd.OutOrStdout()
6161

62+
cmd.Printf("start to fetch metadata from '%s', cache to '%s'\n", c.PluginRepo, pluginRepoCache)
6263
var r *git.Repository
63-
if r, err = git.PlainOpen(pluginRepo); err == nil {
64+
if r, err = git.PlainOpen(pluginRepoCache); err == nil {
6465
var w *git.Worktree
6566
if w, err = r.Worktree(); err != nil {
6667
return
@@ -80,7 +81,7 @@ func (c *jcliPluginFetchCmd) Run(cmd *cobra.Command, args []string) (err error)
8081
}
8182
} else {
8283
cloneOptions := c.getCloneOptions()
83-
_, err = git.PlainClone(pluginRepo, false, cloneOptions)
84+
_, err = git.PlainClone(pluginRepoCache, false, cloneOptions)
8485
}
8586
return
8687
}

pkg/cmd/install.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (c *jcliPluginInstallCmd) Run(cmd *cobra.Command, args []string) (err error
4747
}
4848

4949
var data []byte
50-
pluginsMetadataFile := fmt.Sprintf("%s/.%s/plugins-repo/%s.yaml", c.PluginRepo, userHome, name)
50+
pluginsMetadataFile := fmt.Sprintf("%s/.%s/plugins-repo/%s.yaml", userHome, c.PluginRepo, name)
5151
if data, err = ioutil.ReadFile(pluginsMetadataFile); err == nil {
5252
plugin := pkg.Plugin{}
5353
if err = yaml.Unmarshal(data, &plugin); err == nil {

pkg/cmd/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
// NewConfigPluginListCmd create a command for list all jcli plugins
99
func NewConfigPluginListCmd() (cmd *cobra.Command) {
10-
configPluginListCmd := configPluginListCmd{}
10+
configPluginListCmd := &configPluginListCmd{}
1111

1212
cmd = &cobra.Command{
1313
Use: "list",

pkg/cmd/type.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ type (
1919
Password string
2020
SSHKeyFile string
2121

22-
output io.Writer
23-
PluginOrg string
22+
output io.Writer
23+
PluginOrg string
24+
PluginRepoName string
2425
}
2526

2627
jcliPluginInstallCmd struct {

pkg/core.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ func FindPlugins() (plugins []Plugin, err error) {
3737

3838
plugins = make([]Plugin, 0)
3939
pluginsDir := fmt.Sprintf("%s/.jenkins-cli/plugins-repo/*.yaml", userHome)
40-
if files, err := filepath.Glob(pluginsDir); err == nil {
40+
//fmt.Println("start to parse plugin file from dir", pluginsDir)
41+
var files []string
42+
if files, err = filepath.Glob(pluginsDir); err == nil {
4143
for _, metaFile := range files {
4244
var data []byte
4345
plugin := Plugin{}
@@ -54,6 +56,8 @@ func FindPlugins() (plugins []Plugin, err error) {
5456
}
5557
plugins = append(plugins, plugin)
5658
}
59+
} else {
60+
fmt.Println("failed to parse file", metaFile)
5761
}
5862
}
5963
}

0 commit comments

Comments
 (0)