provider

package
v0.0.0-...-95ed4c6 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2019 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package provider provides an interface for querying git provider APIs

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsHosted

func IsHosted(u string) bool

IsHosted checks if the specified URL is a Git SaaS provider

func MigrateWiki

func MigrateWiki(repo *GitRepository, id *auth.ID) error

func ToGitLabelStringSlice

func ToGitLabelStringSlice(labels []GitLabel) *[]string

ToGitLabelStringSlice converts a list of GitLabels to a list of strings

func UsersToString

func UsersToString(users []GitUser) *[]string

UsersToString converts a list of GitUsers to a pointer to a slice of user strings

Types

type CachedIssue

type CachedIssue struct {
	Issue *GitIssue

	Comments map[time.Time]*GitIssueComment
	// contains filtered or unexported fields
}

type CachedRepo

type CachedRepo struct {
	Repo *GitRepository

	Issues map[string]*CachedIssue

	Labels map[string]*GitLabel
	// contains filtered or unexported fields
}

type FakeIssue

type FakeIssue struct {
	Issue    *GitIssue
	Comments []*GitIssueComment
}

FakeIssue stores information about git issues and their associated comments

type FakeProvider

type FakeProvider struct {
	Repositories *sync.Map
}

FakeProvider stores a thread safe hashmap of repository data

func (*FakeProvider) CreateIssue

func (f *FakeProvider) CreateIssue(issue *GitIssue) (*GitIssue, error)

CreateIssue creates a new fake issue

func (*FakeProvider) CreateIssueComment

func (f *FakeProvider) CreateIssueComment(issueNum int, comment *GitIssueComment) error

CreateIssueComment creates a new fake issue comment

func (*FakeProvider) CreateLabel

func (f *FakeProvider) CreateLabel(label *GitLabel) (*GitLabel, error)

CreateLabel creates a new fake issue label

func (*FakeProvider) CreateRepository

func (f *FakeProvider) CreateRepository(srcRepo *GitRepository) (*GitRepository, error)

CreateRepository creates a new Fake repository

func (*FakeProvider) GetAuth

func (f *FakeProvider) GetAuth() *auth.ID

GetAuthToken returns a string with a user's api authentication token

func (*FakeProvider) GetComments

func (f *FakeProvider) GetComments(pid, issueNum int, repo string) ([]*GitIssueComment, error)

GetComments gets the fake provider's comments

func (*FakeProvider) GetImportProgress

func (f *FakeProvider) GetImportProgress(repo string) (string, error)

func (*FakeProvider) GetIssues

func (f *FakeProvider) GetIssues(pid int, repo string) ([]*GitIssue, error)

GetIssues gets the fake provider's issues

func (*FakeProvider) GetLabels

func (f *FakeProvider) GetLabels(pid int, repo string) ([]*GitLabel, error)

GetLabels gets the fake provider's labels

func (*FakeProvider) GetRepositories

func (f *FakeProvider) GetRepositories() ([]*GitRepository, error)

GetRepositories gets the fake provider's repositories

func (*FakeProvider) MigrateRepo

func (f *FakeProvider) MigrateRepo(repo *GitRepository, token string) (string, error)

MigrateRepo migrates a git repo from an existing provider

type FakeRepository

type FakeRepository struct {
	GitRepo     *GitRepository
	Issues      *sync.Map
	Labels      []*GitLabel
	Private     bool
	Description string
	// contains filtered or unexported fields
}

FakeRepository stores information about a new git repository

type GitIssue

type GitIssue struct {
	Repo      string
	PID       int
	Number    int
	Title     string
	Body      string
	State     string
	Labels    []GitLabel
	User      *GitUser
	Assignees []GitUser
}

GitIssue stores general git SaaS issue data

type GitIssueComment

type GitIssueComment struct {
	Repo      string
	IssueNum  int
	User      GitUser
	Body      string
	CreatedAt time.Time
	UpdatedAt time.Time
}

