fix: migrate from master to main (#63)

This commit is contained in:
Teppei Fukuda 2020-12-18 00:05:35 +09:00 committed by GitHub
parent 3747382c12
commit 38a3516f0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 18 additions and 17 deletions

View File

@ -1,7 +1,7 @@
# vuln-list-update # vuln-list-update
[![Go Report Card](https://goreportcard.com/badge/github.com/aquasecurity/vuln-list-update)](https://goreportcard.com/report/github.com/aquasecurity/vuln-list-update) [![Go Report Card](https://goreportcard.com/badge/github.com/aquasecurity/vuln-list-update)](https://goreportcard.com/report/github.com/aquasecurity/vuln-list-update)
[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://github.com/aquasecurity/vuln-list-update/blob/master/LICENSE) [![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://github.com/aquasecurity/vuln-list-update/blob/main/LICENSE)
Collect vulnerability information and save it in parsable format automatically Collect vulnerability information and save it in parsable format automatically

View File

@ -19,6 +19,7 @@ import (
const ( const (
alpineDir = "alpine" alpineDir = "alpine"
defaultBranch = "master"
repoURL = "https://git.alpinelinux.org/aports/" repoURL = "https://git.alpinelinux.org/aports/"
) )
@ -38,7 +39,7 @@ type Config struct {
func (c Config) Update() (err error) { func (c Config) Update() (err error) {
log.Println("Fetching Alpine data...") log.Println("Fetching Alpine data...")
repoDir = filepath.Join(c.CacheDir, "aports") repoDir = filepath.Join(c.CacheDir, "aports")
if _, err = c.GitClient.CloneOrPull(repoURL, repoDir); err != nil { if _, err = c.GitClient.CloneOrPull(repoURL, repoDir, defaultBranch); err != nil {
return xerrors.Errorf("failed to clone alpine repository: %w", err) return xerrors.Errorf("failed to clone alpine repository: %w", err)
} }
@ -51,7 +52,7 @@ func (c Config) Update() (err error) {
// restore branch // restore branch
defer func() { defer func() {
if derr := c.GitClient.Checkout(repoDir, "master"); derr != nil { if derr := c.GitClient.Checkout(repoDir, defaultBranch); derr != nil {
log.Printf("checkout error: %s", derr) log.Printf("checkout error: %s", derr)
} }
}() }()

View File

@ -24,8 +24,8 @@ type MockGitConfig struct {
mock.Mock mock.Mock
} }
func (mgc *MockGitConfig) CloneOrPull(a string, b string) (map[string]struct{}, error) { func (mgc *MockGitConfig) CloneOrPull(a string, b string, c string) (map[string]struct{}, error) {
args := mgc.Called(a, b) args := mgc.Called(a, b, c)
return args.Get(0).(map[string]struct{}), args.Error(1) return args.Get(0).(map[string]struct{}), args.Error(1)
} }
@ -366,7 +366,7 @@ func TestConfig_Update(t *testing.T) {
// setup expectations with a placeholder in the argument list // setup expectations with a placeholder in the argument list
mockGitConfig.On("RemoteBranch", repoDir).Return( mockGitConfig.On("RemoteBranch", repoDir).Return(
tc.remoteBranch.returnArg, tc.remoteBranch.err) tc.remoteBranch.returnArg, tc.remoteBranch.err)
mockGitConfig.On("CloneOrPull", mock.Anything, repoDir).Return( mockGitConfig.On("CloneOrPull", mock.Anything, repoDir, "master").Return(
tc.cloneOrPull.returnArg, tc.cloneOrPull.err) tc.cloneOrPull.returnArg, tc.cloneOrPull.err)
for arg, returnErr := range tc.checkout { for arg, returnErr := range tc.checkout {
mockGitConfig.On("Checkout", repoDir, arg).Return(returnErr) mockGitConfig.On("Checkout", repoDir, arg).Return(returnErr)

View File

@ -13,7 +13,7 @@ import (
) )
type Operations interface { type Operations interface {
CloneOrPull(string, string) (map[string]struct{}, error) CloneOrPull(string, string, string) (map[string]struct{}, error)
RemoteBranch(string) ([]string, error) RemoteBranch(string) ([]string, error)
Checkout(string, string) error Checkout(string, string) error
} }
@ -21,7 +21,7 @@ type Operations interface {
type Config struct { type Config struct {
} }
func (gc Config) CloneOrPull(url, repoPath string) (map[string]struct{}, error) { func (gc Config) CloneOrPull(url, repoPath, branch string) (map[string]struct{}, error) {
exists, err := utils.Exists(filepath.Join(repoPath, ".git")) exists, err := utils.Exists(filepath.Join(repoPath, ".git"))
if err != nil { if err != nil {
return nil, err return nil, err
@ -30,7 +30,7 @@ func (gc Config) CloneOrPull(url, repoPath string) (map[string]struct{}, error)
updatedFiles := map[string]struct{}{} updatedFiles := map[string]struct{}{}
if exists { if exists {
log.Println("git pull") log.Println("git pull")
files, err := pull(url, repoPath) files, err := pull(url, repoPath, branch)
if err != nil { if err != nil {
return nil, xerrors.Errorf("git pull error: %w", err) return nil, xerrors.Errorf("git pull error: %w", err)
} }
@ -75,7 +75,7 @@ func clone(url, repoPath string) error {
return nil return nil
} }
func pull(url, repoPath string) ([]string, error) { func pull(url, repoPath, branch string) ([]string, error) {
commandArgs := generateGitArgs(repoPath) commandArgs := generateGitArgs(repoPath)
remoteCmd := []string{"remote", "get-url", "--push", "origin"} remoteCmd := []string{"remote", "get-url", "--push", "origin"}
@ -99,7 +99,7 @@ func pull(url, repoPath string) ([]string, error) {
return nil, nil return nil, nil
} }
pullCmd := []string{"pull", "origin", "master"} pullCmd := []string{"pull", "origin", branch}
if _, err = utils.Exec("git", append(commandArgs, pullCmd...)); err != nil { if _, err = utils.Exec("git", append(commandArgs, pullCmd...)); err != nil {
return nil, xerrors.Errorf("error in git pull: %w", err) return nil, xerrors.Errorf("error in git pull: %w", err)
} }

View File

@ -64,7 +64,7 @@ func run() error {
log.Printf("target repository is %s/%s\n", repoOwner, repoName) log.Printf("target repository is %s/%s\n", repoOwner, repoName)
if _, err := gc.CloneOrPull(url, utils.VulnListDir()); err != nil { if _, err := gc.CloneOrPull(url, utils.VulnListDir(), "main"); err != nil {
return xerrors.Errorf("clone or pull error: %w", err) return xerrors.Errorf("clone or pull error: %w", err)
} }
@ -193,7 +193,7 @@ func run() error {
} }
log.Println("git push") log.Println("git push")
if err = gc.Push(utils.VulnListDir(), "master"); err != nil { if err = gc.Push(utils.VulnListDir(), "main"); err != nil {
return xerrors.Errorf("failed to git push: %w", err) return xerrors.Errorf("failed to git push: %w", err)
} }

View File

@ -10,7 +10,7 @@ git commit -m "$3"
ret=$? ret=$?
if [ $ret = 0 ]; then if [ $ret = 0 ]; then
git push https://${GITHUB_TOKEN}@github.com/aquasecurity/vuln-list.git master git push https://${GITHUB_TOKEN}@github.com/aquasecurity/vuln-list.git main
else else
echo "skip push" echo "skip push"
fi fi

View File

@ -67,7 +67,7 @@ type Status struct {
func Update() error { func Update() error {
gc := git.Config{} gc := git.Config{}
dir := filepath.Join(utils.CacheDir(), "ubuntu-cve-tracker") dir := filepath.Join(utils.CacheDir(), "ubuntu-cve-tracker")
if _, err := gc.CloneOrPull(repoURL, dir); err != nil { if _, err := gc.CloneOrPull(repoURL, dir, "master"); err != nil {
return xerrors.Errorf("failed to clone or pull: %w", err) return xerrors.Errorf("failed to clone or pull: %w", err)
} }