Skip to content

Commit ef3240a

Browse files
authored
Merge pull request #10 from manicminer/support-gitlab-subgroups
support subgroups in GitLab
2 parents ffa98c1 + 15b1155 commit ef3240a

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

main.go

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,28 @@ func main() {
372372
}
373373
}
374374

375+
func parseProjectSlugs(proj []string) ([]string, []string, error) {
376+
if len(proj) != 2 {
377+
return nil, nil, fmt.Errorf("too many fields")
378+
}
379+
380+
delimPosition := strings.LastIndex(proj[0], "/")
381+
gitlabPath := []string{
382+
proj[0][:delimPosition],
383+
proj[0][delimPosition+1:],
384+
}
385+
githubPath := strings.Split(proj[1], "/")
386+
387+
if len(gitlabPath) != 2 {
388+
return nil, nil, fmt.Errorf("invalid GitLab project: %s", proj[0])
389+
}
390+
if len(githubPath) != 2 {
391+
return nil, nil, fmt.Errorf("invalid GitHub project: %s", proj[1])
392+
}
393+
394+
return gitlabPath, githubPath, nil
395+
}
396+
375397
func printReport(ctx context.Context, projects []Project) {
376398
logger.Debug("building report")
377399

@@ -406,9 +428,11 @@ func printReport(ctx context.Context, projects []Project) {
406428
fmt.Println()
407429
}
408430

409-
func reportProject(ctx context.Context, proj []string) (*Report, error) {
410-
gitlabPath := strings.Split(proj[0], "/")
411-
//githubPath := strings.Split(proj[1], "/")
431+
func reportProject(_ context.Context, proj []string) (*Report, error) {
432+
gitlabPath, _, err := parseProjectSlugs(proj)
433+
if err != nil {
434+
return nil, fmt.Errorf("parsing project slugs: %v", err)
435+
}
412436

413437
logger.Debug("searching for GitLab project", "name", gitlabPath[1], "group", gitlabPath[0])
414438
searchTerm := gitlabPath[1]
@@ -523,8 +547,10 @@ func performMigration(ctx context.Context, projects []Project) error {
523547
}
524548

525549
func migrateProject(ctx context.Context, proj []string) error {
526-
gitlabPath := strings.Split(proj[0], "/")
527-
githubPath := strings.Split(proj[1], "/")
550+
gitlabPath, githubPath, err := parseProjectSlugs(proj)
551+
if err != nil {
552+
return fmt.Errorf("parsing project slugs: %v", err)
553+
}
528554

529555
logger.Info("searching for GitLab project", "name", gitlabPath[1], "group", gitlabPath[0])
530556
searchTerm := gitlabPath[1]

0 commit comments

Comments
 (0)