GitIssueComment stores general SaaS git issue comment data

type GitLabel

type GitLabel struct {
	Repo        string
	Name        string
	Color       string
	Description string
}

GitLabel stores general git SaaS label data

func ToGitLabels

func ToGitLabels(names []string) []GitLabel

ToGitLabels converts a list of strings into a list of GitLabels

type GitProvider

type GitProvider interface {
	// Create methods
	CreateRepository(*GitRepository) (*GitRepository, error)

	CreateIssue(*GitIssue) (*GitIssue, error)

	CreateIssueComment(int, *GitIssueComment) error

	CreateLabel(*GitLabel) (*GitLabel, error)

	MigrateRepo(*GitRepository, string) (string, error)

	// Read methods
	GetRepositories() ([]*GitRepository, error)

	GetIssues(int, string) ([]*GitIssue, error)

	GetComments(int, int, string) ([]*GitIssueComment, error)

	GetLabels(int, string) ([]*GitLabel, error)

	GetAuth() *auth.ID

	GetImportProgress(string) (string, error)
}

GitProvider

func NewFakeProvider

func NewFakeProvider() GitProvider

NewFakeProvider creates a new fake provider

func NewGithubProvider

func NewGithubProvider(ctx context.Context, id *auth.ID) (GitProvider, error)

NewGithubProvider creates a new GitHub clients which implements the provider interface

func NewGitlabProvider

func NewGitlabProvider(id *auth.ID) (GitProvider, error)

NewGitlabProvider creates a new GitLab client which implements the provider interface

func WithGithubClient

func WithGithubClient(ctx context.Context, client *github.Client, id *auth.ID) GitProvider

WithGithubClient creates a new GitProvider with a GitHub client

func WithGitlabClient

func WithGitlabClient(client *gitlab.Client, id *auth.ID) GitProvider

WithGitlabClient creates a new GitProvider with a Gitlab client This function is exported to create mock clients in tests

type GitRepository

type GitRepository struct {
	Name        string
	Description string
	CloneURL    string
	SSHURL      string
	Owner       string
	Archived    bool
	Fork        bool
	Empty       bool
	PID         int
}

GitRepository stores general git repository data

type GitUser

type GitUser struct {
	Login string
	Name  string
	Email string
}

GitUser stores general git SaaS user data

type GithubProvider

type GithubProvider struct {
	Client  *github.Client
	Context context.Context
	ID      *auth.ID

	Repocache map[string]*CachedRepo
	Members   map[string]*github.User
	// contains filtered or unexported fields
}

GitHubProvider implements the provider interface for GitHub

func (*GithubProvider) CreateIssue

func (g *GithubProvider) CreateIssue(issue *GitIssue) (*GitIssue, error)

CreateIssue creates a new GitHub issue

func (*GithubProvider) CreateIssueComment

func (g *GithubProvider) CreateIssueComment(issueNum int, comment *GitIssueComment) error

CreateIssueComment creates a new GitHub issue comment

func (*GithubProvider) CreateLabel

func (g *GithubProvider) CreateLabel(srcLabel *GitLabel) (*GitLabel, error)

CreateLabel creates a new GitHub issue label

func (*GithubProvider) CreateRepository

func (g *GithubProvider) CreateRepository(srcRepo *GitRepository) (*GitRepository, error)

CreateRepository creates a new GitHub repository

func (*GithubProvider) GetAuth

func (g *GithubProvider) GetAuth() *auth.ID

GetAuth returns a string with a user's api authentication token

func (*GithubProvider) GetComments

func (g *GithubProvider) GetComments(pid, issueNum int, repo string) ([]*GitIssueComment, error)

GetComments retrieves a list of issue comments associated with a GitHub issue

func (*GithubProvider) GetImportProgress

func (g *GithubProvider) GetImportProgress(repoName string) (string, error)

GetImportProgress checks the progress of a previously started GitHub import

func (*GithubProvider) GetIssues

func (g *GithubProvider) GetIssues(pid int, repo string) ([]*GitIssue, error)

