mirror of
https://github.com/cooperspencer/gickup
synced 2024-11-08 12:09:18 +01:00
parent
d96310d74a
commit
bee477bf65
@ -3,12 +3,18 @@ package github
|
||||
import (
|
||||
"context"
|
||||
"gickup/types"
|
||||
|
||||
"github.com/google/go-github/v41/github"
|
||||
"github.com/rs/zerolog/log"
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
||||
func addWiki(r github.Repository, repo types.GenRepo, token string) types.Repo {
|
||||
if r.GetHasWiki() && repo.Wiki && r.GetHasPages() {
|
||||
return types.Repo{Name: *r.Name + ".wiki", Url: types.DotGitRx.ReplaceAllString(r.GetCloneURL(), ".wiki.git"), SshUrl: types.DotGitRx.ReplaceAllString(r.GetSSHURL(), ".wiki.git"), Token: token, Defaultbranch: r.GetDefaultBranch(), Origin: repo, Owner: r.GetOwner().GetLogin(), Hoster: "github.com"}
|
||||
}
|
||||
return types.Repo{}
|
||||
}
|
||||
|
||||
func Get(conf *types.Conf) []types.Repo {
|
||||
repos := []types.Repo{}
|
||||
for _, repo := range conf.Source.Github {
|
||||
@ -76,8 +82,9 @@ func Get(conf *types.Conf) []types.Repo {
|
||||
for _, r := range githubrepos {
|
||||
if include[*r.Name] {
|
||||
repos = append(repos, types.Repo{Name: r.GetName(), Url: r.GetCloneURL(), SshUrl: r.GetSSHURL(), Token: token, Defaultbranch: r.GetDefaultBranch(), Origin: repo, Owner: r.GetOwner().GetLogin(), Hoster: "github.com"})
|
||||
if *r.HasWiki && repo.Wiki && *r.HasPages {
|
||||
repos = append(repos, types.Repo{Name: *r.Name + ".wiki", Url: types.DotGitRx.ReplaceAllString(r.GetCloneURL(), ".wiki.git"), SshUrl: types.DotGitRx.ReplaceAllString(r.GetSSHURL(), ".wiki.git"), Token: token, Defaultbranch: r.GetDefaultBranch(), Origin: repo, Owner: r.GetOwner().GetLogin(), Hoster: "github.com"})
|
||||
wiki := addWiki(*r, repo, token)
|
||||
if wiki.Name != "" {
|
||||
repos = append(repos, wiki)
|
||||
}
|
||||
continue
|
||||
}
|
||||
@ -91,14 +98,16 @@ func Get(conf *types.Conf) []types.Repo {
|
||||
if len(includeorgs) > 0 {
|
||||
if includeorgs[r.GetOwner().GetLogin()] {
|
||||
repos = append(repos, types.Repo{Name: r.GetName(), Url: r.GetCloneURL(), SshUrl: r.GetSSHURL(), Token: token, Defaultbranch: r.GetDefaultBranch(), Origin: repo, Owner: r.GetOwner().GetLogin(), Hoster: "github.com"})
|
||||
if *r.HasWiki && repo.Wiki && *r.HasPages {
|
||||
repos = append(repos, types.Repo{Name: *r.Name + ".wiki", Url: types.DotGitRx.ReplaceAllString(r.GetCloneURL(), ".wiki.git"), SshUrl: types.DotGitRx.ReplaceAllString(r.GetSSHURL(), ".wiki.git"), Token: token, Defaultbranch: r.GetDefaultBranch(), Origin: repo, Owner: r.GetOwner().GetLogin(), Hoster: "github.com"})
|
||||
wiki := addWiki(*r, repo, token)
|
||||
if wiki.Name != "" {
|
||||
repos = append(repos, wiki)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
repos = append(repos, types.Repo{Name: r.GetName(), Url: r.GetCloneURL(), SshUrl: r.GetSSHURL(), Token: token, Defaultbranch: r.GetDefaultBranch(), Origin: repo, Owner: r.GetOwner().GetLogin(), Hoster: "github.com"})
|
||||
if *r.HasWiki && repo.Wiki && *r.HasPages {
|
||||
repos = append(repos, types.Repo{Name: *r.Name + ".wiki", Url: types.DotGitRx.ReplaceAllString(r.GetCloneURL(), ".wiki.git"), SshUrl: types.DotGitRx.ReplaceAllString(r.GetSSHURL(), ".wiki.git"), Token: token, Defaultbranch: r.GetDefaultBranch(), Origin: repo, Owner: r.GetOwner().GetLogin(), Hoster: "github.com"})
|
||||
wiki := addWiki(*r, repo, token)
|
||||
if wiki.Name != "" {
|
||||
repos = append(repos, wiki)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/go-git/go-git/v5"
|
||||
"github.com/go-git/go-git/v5/config"
|
||||
"github.com/go-git/go-git/v5/plumbing/transport"
|
||||
"github.com/go-git/go-git/v5/plumbing/transport/http"
|
||||
"github.com/go-git/go-git/v5/plumbing/transport/ssh"
|
||||
@ -68,6 +69,10 @@ func Locally(repo types.Repo, l types.Local, dry bool) {
|
||||
if x == tries {
|
||||
log.Fatal().Str("stage", "locally").Str("path", l.Path).Str("repo", repo.Name).Msg(err.Error())
|
||||
} else {
|
||||
if strings.Contains(err.Error(), "ERR access denied or repository not exported") {
|
||||
log.Warn().Str("stage", "locally").Str("path", l.Path).Str("repo", repo.Name).Msgf("%s doesn't exist.", repo.Name)
|
||||
break
|
||||
}
|
||||
if strings.Contains(err.Error(), "remote repository is empty") {
|
||||
log.Warn().Str("stage", "locally").Str("path", l.Path).Str("repo", repo.Name).Msg(err.Error())
|
||||
break
|
||||
@ -110,6 +115,13 @@ func updateRepository(repoPath string, auth transport.AuthMethod, dry bool) erro
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
remote, _ := r.Remote("origin")
|
||||
|
||||
rem := git.NewRemote(nil, &config.RemoteConfig{Name: "origin", URLs: remote.Config().URLs})
|
||||
_, err = rem.List(&git.ListOptions{Auth: auth})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
w, err := r.Worktree()
|
||||
if err != nil {
|
||||
@ -145,7 +157,13 @@ func cloneRepository(repo types.Repo, auth transport.AuthMethod, dry bool) error
|
||||
}
|
||||
}
|
||||
|
||||
_, err := git.PlainClone(repo.Name, false, &git.CloneOptions{
|
||||
rem := git.NewRemote(nil, &config.RemoteConfig{Name: "origin", URLs: []string{url}})
|
||||
_, err := rem.List(&git.ListOptions{Auth: auth})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = git.PlainClone(repo.Name, false, &git.CloneOptions{
|
||||
URL: url,
|
||||
Auth: auth,
|
||||
SingleBranch: false,
|
||||
|
Loading…
Reference in New Issue
Block a user