git

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2019 License: BSD-2-Clause Imports: 10 Imported by: 1

Documentation

Overview

Package git provides easy API access to Sourcehut Git repositories.

Index

Constants

View Source
const BaseURL = "https://git.sr.ht/api/"

BaseURL is the default public Sourcehut API URL. It is exported for convenience.

Variables

This section is empty.

Functions

This section is empty.

Types

type Author

type Author struct {
	Email string `json:"email"`
	Name  string `json:"name"`
}

Author is information about the author or committer of a commit.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client handles communication with the Sourcehut API.

API docs: https://man.sr.ht/git.sr.ht/api.md

func NewClient

func NewClient(opts ...Option) (*Client, error)

NewClient returns a new mailing list API client.

func (*Client) DeleteRepo added in v0.0.3

func (c *Client) DeleteRepo(repo string) error

DeleteRepo removes a repository.

func (*Client) GetUser

func (c *Client) GetUser(username string) (sourcehut.User, error)

GetUser returns information about the provided username, or the currently authenticated user if the username is empty.

func (*Client) NewRepo added in v0.0.3

func (c *Client) NewRepo(name, description string, visibility RepoVisibility) (*Repo, error)

NewRepo creates and returns a new repository from the provided template.

func (*Client) Repo added in v0.0.3

func (c *Client) Repo(username, repo string) (*Repo, error)

Repo returns information about a specific repository owned by the provided username. If an empty username is provided, the authenticated user is used.

func (*Client) Repos

func (c *Client) Repos(username string) (RepoIter, error)

Repos returns an iterator over all repos owned by the provided username. If an empty username is provided, the authenticated user is used.

func (*Client) UpdateRepo added in v0.0.3

func (c *Client) UpdateRepo(oldName string, repo *Repo) error

UpdateRepo updates an existing repository. Only the name, description, and visibility will be modified.

If repo.Name differs from oldName, a redirect from the old name to the new name.

func (*Client) Version

func (c *Client) Version() (string, error)

Version returns the version of the API.

API docs: https://man.sr.ht/api-conventions.md#get-apiversion

type Commit

type Commit struct {
	ID        string    `json:"id"`
	ShortID   string    `json:"short_id"`
	Author    Author    `json:"author"`
	Committer Author    `json:"committer"`
	Timestamp time.Time `json:"timestamp"`
	Message   string    `json:"message"`
	Tree      string    `json:"tree"`
	Signature *struct {
		Signature string `json:"signature"`
		Data      string `json:"data"`
	} `json:"signature"`
	Parents []string `json:"Parents"`
}

Commit is a single commit in a repo.

type Option

type Option func(*Client) error

Option is used to configure an API client.

func Base

func Base(base string) Option

Base returns an option that configures the public Sourcehut API URL.

If base does not have a trailing slash, one is added automatically. If unspecified, BaseURL is used.

func SrhtClient

func SrhtClient(client sourcehut.Client) Option

SrhtClient returns an option that configures the client to use the provided sourcehut.Client for API requests. If unspecified, the default sourcehut.Client (with no options of its own) is used.

type Ref

type Ref struct {
	Name   string `json:"name"`
	Target string `json:"target"`
}

Ref is a reference to an object in a repo.

type Repo

type Repo struct {
	ID          int64          `json:"id"`
	Created     time.Time      `json:"created"`
	Subject     string         `json:"subject"`
	Name        string         `json:"name"`
	Description string         `json:"description"`
	Visibility  RepoVisibility `json:"visibility"`
}

Repo represents a repository.

type RepoIter

type RepoIter struct {
	*sourcehut.Iter
}

RepoIter is used for iterating over a collection of repos.

func (RepoIter) Repo

func (i RepoIter) Repo() *Repo

Repo returns the repo which the iterator is currently pointing to.

type RepoVisibility

type RepoVisibility string

RepoVisibility is the visibility level of a repo.

const (
	VisibilityPublic   RepoVisibility = "public"
	VisibilityUnlisted RepoVisibility = "unlisted"
	VisibilityPrivate  RepoVisibility = "private"
)

Supported visibility levels.

type Tree

type Tree struct {
	ID      string `json:"id"`
	ShortID string `json:"short_id"`
	Entries []struct {
		ID   string      `json:"id"`
		Name string      `json:"name"`
		Type TreeType    `json:"type"`
		Mode os.FileMode `json:"mode"`
	} `json:"entries"`
}

Tree is a tree within a commit.

type TreeType

type TreeType string

TreeType is a supported type of tree (tree or blob).

const (
	TypeTree TreeType = "tree"
	TypeBlob TreeType = "blob"
)

Valid and supported tree type's.

Jump to

Keyboard shortcuts

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