Skip to content

Commit

Permalink
adding user sync flag (#7)
Browse files Browse the repository at this point in the history
* adding user sync flag

* forgot to remove spinner

* wrong spinner, putting back
  • Loading branch information
antgrutta authored Nov 1, 2023
1 parent fac870f commit 95fcc1c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Flags:
-a, --source-token string Source Organization GitHub token. Scopes: read:org, read:user, user:email
-t, --target-organization string Target Organization to sync teams from
-b, --target-token string Target Organization GitHub token. Scopes: admin:org
-u, --user-sync string User sync mode. One of: all, disable (default "none")
```

### Mapping File Example
Expand Down
5 changes: 5 additions & 0 deletions cmd/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var syncCmd = &cobra.Command{
targetToken := cmd.Flag("target-token").Value.String()
mappingFile := cmd.Flag("mapping-file").Value.String()
ghHostname := cmd.Flag("source-hostname").Value.String()
userSync := cmd.Flag("user-sync").Value.String()

// Set ENV variables
os.Setenv("GHMT_SOURCE_ORGANIZATION", sourceOrganization)
Expand All @@ -32,6 +33,7 @@ var syncCmd = &cobra.Command{
os.Setenv("GHMT_TARGET_TOKEN", targetToken)
os.Setenv("GHMT_MAPPING_FILE", mappingFile)
os.Setenv("GHMT_SOURCE_HOSTNAME", ghHostname)
os.Setenv("GHMT_USER_SYNC", userSync)

// Bind ENV variables in Viper
viper.BindEnv("SOURCE_ORGANIZATION")
Expand All @@ -40,6 +42,7 @@ var syncCmd = &cobra.Command{
viper.BindEnv("TARGET_TOKEN")
viper.BindEnv("MAPPING_FILE")
viper.BindEnv("SOURCE_HOSTNAME")
viper.BindEnv("USER_SYNC")
// Call syncTeams
sync.SyncTeams()
},
Expand All @@ -65,4 +68,6 @@ func init() {

syncCmd.Flags().StringP("source-hostname", "u", "", "GitHub Enterprise source hostname url (optional) Ex. https://github.example.com")

syncCmd.Flags().StringP("user-sync", "u", "all", "User sync mode. One of: all, disable (default \"none\")")

}
10 changes: 8 additions & 2 deletions internal/team/team.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"time"

"github.com/mona-actions/gh-migrate-teams/internal/api"
"github.com/spf13/viper"
)

type Teams []Team
Expand Down Expand Up @@ -104,8 +105,13 @@ func (t Team) CreateTeam() {
api.AddTeamRepository(t.Slug, repository.Name, repository.Permission)
}

for _, member := range t.Members {
api.AddTeamMember(t.Slug, member.Login)
// Check to see if user sync has been disabled
userSync := viper.GetString("USER_SYNC")

if userSync != "disable" {
for _, member := range t.Members {
api.AddTeamMember(t.Slug, member.Login)
}
}
}

Expand Down

0 comments on commit 95fcc1c

Please sign in to comment.