Skip to content

Commit 72ec2ba

Browse files
authored
fix: add downloading tips and add SHA for updating github files (#76)
* add downloading tips add getting sha from github for delete opt add function note
1 parent 9acee5d commit 72ec2ba

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

Diff for: internal/pkg/githubactions/githubactions.go

+16-12
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ func (ga *GithubActions) GetLanguage() *Language {
4444
}
4545

4646
func (ga *GithubActions) AddWorkflow(workflow *Workflow) error {
47-
exists, err := ga.fileExists(workflow.workflowFileName)
47+
sha, err := ga.getFileSHA(workflow.workflowFileName)
4848
if err != nil {
4949
return err
5050
}
51-
if exists {
51+
if sha != "" {
5252
log.Printf("github actions Workflow %s already exists\n", workflow.workflowFileName)
5353
return nil
5454
}
@@ -77,11 +77,11 @@ func (ga *GithubActions) AddWorkflow(workflow *Workflow) error {
7777
}
7878

7979
func (ga *GithubActions) DeleteWorkflow(workflow *Workflow) error {
80-
exists, err := ga.fileExists(workflow.workflowFileName)
80+
sha, err := ga.getFileSHA(workflow.workflowFileName)
8181
if err != nil {
8282
return err
8383
}
84-
if !exists {
84+
if sha == "" {
8585
log.Printf("github actions Workflow %s already removed\n", workflow.workflowFileName)
8686
return nil
8787
}
@@ -109,27 +109,31 @@ func (ga *GithubActions) DeleteWorkflow(workflow *Workflow) error {
109109
return nil
110110
}
111111

112-
func (ga *GithubActions) fileExists(filename string) (bool, error) {
113-
_, _, resp, err := ga.client.Repositories.GetContents(
112+
// getFileSHA:
113+
// 1. if file exists without error: return (string(SHA), nil)
114+
// 2. if some errors occurred: return ("", err)
115+
// 3. if file not found without error: return ("", nil)
116+
func (ga *GithubActions) getFileSHA(filename string) (string, error) {
117+
content, _, resp, err := ga.client.Repositories.GetContents(
114118
ga.ctx,
115119
ga.options.Owner,
116120
ga.options.Repo,
117121
generateGitHubWorkflowFileByName(filename),
118122
&github.RepositoryContentGetOptions{},
119123
)
120124

121-
if err != nil {
122-
return false, err
125+
if resp.StatusCode == http.StatusNotFound {
126+
return "", nil
123127
}
124128

125-
if resp.StatusCode == http.StatusNotFound {
126-
return false, nil
129+
if err != nil {
130+
return "", err
127131
}
128132

129133
if resp.StatusCode == http.StatusOK {
130-
return true, nil
134+
return *content.SHA, nil
131135
}
132-
return false, fmt.Errorf("got some error is not expected")
136+
return "", fmt.Errorf("got some error is not expected")
133137
}
134138

135139
func generateGitHubWorkflowFileByName(f string) string {

Diff for: internal/pkg/pluginmanager/manager.go

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package pluginmanager
22

33
import (
44
"errors"
5+
"log"
56
"os"
67
"path/filepath"
78

@@ -19,10 +20,12 @@ func DownloadPlugins(conf *configloader.Config) error {
1920
pluginFileName := configloader.GetPluginFileName(&tool)
2021
if _, err := os.Stat(filepath.Join(pluginsDir, pluginFileName)); errors.Is(err, os.ErrNotExist) {
2122
// plugin does not exist
23+
log.Printf("=== now downloading plugin: %s ,version: %s === \n", pluginFileName, tool.Version)
2224
err := dc.download(pluginsDir, pluginFileName, tool.Version)
2325
if err != nil {
2426
return err
2527
}
28+
log.Printf("=== plugin: %s ,version: %s downloaded === \n", pluginFileName, tool.Version)
2629
}
2730
}
2831

0 commit comments

Comments
 (0)