mirrors

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 30, 2023 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrNotFound

func ErrNotFound(resource, name string) error

func GitURL

func GitURL(repository *Repository, authType GitAuthType) string

func RemoveDuplicates

func RemoveDuplicates(strs []string) []string

func ReposToMap

func ReposToMap(repos []*Repository) map[string]*Repository

ReposToMap convert Repository List to map

func StringListToMap

func StringListToMap(strs []string) map[string]string

StringListToMap convert strings list to map

func StringsEqual

func StringsEqual(a, b *string) bool

StringsEqual compare two string point; if value equal return true; else false

Types

type GitAuthType

type GitAuthType int
const (
	GitKeyAuth GitAuthType = iota
	GitAccessTokenAuth
	GitUsernamePasswordAuth
)

type GitClient

type GitClient struct {
	Timeout     time.Duration
	GitAuthType GitAuthType
	// contains filtered or unexported fields
}

func NewGitAccessTokenClient

func NewGitAccessTokenClient(accessToken string, timeout time.Duration, debug bool) (*GitClient, error)

NewGitAccessTokenClient access_token auth

func NewGitPrivateKeysClient

func NewGitPrivateKeysClient(privateKeyFile, keyPassword string, timeout time.Duration, debug bool) (*GitClient, error)

NewGitPrivateKeysClient ssh key auth

func NewGitUsernamePasswordClient

func NewGitUsernamePasswordClient(username, password string, timeout time.Duration, debug bool) (*GitClient, error)

NewGitUsernamePasswordClient username password auth

func (*GitClient) Clone

func (c *GitClient) Clone(url, path string) error

Clone clone git to local directory

func (*GitClient) CloneOrFetch added in v0.2.0

func (c *GitClient) CloneOrFetch(url, remoteName, path string) (bool, error)

CloneOrFetch if path is not exist run git clone, else fetch

func (*GitClient) CloneOrPull

func (c *GitClient) CloneOrPull(url, remoteName, path string) (bool, error)

CloneOrPull if path is not exist run git clone, else pull

func (*GitClient) CreateRemote

func (c *GitClient) CreateRemote(urls []string, remoteName, path string) error

CreateRemote create remote url eg. https://github.com/git-fixtures/basic.git

func (*GitClient) DeleteBranch added in v0.2.0

func (c *GitClient) DeleteBranch(branchName, path string, repo *git.Repository) error

DeleteBranch delete special branch

func (*GitClient) DeleteRemote

func (c *GitClient) DeleteRemote(remoteName, path string) error

DeleteRemote delete special remote

func (*GitClient) Fetch added in v0.2.0

func (c *GitClient) Fetch(remoteName, path string) error

Fetch git repo changes to local directory

func (*GitClient) Mirror added in v0.2.0

func (c *GitClient) Mirror(remoteName, path string, force bool) error

Push open a repository in a specific path, and push to its remoteName remote. equal git cmd:

git push --prune --tags [--force] [origin|gitee|github] "refs/*:refs/*" #refs/remotes/origin/*:refs/heads/*

func (*GitClient) Pull

func (c *GitClient) Pull(remoteName, path string) error

Pull git repo changes to local directory

type GiteeAPI

type GiteeAPI struct {
	Client  *gitee.APIClient
	Context context.Context

	IsAuthed bool
	// contains filtered or unexported fields
}

func NewGiteeAPI

func NewGiteeAPI(accessToken string) (*GiteeAPI, error)

NewGiteeAPI return new Gitee API

func (*GiteeAPI) CreateOrgRepo

func (g *GiteeAPI) CreateOrgRepo(baseRepo *Repository, orgName string) (*Repository, error)

CreateOrgRepo create a new org repository

func (*GiteeAPI) CreateRepository

func (g *GiteeAPI) CreateRepository(baseRepo *Repository, orgName string) (*Repository, error)

CreateRepository create a new repository, if repo is already exist, just return it

func (*GiteeAPI) CreateUserRepo

func (g *GiteeAPI) CreateUserRepo(baseRepo *Repository) (*Repository, error)

CreateUserRepo create a new user repository

func (*GiteeAPI) GetOrganization

func (g *GiteeAPI) GetOrganization(orgName string) (*Organization, error)

func (*GiteeAPI) GetRepository

func (g *GiteeAPI) GetRepository(orgName, repoName string) (*Repository, error)

GetRepository fetches a repository

func (*GiteeAPI) IsAPIAuthed added in v0.2.3

func (g *GiteeAPI) IsAPIAuthed() bool

IsAPIAuthed return is the API auth, true or false

func (*GiteeAPI) Organizations

func (g *GiteeAPI) Organizations(user string) ([]*Organization, error)

Organizations list all Organizations

func (*GiteeAPI) Repositories

func (g *GiteeAPI) Repositories(user string) ([]*Repository, error)

Repositories list all repositories for the authenticated user

func (*GiteeAPI) RepositoriesByOrg

