Skip to content

Commit

Permalink
Fix CI errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Kuziemko committed Dec 21, 2021
1 parent 539aa40 commit 7087348
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
21 changes: 10 additions & 11 deletions cmd/populator/cmd/register/ocf_manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import (
)

type sourceInfo struct {
dir string
files []string
rootDir string
gitHash []byte
}

Expand Down Expand Up @@ -94,7 +94,7 @@ func runDBPopulateWithSources(ctx context.Context, sources []string) (err error)
var fileList []string
var commits []string
for _, src := range sourcesInfo {
err = filesAlreadyExists(seenFiles, src.files)
err = filesAlreadyExists(seenFiles, src.files, src.rootDir)
if err != nil {
return errors.Wrap(err, "while validating the source files")
}
Expand Down Expand Up @@ -193,9 +193,9 @@ func getSourcesInfo(ctx context.Context, cfg dbpopulator.Config, log *zap.Logger
return nil, errors.Wrap(err, "while getting `git rev-parse HEAD`")
}
sourcesInfo = append(sourcesInfo, sourceInfo{
dir: parent,
files: files,
gitHash: gitHash,
rootDir: rootDir,
})
}
return sourcesInfo, nil
Expand Down Expand Up @@ -230,9 +230,9 @@ func createTempDirName(suffix string) (string, error) {
return hex.EncodeToString(randBytes) + suffix, nil
}

func filesAlreadyExists(container map[string]struct{}, files []string) error {
func filesAlreadyExists(container map[string]struct{}, files []string, rootDir string) error {
for _, file := range files {
shortPath := getPathWithoutRootDir(file)
shortPath := trimRootDir(file, rootDir)
if _, ok := container[shortPath]; ok {
return fmt.Errorf("duplicate path for: %s", shortPath)
}
Expand All @@ -241,23 +241,22 @@ func filesAlreadyExists(container map[string]struct{}, files []string) error {
return nil
}

func getPathWithoutRootDir(fullPath string) string {
parts := strings.Split(fullPath, string(os.PathSeparator))
return path.Join(parts[4:]...)
}

func trimSSHkey(s string) string {
if idx := strings.LastIndex(s, "&sshkey="); idx != -1 {
return s[:idx]
}
return s
}

func trimRootDir(s string, rootDir string) string {
return strings.TrimPrefix(s, rootDir)[1:]
}

func runDBPopulate(ctx context.Context, cfg dbpopulator.Config, session neo4j.Session, log *zap.Logger, source sourceInfo) (err error) {
start := time.Now()
err = retry.Do(func() error {
populated, err := dbpopulator.Populate(
ctx, log, session, source.files, source.dir, fmt.Sprintf("%s:%d", cfg.JSONPublishAddr, cfg.JSONPublishPort))
ctx, log, session, source.files, source.rootDir, fmt.Sprintf("%s:%d", cfg.JSONPublishAddr, cfg.JSONPublishPort))
if err != nil {
log.Error("Cannot populate a new data", zap.String("error", err.Error()))
return err
Expand Down
4 changes: 2 additions & 2 deletions pkg/sdk/dbpopulator/populator.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ func IsDataInDB(session neo4j.Session, log *zap.Logger, commits []string) (bool,
}

log.Info("git commits did not change. Finishing")
return false, nil
return true, nil
}

// SaveCommitsMetadata saves the commits from the repositories in the DB
Expand Down Expand Up @@ -598,7 +598,7 @@ func currentCommits(session neo4j.Session) (string, error) {
}
commit, ok := record.Values[0].(string)
if !ok {
return "", fmt.Errorf("Failed to convert database response: %v", record.Values[0])
return "", fmt.Errorf("failed to convert database response: %v", record.Values[0])
}

return commit, errors.Wrap(result.Err(), "while executing neo4j transaction")
Expand Down

0 comments on commit 7087348

Please sign in to comment.