gitlab

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	APIVersion = "/api/v4"

	BaseURLJihuLab   = "https://jihulab.com"
	BaseURLGitLabURL = "https://gitlab.com"
)
View Source
const PerPageMax = 100

Variables

This section is empty.

Functions

func URLEncoded

func URLEncoded(path string) string

Types

type Client

type Client struct {
	BaseURL string
	Token   string
	User    *User
}

func NewClient

func NewClient(baseURL string, token string) (*Client, error)

func (*Client) BuildAPI

func (c *Client) BuildAPI(path string) string

func (*Client) BuildFileDownloadURL

func (c *Client) BuildFileDownloadURL(projectID, filePath, ref string, private bool) string

func (*Client) DeleteFile

func (c *Client) DeleteFile(data *DeleteFileData) error

func (*Client) GetCurrentAuthenticatedUser

func (c *Client) GetCurrentAuthenticatedUser() (*User, error)

func (*Client) GetFile

func (c *Client) GetFile(projectID, filePath, ref string) (*FileInfo, error)

GetFile https://docs.gitlab.com/ee/api/repository_files.html#get-file-from-repository

func (*Client) GetProject

func (c *Client) GetProject(id string) (*Project, error)

func (*Client) ListRepoTree

func (c *Client) ListRepoTree(projectID string, params *ListRepoTreeParams) ([]*FileNode, error)

ListRepoTree https://docs.gitlab.com/ee/api/repositories.html#list-repository-tree

func (*Client) Request

func (c *Client) Request(method, path string, headers http.Header, data interface{}, params url.Values) (*http.Response, error)

type ContentEncoding

type ContentEncoding string
const (
	ContentEncodingBase64 ContentEncoding = "base64"
	ContentEncodingText   ContentEncoding = "text"
)

type CreateFileData

type CreateFileData struct {
	ProjectID     string          `json:"-"`
	FilePath      string          `json:"-"`
	Branch        string          `json:"branch"`
	Content       string          `json:"content"`
	Encoding      ContentEncoding `json:"encoding,omitempty"`
	AuthorEmail   string          `json:"author_email,omitempty"`
	AuthorName    string          `json:"author_name,omitempty"`
	CommitMessage string          `json:"commit_message"`
	StartBranch   string          `json:"start_branch,omitempty"`
}

func (*CreateFileData) GetFilePath

func (d *CreateFileData) GetFilePath() string

func (*CreateFileData) GetProjectID

func (d *CreateFileData) GetProjectID() string

func (*CreateFileData) Validate

func (d *CreateFileData) Validate() error

type CreateFileResponse

type CreateFileResponse struct {
	FilePath string `json:"file_path"`
	Branch   string `json:"branch"`
}

type DeleteFileData

type DeleteFileData struct {
	ProjectID     string `json:"-"`
	FilePath      string `json:"-"`
	Branch        string `json:"branch"`
	AuthorEmail   string `json:"author_email,omitempty"`
	AuthorName    string `json:"author_name,omitempty"`
	CommitMessage string `json:"commit_message"`
	StartBranch   string `json:"start_branch,omitempty"`
	LastCommitID  string `json:"last_commit_id,omitempty"`
}

func (*DeleteFileData) GetFilePath

func (d *DeleteFileData) GetFilePath() string

func (*DeleteFileData) GetProjectID

func (d *DeleteFileData) GetProjectID() string

func (*DeleteFileData) Validate

func (d *DeleteFileData) Validate() error

type FileInfo

type FileInfo struct {
	FileName      string `json:"file_name"`
	FilePath      string `json:"file_path"`
	Size          int64  `json:"size"`
	Encoding      string `json:"encoding"`
	Content       string `json:"content"`
	ContentSHA256 string `json:"content_sha256"`
	Ref           string `json:"ref"`
	BlobID        string `json:"blob_id"`
	CommitID      string `json:"commit_id"`
	LastCommitID  string `json:"last_commit_id"`
}

func (*FileInfo) GetHumanSize

func (f *FileInfo) GetHumanSize() string

type FileNode

type FileNode struct {
	ID   string       `json:"id"`
	Name string       `json:"name"`
	Type FileNodeType `json:"type"`
	Path string       `json:"path"`
	Mode string       `json:"mode"`
}

type FileNodeType

type FileNodeType string
const (
	FileNodeTypeBlob FileNodeType = "blob"
	FileNodeTypeTree FileNodeType = "tree"
)

type ListRepoTreeParams

type ListRepoTreeParams struct {
	Path      string `url:"path,omitempty"`
	Ref       string `url:"ref,omitempty"`
	Recursive bool   `url:"recursive,omitempty"`
	Page      int    `url:"page,omitempty"`
	PerPage   int    `url:"per_page,omitempty"` // default: 20, max: 100, https://docs.gitlab.com/ee/api/index.html#pagination
}

func (*ListRepoTreeParams) IntoValues

func (p *ListRepoTreeParams) IntoValues() (url.Values, error)

type Project

type Project struct {
	ID                int    `json:"id"`
	Description       string `json:"description"`
	DefaultBranch     string `json:"default_branch"`
	Visibility        string `json:"visibility"`
	Path              string `json:"path"`
	PathWithNamespace string `json:"path_with_namespace"`
	Name              string `json:"name"`
	NameWithNamespace string `json:"name_with_namespace"`
}

func (*Project) IsPrivate

func (p *Project) IsPrivate() bool

type UpdateFileData

type UpdateFileData struct {
	CreateFileData
	LastCommitID string `json:"last_commit_id,omitempty"`
}

type UpdateFileResponse

type UpdateFileResponse CreateFileResponse

type User

type User struct {
	ID       int    `json:"id"`
	Username string `json:"username"`
	Email    string `json:"email"`
	Name     string `json:"name"`
	State    string `json:"state"`
}

Jump to

Keyboard shortcuts

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