func (g *GiteeAPI) RepositoriesByOrg(orgName string) ([]*Repository, error)

RepositoriesByOrg list repositories for special org

func (*GiteeAPI) UpdateRepository

func (g *GiteeAPI) UpdateRepository(orgName, repoName string, baseRepo *Repository) (*Repository, error)

UpdateRepository updates a repository

type GithubAPI

type GithubAPI struct {
	Client  *github.Client
	Context context.Context

	IsAuthed bool
	// contains filtered or unexported fields
}

func NewGithubAPI

func NewGithubAPI(accessToken string) (*GithubAPI, error)

NewGithubAPI return new Github API

func (*GithubAPI) CreateRepository

func (g *GithubAPI) CreateRepository(baseRepo *Repository, orgName string) (*Repository, error)

CreateRepository create a new repository, if repo is already exist, just return it

func (*GithubAPI) GetOrganization

func (g *GithubAPI) GetOrganization(orgName string) (*Organization, error)

GetOrganization get an organization by name

func (*GithubAPI) GetRepository

func (g *GithubAPI) GetRepository(orgName, repoName string) (*Repository, error)

GetRepository fetches a repository

func (*GithubAPI) IsAPIAuthed added in v0.2.3

func (g *GithubAPI) IsAPIAuthed() bool

IsAPIAuthed return is the API auth, true or false

func (*GithubAPI) Organizations

func (g *GithubAPI) Organizations(user string) ([]*Organization, error)

Organizations list Organizations

func (*GithubAPI) Repositories

func (g *GithubAPI) Repositories(user string) ([]*Repository, error)

Repositories list all repositories for the authenticated user, if user is empty show all repos support two method:

https://docs.github.com/en/rest/repos/repos#list-repositories-for-the-authenticated-user if user is empty
https://docs.github.com/en/rest/repos/repos#list-repositories-for-a-user if user is special

func (*GithubAPI) RepositoriesByOrg

func (g *GithubAPI) RepositoriesByOrg(orgName string) ([]*Repository, error)

RepositoriesByOrg list repositories for special org

func (*GithubAPI) UpdateRepository

func (g *GithubAPI) UpdateRepository(orgName, repoName string, baseRepo *Repository) (*Repository, error)

UpdateRepository updates a repository

type IGitAPI

type IGitAPI interface {
	IsAPIAuthed() bool
	Organizations(user string) ([]*Organization, error)
	GetOrganization(orgName string) (*Organization, error)
	Repositories(user string) ([]*Repository, error)
	GetRepository(orgName, repoName string) (*Repository, error)
	CreateRepository(baseRepo *Repository, orgName string) (*Repository, error)
	UpdateRepository(orgName, repoName string, baseRepo *Repository) (*Repository, error)
	RepositoriesByOrg(orgName string) ([]*Repository, error)
}

type IMirror

type IMirror interface {
	Do() error
	// contains filtered or unexported methods
}

type Mirror

type Mirror struct {
	SrcGit string
	SrcOrg string

	DstGit string
	DstOrg string

	SrcAccountType string
	DstAccountType string
	CloneStyle     string
	CachePath      string
	BlackList      []string
	WhiteList      []string
	ForceUpdate    bool
	Debug          bool
	Timeout        time.Duration
	Mappings       map[string]string
	// contains filtered or unexported fields
}

func New

func New(srcGit, srcOrg, srcToken, dstGit, dstOrg, dstKey, dstToken, srcAccountType, dstAccountType, cloneStyle,
	cachePath string, blackList, whiteList []string, forceUpdate, debug bool, timeout time.Duration,
	mappings map[string]string) *Mirror

func (*Mirror) Do

func (m *Mirror) Do() error

Do mirror logic

type Organization

type Organization struct {
	Name        *string `json:"name,omitempty"`
	Description *string `json:"description,omitempty"`
	Type        *string `json:"type,omitempty"` // github: Organization or User; gitee: personal or group
}

type Repository

type Repository struct {
	Owner        *User         `json:"owner,omitempty"`
	Name         *string       `json:"name,omitempty"`
	FullName     *string       `json:"full_name,omitempty"`
	Description  *string       `json:"description,omitempty"`
	HTMLURL      *string       `json:"html_url,omitempty"`
	CloneURL     *string       `json:"clone_url,omitempty"`
	GitURL       *string       `json:"git_url,omitempty"`
	SSHURL       *string       `json:"ssh_url,omitempty"`
	Homepage     *string       `json:"homepage,omitempty"`
	Fork         *bool         `json:"fork,omitempty"`
	Organization *Organization `json:"organization,omitempty"`
	Topics       []string      `json:"topics,omitempty"`

	// Additional mutable fields when creating and editing a repository
	Private  *bool `json:"private,omitempty"`
	Archived *bool `json:"archived,omitempty"`
}

Repository represents a Common repository.

type User

type User struct {
	Name *string `json:"name,omitempty"`
	Type *string `json:"type,omitempty"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL