Add filename length limit on gitlab repos with name collisions (#242)

This commit is contained in:
Jay Gabriels
2022-08-28 09:18:22 -07:00
committed by GitHub
parent 89337a404f
commit bb780ef2a1
3 changed files with 27 additions and 2 deletions

View File

@@ -3,6 +3,15 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
## [1.8.8] - unreleased
### Added
- Filename length limit on gitlab repos with name collisions
### Changed
### Deprecated
### Removed
### Fixed
### Security
## [1.8.7] - 7/19/22
### Added
### Changed

View File

@@ -470,6 +470,15 @@ func printDryRun(repos []scm.Repo) {
}
}
func trimCollisionFilename(filename string) string {
maxLen := 248
if len(filename) > maxLen {
return filename[:strings.LastIndex(filename[:maxLen], "_")]
}
return filename
}
// CloneAllRepos clones all repos
func CloneAllRepos(git git.Gitter, cloneTargets []scm.Repo) {
// Filter repos that have attributes that don't need specific scm api calls
@@ -558,7 +567,14 @@ func CloneAllRepos(git git.Gitter, cloneTargets []scm.Repo) {
// Only GitLab repos can have collisions due to groups and subgroups
// If there are collisions and this is a repo with a naming collision change name to avoid collisions
if hasCollisions && repoNameWithCollisions[repo.Name] {
repoSlug = strings.Replace(repo.Path, "/", "_", -1)
repoSlug = trimCollisionFilename(strings.Replace(repo.Path, "/", "_", -1))
// If a collision has another collision with trimmed name append a number
if _, ok := repoNameWithCollisions[repoSlug]; ok {
repoSlug = fmt.Sprintf("_%v_%v", strconv.Itoa(i), repoSlug)
} else {
repoNameWithCollisions[repoSlug] = true
}
}
repo.HostPath = filepath.Join(outputDirAbsolutePath, repoSlug)

View File

@@ -6,7 +6,7 @@ import (
"github.com/spf13/cobra"
)
const ghorgVersion = "v1.8.7"
const ghorgVersion = "v1.8.8"
var versionCmd = &cobra.Command{
Use: "version",