示例#1
0
func runPeriodicSync(client *gh.Client, config *Config) {
	// Get the list of repositories.
	repos := make([]*storage.Repository, 0, len(config.Repositories))
	for _, r := range config.Repositories {
		repos = append(repos, r)
	}

	// Run a default synchronization job, with the storage type set to
	// StoreCurrentState (which corresponds to our rolling storage).
	syncOptions := github.DefaultSyncOptions
	syncOptions.SleepPerPage = 10 // TODO Tired of getting blacklisted :-)
	syncOptions.State = github.GitHubStateFilterOpened
	syncOptions.Storage = storage.StoreCurrentState

	// Create the blobStore and run the syncCommand.
	blobStore := storage.NewTransformingBlobStore()
	github.NewSyncCommandWithOptions(client, blobStore, &syncOptions).Run(repos)
}
示例#2
0
// doSyncCommand runs a synchronization job: it fetches all GitHub issues and
// pull requests starting with the From index. It uses the API pagination to
// reduce API calls, and allows a Sleep delay between each page to avoid
// triggering the abuse detection mechanism.
func doSyncCommand(c *cli.Context) {
	config := ParseConfigOrDie(c.GlobalString("config"))
	client := github.NewClient(config.GitHubAPIToken)
	blobStore := storage.NewTransformingBlobStore()

	// Get the list of repositories from command-line (defaults to all).
	repoToSync := c.Args()
	if len(repoToSync) == 0 {
		repoToSync = make([]string, 0, len(config.Repositories))
		for givenName, _ := range config.Repositories {
			repoToSync = append(repoToSync, givenName)
		}
	}

	// Get the repositories instances from their given names.
	repos := make([]*storage.Repository, 0, len(repoToSync))
	for _, givenName := range repoToSync {
		r, ok := config.Repositories[givenName]
		if !ok {
			log.Fatalf("unknown repository %q", givenName)
		}
		repos = append(repos, r)
	}

	// Configure a syncJob taking all issues (opened and closed) and storing
	// in the snapshot store.
	syncOptions := github.DefaultSyncOptions
	syncOptions.From = c.Int("from")
	syncOptions.SleepPerPage = c.Int("sleep")
	syncOptions.State = github.GitHubStateFilterAll
	syncOptions.Storage = storage.StoreSnapshot

	// Create and run the synchronization job.
	log.Warnf("running sync jobs on repositories %s", strings.Join(repoToSync, ", "))
	github.NewSyncCommandWithOptions(client, blobStore, &syncOptions).Run(repos)
}