Skip to content

panic: index out of range [1] when syncing repository team permissions with byRepos #36

@sivakinfomagnus

Description

@sivakinfomagnus

panic: index out of range [1] when syncing repository team permissions with byRepos

Describe the bug

When running gh migrate-teams sync byRepos with --skip-teams flag to sync repository permissions to existing teams, the command panics with an index out of range error in team.GetRepositoryTeams().

To Reproduce

Steps to reproduce the behavior:

  1. Create a text file with repository names to sync (e.g., repositories.txt containing jenkins)
  2. Run the command:
    gh migrate-teams sync byRepos \
      --source-token <source_pat> \
      --target-organization <target_org> \
      --target-token <target_pat> \
      --from-file repositories.txt \
      --skip-teams \
      --mapping-file user_mapping.csv
  3. Command successfully fetches repositories from the list
  4. Starts "Fetching teams for repository: jenkins"
  5. See error: panic: runtime error: index out of range [1] with length 1

Full error output:

2026/03/03 19:53:54 Fetched a total of 1 repositories from the repository list
2026/03/03 19:53:54 Fetching teams for repository: jenkins
panic: runtime error: index out of range [1] with length 1

goroutine 1 [running]:
github.com/mona-actions/gh-migrate-teams/internal/team.GetRepositoryTeams({0xc000012ee0?, 0x0?})
	github.com/mona-actions/gh-migrate-teams/internal/team/team.go:202 +0x7db
github.com/mona-actions/gh-migrate-teams/pkg/sync.SyncTeamsByRepo()
	github.com/mona-actions/gh-migrate-teams/pkg/sync/sync.go:128 +0x465
github.com/mona-actions/gh-migrate-teams/cmd.init.func1(0x10141e0, {0xacdc67?, 0x4?, 0xacdc17?})
	github.com/mona-actions/gh-migrate-teams/cmd/byRepos.go:61 +0x638
github.com/spf13/cobra.(*Command).execute(0x10141e0, {0xc000116580, 0xb, 0xb})
	github.com/spf13/cobra@v1.8.0/command.go:987 +0xa91
github.com/spf13/cobra.(*Command).ExecuteC(0x10147a0)
	github.com/spf13/cobra@v1.8.0/command.go:1115 +0x3ff
github.com/spf13/cobra.(*Command).Execute(...)
	github.com/spf13/cobra@v1.8.0/command.go:1039
github.com/mona-actions/gh-migrate-teams/cmd.Execute()
	github.com/mona-actions/gh-migrate-teams/cmd/root.go:26 +0x1a
main.main()
	github.com/mona-actions/gh-migrate-teams/main.go:9 +0xf

Expected behavior

The command should successfully fetch team permissions from the source repository and apply them to the target repository without crashing. Teams already exist in the target organization (created separately), and the --skip-teams flag should only sync repository permissions to those existing teams.

Environment

(please complete the following information)

  • Go version: embedded in gh extension (gh-migrate-teams latest)
  • Shell Type: zsh
  • Terminal: native Linux terminal
  • gh CLI version: 2.45.0 (2025-07-18 Ubuntu 2.45.0-1ubuntu0.3)
  • gh-migrate-teams: Latest version (installed via gh extension install mona-actions/gh-migrate-teams)
  • OS: Ubuntu/Linux
  • Source: GitHub.com (GHEC)
  • Target: GitHub.com (GHEC EMU)

Additional context

  • The panic occurs at team.go:202 in the GetRepositoryTeams function, indicating an attempt to access array index [1] when the array only has length 1 (valid indices: 0)
  • This appears to be a logic error where the code assumes at least 2 elements in an array when there might only be 1
  • The repository being migrated is a valid repository with existing team permissions in the source organization
  • Teams already exist in the target organization (created via separate process before running this command)
  • Other gh-migrate-teams commands (like team export/import) work correctly
  • Currently working around this by using GitHub REST API directly to set team repository permissions

Issue URL: https://github.com/mona-actions/gh-migrate-teams/issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions