Skip to content

Commit

Permalink
fix: use publiccode.yml's url when cloning the repo locally (italia#265)
Browse files Browse the repository at this point in the history
fix: use publiccode.yml's url when cloning the repo locally

Use the URL in publiccode.yml when cloning the repo locally, so the
vitality of software using metarepos is calculated against the actual software
repository instead of the metarepo itself.

Fix italia#264.
  • Loading branch information
bfabio committed May 10, 2022
1 parent e20520c commit c2c51ee
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions crawler/crawler/cloneRepository.go
Expand Up @@ -12,7 +12,7 @@ import (
)

// CloneRepository clone the repository into DATADIR/repos/<hostname>/<vendor>/<repo>/gitClone
func CloneRepository(domain Domain, hostname, name, gitURL, gitBranch, index string) error {
func CloneRepository(domain Domain, hostname, name, gitURL, index string) error {
if domain.Host == "" {
return errors.New("cannot save a file without domain host")
}
Expand All @@ -33,17 +33,17 @@ func CloneRepository(domain Domain, hostname, name, gitURL, gitBranch, index str
if err != nil {
return errors.New(fmt.Sprintf("cannot git pull the repository: %s: %s", err.Error(), out))
}
// Command is: git reset --hard origin/<branch_name>
out, err = exec.Command("git", "-C", path, "reset", "--hard", "origin/"+gitBranch).CombinedOutput() // nolint: gas
out, err = exec.Command("git", "-C", path, "reset", "--hard", "origin/HEAD").CombinedOutput() // nolint: gas
if err != nil {
return errors.New(fmt.Sprintf("cannot git pull the repository: %s: %s", err.Error(), out))
}
return err

return nil
}

// Clone the repository using the external command "git".
// Command is: git clone -b <branch> <remote_repo>
out, err := exec.Command("git", "clone", "-b", gitBranch, gitURL, path).CombinedOutput() // nolint: gas
out, err := exec.Command("git", "clone", gitURL, path).CombinedOutput() // nolint: gas
if err != nil {
return errors.New(fmt.Sprintf("cannot git clone the repository: %s: %s", err.Error(), out))
}
Expand Down
2 changes: 1 addition & 1 deletion crawler/crawler/crawler.go
Expand Up @@ -437,7 +437,7 @@ func (c *Crawler) ProcessRepo(repository Repository) {
}

// Clone repository.
err = CloneRepository(repository.Domain, repository.Hostname, repository.Name, repository.GitCloneURL, repository.GitBranch, c.index)
err = CloneRepository(repository.Domain, repository.Hostname, repository.Name, parser.PublicCode.URL.String(), c.index)
if err != nil {
message = fmt.Sprintf("[%s] error while cloning: %v\n", repository.Name, err)
log.Errorf(message)
Expand Down

0 comments on commit c2c51ee

Please sign in to comment.