GetIssues retrieves a list of issues associated with a GitHub repository

func (*GithubProvider) GetLabels

func (g *GithubProvider) GetLabels(pid int, repo string) ([]*GitLabel, error)

GetLabels retrieves a list of labels associated with a GitHub repository

func (*GithubProvider) GetRepositories

func (g *GithubProvider) GetRepositories() ([]*GitRepository, error)

GetRepositories retrieves a list of GitHub repositories for the organization/owner

func (*GithubProvider) LoadCache

func (g *GithubProvider) LoadCache() error

func (*GithubProvider) MigrateRepo

func (g *GithubProvider) MigrateRepo(repo *GitRepository, token string) (string, error)

MigrateRepo migrates a repo from an existing provider into GitHub

func (*GithubProvider) NewCachedIssue

func (g *GithubProvider) NewCachedIssue(issue *GitIssue) *CachedIssue

func (*GithubProvider) NewCachedRepo

func (g *GithubProvider) NewCachedRepo(repo *GitRepository)

func (*GithubProvider) PrintCache

func (g *GithubProvider) PrintCache()

func (*GithubProvider) RepositoryExists

func (g *GithubProvider) RepositoryExists(name string) bool

RepositoryExists checks if a given repostory already exists in GitHub

type GitlabProvider

type GitlabProvider struct {
	Client  *gitlab.Client
	Context context.Context
	ID      *auth.ID
}

GitlabProvider implements the provider interface for GitLab

func (*GitlabProvider) CreateIssue

func (g *GitlabProvider) CreateIssue(issue *GitIssue) (*GitIssue, error)

CreateIssue creates a new GitLab issue

func (*GitlabProvider) CreateIssueComment

func (g *GitlabProvider) CreateIssueComment(issueNum int, comment *GitIssueComment) error

CreateIssueComment creates a new GitLab issue note/comment

func (*GitlabProvider) CreateLabel

func (g *GitlabProvider) CreateLabel(label *GitLabel) (*GitLabel, error)

CreateLabel creates a new GitLab issue label

func (*GitlabProvider) CreateRepository

func (g *GitlabProvider) CreateRepository(repo *GitRepository) (*GitRepository, error)

CreateRepository creates a new GitLab repository

func (*GitlabProvider) GetAuth

func (g *GitlabProvider) GetAuth() *auth.ID

GetAuthToken returns a string with a user's api authentication token

func (*GitlabProvider) GetComments

func (g *GitlabProvider) GetComments(pid, issueNum int, repo string) ([]*GitIssueComment, error)

GetComments retrieves a full list of comments for a project issue For >100 comments this _depaginates_ the responses and appends them to one slice

func (*GitlabProvider) GetImportProgress

func (g *GitlabProvider) GetImportProgress(repo string) (string, error)

func (*GitlabProvider) GetIssues

func (g *GitlabProvider) GetIssues(pid int, repo string) ([]*GitIssue, error)

GetIssues retrieves a full list of Issues for a project For >100 issues this _depaginates_ the responses and appends them to one slice

func (*GitlabProvider) GetLabels

func (g *GitlabProvider) GetLabels(pid int, repo string) ([]*GitLabel, error)

GetLabels retrieves a full list of labels associated with a project

func (*GitlabProvider) GetRepositories

func (g *GitlabProvider) GetRepositories() ([]*GitRepository, error)

GetRepositories gets a list of all repositories in the target Gitlab instance For >100 repositories this _depaginates_ the responses and appends them to one slice

func (*GitlabProvider) GetUserByID

func (g *GitlabProvider) GetUserByID(uid int) *GitUser

GetUserByID looks up a user by ID and lifts them to the GitUser type

func (*GitlabProvider) MigrateRepo

func (g *GitlabProvider) MigrateRepo(repo *GitRepository, token string) (string, error)

MigrateRepo migrates a git repo from an existing provider

Jump to

Keyboard shortcuts

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