-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Move the options parsing out of main * move more stuff out of main
- Loading branch information
Showing
8 changed files
with
286 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package main | ||
|
||
type appConfig struct { | ||
service string | ||
gitHostURL string | ||
backupDir string | ||
ignorePrivate bool | ||
ignoreFork bool | ||
useHTTPSClone bool | ||
bare bool | ||
|
||
githubRepoType string | ||
githubNamespaceWhitelist []string | ||
githubCreateUserMigration bool | ||
githubCreateUserMigrationRetry bool | ||
githubCreateUserMigrationRetryMax int | ||
githubListUserMigrations bool | ||
githubWaitForMigrationComplete bool | ||
|
||
gitlabProjectVisibility string | ||
gitlabProjectMembershipType string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"sync" | ||
) | ||
|
||
func handleGitRepositoryClone(client interface{}, c *appConfig) { | ||
|
||
// Used for waiting for all the goroutines to finish before exiting | ||
var wg sync.WaitGroup | ||
defer wg.Wait() | ||
|
||
tokens := make(chan bool, MaxConcurrentClones) | ||
gitHostUsername = getUsername(client, c.service) | ||
|
||
if len(gitHostUsername) == 0 && !*ignorePrivate && *useHTTPSClone { | ||
log.Fatal("Your Git host's username is needed for backing up private repositories via HTTPS") | ||
} | ||
repos, err := getRepositories( | ||
client, | ||
c.service, | ||
c.githubRepoType, | ||
c.githubNamespaceWhitelist, | ||
c.gitlabProjectVisibility, | ||
c.gitlabProjectMembershipType, | ||
c.ignoreFork, | ||
) | ||
if err != nil { | ||
log.Fatal(err) | ||
} else { | ||
log.Printf("Backing up %v repositories now..\n", len(repos)) | ||
for _, repo := range repos { | ||
tokens <- true | ||
wg.Add(1) | ||
go func(repo *Repository) { | ||
stdoutStderr, err := backUp(c.backupDir, repo, c.bare, &wg) | ||
if err != nil { | ||
log.Printf("Error backing up %s: %s\n", repo.Name, stdoutStderr) | ||
} | ||
<-tokens | ||
}(repo) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"time" | ||
) | ||
|
||
func handleGithubCreateUserMigration(client interface{}, c *appConfig) { | ||
repos, err := getRepositories( | ||
client, | ||
c.service, | ||
c.githubRepoType, | ||
c.githubNamespaceWhitelist, | ||
c.gitlabProjectVisibility, | ||
c.gitlabProjectMembershipType, | ||
c.ignoreFork, | ||
) | ||
if err != nil { | ||
log.Fatalf("Error getting list of repositories: %v", err) | ||
} | ||
|
||
log.Printf("Creating a user migration for %d repos", len(repos)) | ||
m, err := createGithubUserMigration( | ||
context.Background(), | ||
client, repos, | ||
c.githubCreateUserMigrationRetry, | ||
c.githubCreateUserMigrationRetryMax, | ||
) | ||
if err != nil { | ||
log.Fatalf("Error creating migration: %v", err) | ||
} | ||
|
||
if c.githubWaitForMigrationComplete { | ||
migrationStatePollingDuration := 60 * time.Second | ||
err = downloadGithubUserMigrationData( | ||
context.Background(), | ||
client, c.backupDir, | ||
m.ID, | ||
migrationStatePollingDuration, | ||
) | ||
if err != nil { | ||
log.Fatalf("Error querying/downloading migration: %v", err) | ||
} | ||
} | ||
|
||
orgs, err := getGithubUserOwnedOrgs(context.Background(), client) | ||
if err != nil { | ||
log.Fatal("Error getting user organizations", err) | ||
} | ||
for _, o := range orgs { | ||
orgRepos, err := getGithubOrgRepositories(context.Background(), client, o) | ||
if err != nil { | ||
log.Fatal("Error getting org repos", err) | ||
} | ||
if len(orgRepos) == 0 { | ||
log.Printf("No repos found in %s", *o.Login) | ||
continue | ||
} | ||
log.Printf("Creating a org migration (%s) for %d repos", *o.Login, len(orgRepos)) | ||
oMigration, err := createGithubOrgMigration(context.Background(), client, *o.Login, orgRepos) | ||
if err != nil { | ||
log.Fatalf("Error creating migration: %v", err) | ||
} | ||
if c.githubWaitForMigrationComplete { | ||
migrationStatePollingDuration := 60 * time.Second | ||
downloadGithubOrgMigrationData( | ||
context.Background(), | ||
client, | ||
*o.Login, | ||
c.backupDir, | ||
oMigration.ID, | ||
migrationStatePollingDuration, | ||
) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
|
||
"github.com/google/go-github/v34/github" | ||
) | ||
|
||
func handleGithubListUserMigrations(client interface{}, c *appConfig) { | ||
|
||
mList, err := getGithubUserMigrations(client) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
for _, m := range mList { | ||
mData, err := GetGithubUserMigration(client, m.ID) | ||
if err != nil { | ||
fmt.Printf("Error getting migration data: %v", *m.ID) | ||
// FIXME | ||
continue | ||
} | ||
|
||
var archiveURL string | ||
_, err = client.(*github.Client).Migrations.UserMigrationArchiveURL(context.Background(), *m.ID) | ||
if err != nil { | ||
archiveURL = "No Longer Available" | ||
} else { | ||
archiveURL = "Available for Download" | ||
} | ||
fmt.Printf("%v - %v - %v - %v\n", *mData.ID, *mData.CreatedAt, *mData.State, archiveURL) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.