1
1
mirror of https://github.com/cooperspencer/gickup synced 2024-11-08 12:09:18 +01:00

fix: stat github wiki remotes to verify their existence (#98)

* fix: stat github wiki remotes to verify their existence

* fix: also check gitea wiki remotes
This commit is contained in:
Matthew Toohey 2022-03-02 13:21:23 -08:00 committed by GitHub
parent 8b0f820ec8
commit 545c9e3f73
Signed by: GitHub
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 5 deletions

@ -95,7 +95,7 @@ func Get(conf *types.Conf) []types.Repo {
for _, r := range gitearepos {
if include[r.Name] {
repos = append(repos, types.Repo{Name: r.Name, Url: r.CloneURL, SshUrl: r.SSHURL, Token: token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: r.Owner.UserName, Hoster: types.GetHost(repo.Url)})
if r.HasWiki && repo.Wiki {
if r.HasWiki && repo.Wiki && types.StatRemote(r.CloneURL, r.SSHURL, repo) {
repos = append(repos, types.Repo{Name: r.Name + ".wiki", Url: types.DotGitRx.ReplaceAllString(r.CloneURL, ".wiki.git"), SshUrl: types.DotGitRx.ReplaceAllString(r.SSHURL, ".wiki.git"), Token: token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: r.Owner.UserName, Hoster: types.GetHost(repo.Url)})
}
continue
@ -105,7 +105,7 @@ func Get(conf *types.Conf) []types.Repo {
}
if len(repo.Include) == 0 {
repos = append(repos, types.Repo{Name: r.Name, Url: r.CloneURL, SshUrl: r.SSHURL, Token: token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: r.Owner.UserName, Hoster: types.GetHost(repo.Url)})
if r.HasWiki && repo.Wiki {
if r.HasWiki && repo.Wiki && types.StatRemote(r.CloneURL, r.SSHURL, repo) {
repos = append(repos, types.Repo{Name: r.Name + ".wiki", Url: types.DotGitRx.ReplaceAllString(r.CloneURL, ".wiki.git"), SshUrl: types.DotGitRx.ReplaceAllString(r.SSHURL, ".wiki.git"), Token: token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: r.Owner.UserName, Hoster: types.GetHost(repo.Url)})
}
}
@ -152,7 +152,7 @@ func Get(conf *types.Conf) []types.Repo {
for _, r := range orgrepos {
if include[r.Name] {
repos = append(repos, types.Repo{Name: r.Name, Url: r.CloneURL, SshUrl: r.SSHURL, Token: token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: r.Owner.UserName, Hoster: types.GetHost(repo.Url)})
if r.HasWiki && repo.Wiki {
if r.HasWiki && repo.Wiki && types.StatRemote(r.CloneURL, r.SSHURL, repo) {
repos = append(repos, types.Repo{Name: r.Name + ".wiki", Url: types.DotGitRx.ReplaceAllString(r.CloneURL, ".wiki.git"), SshUrl: types.DotGitRx.ReplaceAllString(r.SSHURL, ".wiki.git"), Token: token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: r.Owner.UserName, Hoster: types.GetHost(repo.Url)})
}
continue
@ -162,7 +162,7 @@ func Get(conf *types.Conf) []types.Repo {
}
if len(repo.Include) == 0 {
repos = append(repos, types.Repo{Name: r.Name, Url: r.CloneURL, SshUrl: r.SSHURL, Token: token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: r.Owner.UserName, Hoster: types.GetHost(repo.Url)})
if r.HasWiki && repo.Wiki {
if r.HasWiki && repo.Wiki && types.StatRemote(r.CloneURL, r.SSHURL, repo) {
repos = append(repos, types.Repo{Name: r.Name + ".wiki", Url: types.DotGitRx.ReplaceAllString(r.CloneURL, ".wiki.git"), SshUrl: types.DotGitRx.ReplaceAllString(r.SSHURL, ".wiki.git"), Token: token, Defaultbranch: r.DefaultBranch, Origin: repo, Owner: r.Owner.UserName, Hoster: types.GetHost(repo.Url)})
}
}

@ -9,7 +9,7 @@ import (
)
func addWiki(r github.Repository, repo types.GenRepo, token string) types.Repo {
if r.GetHasWiki() && repo.Wiki && r.GetHasPages() {
if r.GetHasWiki() && repo.Wiki && types.StatRemote(r.GetCloneURL(), r.GetSSHURL(), repo) {
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{}

@ -3,11 +3,17 @@ package types
import (
"fmt"
"os"
"path"
"regexp"
"strconv"
"strings"
"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"
"github.com/gookit/color"
"github.com/robfig/cron/v3"
"github.com/rs/zerolog/log"
@ -275,3 +281,35 @@ func GetMap(excludes []string) map[string]bool {
}
return excludemap
}
func StatRemote(URL, sshURL string, repo GenRepo) bool {
var url string
var auth transport.AuthMethod
var err error
if repo.SSH {
url = DotGitRx.ReplaceAllString(sshURL, ".wiki.git")
if repo.SSHKey == "" {
home := os.Getenv("HOME")
repo.SSHKey = path.Join(home, ".ssh", "id_rsa")
}
auth, err = ssh.NewPublicKeysFromFile("git", repo.SSHKey, "")
if err != nil {
panic(err)
}
} else {
url = DotGitRx.ReplaceAllString(URL, ".wiki.git")
if repo.Token != "" {
auth = &http.BasicAuth{
Username: "xyz",
Password: repo.Token,
}
} else if repo.Username != "" && repo.Password != "" {
auth = &http.BasicAuth{
Username: repo.Username,
Password: repo.Password,
}
}
}
_, err = git.NewRemote(nil, &config.RemoteConfig{Name: "origin", URLs: []string{url}}).List(&git.ListOptions{Auth: auth})
return err == nil
}