func doImportPocket(c *cli.Context) { if pocket.ConsumerKey == "" { utils.Log("error", "Built without consumer key set") return } accessToken, err := GitConfig("ghq.pocket.token") utils.PanicIf(err) if accessToken == "" { receiverURL, ch, err := pocket.StartAccessTokenReceiver() utils.PanicIf(err) utils.Log("pocket", "Waiting for Pocket authentication callback at "+receiverURL) utils.Log("pocket", "Obtaining request token") authRequest, err := pocket.ObtainRequestToken(receiverURL) utils.DieIf(err) url := pocket.GenerateAuthorizationURL(authRequest.Code, receiverURL) utils.Log("open", url) <-ch utils.Log("pocket", "Obtaining access token") authorized, err := pocket.ObtainAccessToken(authRequest.Code) utils.DieIf(err) utils.Log("authorized", authorized.Username) accessToken = authorized.AccessToken utils.Run("git", "config", "ghq.pocket.token", authorized.AccessToken) } utils.Log("pocket", "Retrieving github.com entries") res, err := pocket.RetrieveGitHubEntries(accessToken) utils.DieIf(err) for _, item := range res.List { url, err := url.Parse(item.ResolvedURL) if err != nil { utils.Log("error", fmt.Sprintf("Could not parse URL <%s>: %s", item.ResolvedURL, err)) continue } remote, err := NewRemoteRepository(url) if utils.ErrorIf(err) { continue } if remote.IsValid() == false { utils.Log("skip", fmt.Sprintf("Not a valid repository: %s", url)) continue } getRemoteRepository(remote, c.Bool("update")) } }
var GitBackend = &VCSBackend{ Clone: func(remote *url.URL, local string, shallow bool) error { dir, _ := filepath.Split(local) err := os.MkdirAll(dir, 0755) if err != nil { return err } args := []string{"clone"} if shallow { args = append(args, "--depth", "1") } args = append(args, remote.String(), local) return utils.Run("git", args...) }, Update: func(local string) error { return utils.RunInDir(local, "git", "pull", "--ff-only") }, } var MercurialBackend = &VCSBackend{ // Mercurial seems not supporting shallow clone currently. Clone: func(remote *url.URL, local string, ignoredShallow bool) error { dir, _ := filepath.Split(local) err := os.MkdirAll(dir, 0755) if err != nil { return err }