ginclient

package
v0.0.0-...-854ad97 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2021 License: BSD-3-Clause Imports: 16 Imported by: 5

Documentation

Overview

Package ginclient augments the web package with functions to interact with GIN Gogs (https://github.com/G-Node/gogs) specifically.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(paths []string, addchan chan<- git.RepoFileStatus)

Add updates the index with the changes in the files specified by 'paths'. The status channel 'addchan' is closed when this function returns.

func CheckoutFileCopies

func CheckoutFileCopies(commithash string, paths []string, outpath string, suffix string, cochan chan<- FileCheckoutStatus)

CheckoutFileCopies checks out copies of files specified by path from the revision with the specified commithash. The checked out files are stored in the location specified by outpath. The timestamp of the revision is appended to the original filenames (before the extension).

func CheckoutVersion

func CheckoutVersion(commithash string, paths []string) error

CheckoutVersion checks out all files specified by paths from the revision with the specified commithash.

func CommitIfNew

func CommitIfNew() (bool, error)

CommitIfNew creates an empty initial git commit if the current repository is completely new. If a new commit is created and a default remote exists, the new commit is pushed to initialise the remote as well. Returns 'true' if (and only if) a commit was created.

func DefaultRemote

func DefaultRemote() (string, error)

DefaultRemote returns the name of the configured default gin remote. If a remote is not set in the config, the remote of the default git upstream is set and returned.

func DefaultServer

func DefaultServer() string

DefaultServer returns the alias of the configured default gin server.

func RemoveRemote

func RemoveRemote(remote string) error

RemoveRemote removes a remote from the repository configuration.

func RemoveServer

func RemoveServer(alias string) error

RemoveServer removes a server from the user configuration. Returns with error if no server with the given alias exists.

func SetDefaultRemote

func SetDefaultRemote(remote string) error

SetDefaultRemote sets the name of the default gin remote.

func SetDefaultServer

func SetDefaultServer(alias string) error

SetDefaultServer sets the alias of the default gin server. Returns with error if no server with the given alias exists.

func UnsetDefaultRemote

func UnsetDefaultRemote() error

UnsetDefaultRemote unsets the default gin remote in the git configuration.

Types

type AccessToken

type AccessToken struct {
	Name string `json:"name"`
	Sha1 string `json:"sha1"`
}

AccessToken represents a API access token.

type Client

type Client struct {
	*web.Client
	// contains filtered or unexported fields
}

Client is a client interface to the GIN server. Embeds web.Client.

func New

func New(alias string) *Client

New returns a new client for the GIN server, configured with the server referred to by the alias in the argument.

func (*Client) AddKey

func (gincl *Client) AddKey(key, description string, force bool) error

AddKey adds the given key to the current user's authorised keys. If force is enabled, any key which matches the new key's description will be overwritten.

func (*Client) CloneRepo

func (gincl *Client) CloneRepo(repopath string, clonechan chan<- git.RepoFileStatus)

CloneRepo clones a remote repository and initialises annex. The status channel 'clonechan' is closed when this function returns.

func (*Client) CreateRepo

func (gincl *Client) CreateRepo(name, description string) error

CreateRepo creates a repository on the server.

func (*Client) DelRepo

func (gincl *Client) DelRepo(name string) error

DelRepo deletes a repository from the server.

func (*Client) DeletePubKey

func (gincl *Client) DeletePubKey(id int64) error

DeletePubKey the key with the given ID from the current user's authorised keys.

func (*Client) DeletePubKeyByIdx

func (gincl *Client) DeletePubKeyByIdx(idx int) (string, error)

DeletePubKeyByIdx removes the key with the given index from the current user's authorised keys. Upon deletion, it returns the title of the key that was deleted. Note that the first key has index 1.

func (*Client) DeletePubKeyByTitle

func (gincl *Client) DeletePubKeyByTitle(title string) error

DeletePubKeyByTitle removes the key that matches the given title from the current user's authorised keys.

func (*Client) Download

func (gincl *Client) Download(remote string) error

Download downloads changes and placeholder files in an already checked out repository.

func (*Client) GetContent

func (gincl *Client) GetContent(paths []string, getcontchan chan<- git.RepoFileStatus)

GetContent downloads the contents of placeholder files in a checked out repository. The status channel 'getcontchan' is closed when this function returns.

func (*Client) GetRepo

func (gincl *Client) GetRepo(repoPath string) (gogs.Repository, error)

GetRepo retrieves the information of a repository.

func (*Client) GetTokens

func (gincl *Client) GetTokens(username, password string) ([]AccessToken, error)

GetTokens returns all the user's active access tokens from the GIN server.

func (*Client) GetUserKeys

func (gincl *Client) GetUserKeys() ([]gogs.PublicKey, error)

GetUserKeys fetches the public keys that the user has added to the auth server.

func (*Client) GitAddress

func (gincl *Client) GitAddress() string

GitAddress returns the full address string for the configured git server

func (*Client) InitDir

func (gincl *Client) InitDir(bare bool) error

InitDir initialises the local directory with the default remote and git (and annex) configuration options. Optionally initialised as a bare repository (for annex directory remotes).

func (*Client) ListFiles

func (gincl *Client) ListFiles(paths ...string) (map[string]FileStatus, error)

ListFiles lists the files and directories specified by paths and their sync status.

func (*Client) ListRepos

func (gincl *Client) ListRepos(user string) ([]gogs.Repository, error)

ListRepos gets a list of repositories (public or user specific)

func (*Client) LoadToken

func (gincl *Client) LoadToken() error

LoadToken calls the embedded UserToken.LoadToken function with the configured server alias.

func (*Client) LockContent

func (gincl *Client) LockContent(paths []string, lcchan chan<- git.RepoFileStatus)

LockContent locks local files, turning them into symlinks (if supported by the filesystem). The status channel 'lockchan' is closed when this function returns.

func (*Client) Login

func (gincl *Client) Login(username, password, clientID string) error

Login requests a token from the auth server and stores the username and token to file and adds them to the Client. It also generates a key pair for the user for use in git commands. (See also NewToken)

func (*Client) Logout

func (gincl *Client) Logout()

Logout logs out the currently logged in user in 3 steps: 1. Remove the public key matching the current hostname from the server. 2. Delete the private key file from the local machine. 3. Delete the user token.

func (*Client) MakeSessionKey

func (gincl *Client) MakeSessionKey() error

MakeSessionKey creates a private+public key pair. The private key is saved in the user's configuration directory, to be used for git commands. The public key is added to the GIN server for the current logged in user.

func (*Client) NewToken

func (gincl *Client) NewToken(username, password, clientID string) error

NewToken requests a new user token from the GIN server and adds it to the Client along with the username.

func (*Client) RemoveContent

func (gincl *Client) RemoveContent(paths []string, rmcchan chan<- git.RepoFileStatus)

RemoveContent removes the contents of local files, turning them into placeholders but only if the content is available on a remote. The status channel 'rmcchan' is closed when this function returns.

func (*Client) RequestAccount

func (gincl *Client) RequestAccount(name string) (gogs.User, error)

RequestAccount requests a specific account by name.

func (*Client) Sync

func (gincl *Client) Sync(content bool) error

Sync synchronises changes bidirectionally (uploads and downloads), optionally transferring content between remotes and the local clone.

func (*Client) UnlockContent

func (gincl *Client) UnlockContent(paths []string, ulcchan chan<- git.RepoFileStatus)

UnlockContent unlocks local files turning them into normal files, if the content is locally available. The status channel 'unlockchan' is closed when this function returns.

func (*Client) Upload

func (gincl *Client) Upload(paths []string, remotes []string, uploadchan chan<- git.RepoFileStatus)

Upload transfers locally recorded changes to a remote. The status channel 'uploadchan' is closed when this function returns.

func (*Client) WebAddress

func (gincl *Client) WebAddress() string

WebAddress returns the full address string for the configured web server

type FileCheckoutStatus

type FileCheckoutStatus struct {
	Filename    string
	Type        string
	Destination string
	Err         error
}

FileCheckoutStatus is used to report the status of a CheckoutFileCopies() operation.

type FileStatus

type FileStatus uint8

FileStatus represents the state a file is in with respect to local and remote changes.

const (
	// Synced indicates that an annexed file is synced between local and remote
	Synced FileStatus = iota
	// NoContent indicates that a file represents an annexed file that has not had its contents synced yet
	NoContent
	// Modified indicatres that a file has local modifications that have not been committed
	Modified
	// LocalChanges indicates that a file has local, committed modifications that have not been pushed
	LocalChanges
	// RemoteChanges indicates that a file has remote modifications that have not been pulled
	RemoteChanges
	// Unlocked indicates that a file is being tracked and is unlocked for editing
	Unlocked
	// TypeChange indicates that a file being tracked as locked (unlocked) is now unlocked (locked)
	TypeChange
	// Removed indicates that a (previously) tracked file has been deleted or moved
	Removed
	// Untracked indicates that a file is not being tracked by neither git nor git annex
	Untracked
)

func (FileStatus) Abbrev

func (fs FileStatus) Abbrev() string

Abbrev returns the two-letter abbrevation of the file status OK (Synced), NC (NoContent), MD (Modified), LC (LocalUpdates), RC (RemoteUpdates), UL (Unlocked), TC (TypeChange), RM (Removed), ?? (Untracked)

func (FileStatus) Description

func (fs FileStatus) Description() string

Description returns the long description of the file status

type FileStatusSlice

type FileStatusSlice []FileStatus

FileStatusSlice is a slice of FileStatus which implements Len() and Less() to allow sorting.

func (FileStatusSlice) Len

func (fsSlice FileStatusSlice) Len() int

Len is the number of elements in FileStatusSlice.

func (FileStatusSlice) Less

func (fsSlice FileStatusSlice) Less(i, j int) bool

Less reports whether the element with index i should sort before the element with index j.

func (FileStatusSlice) Swap

func (fsSlice FileStatusSlice) Swap(i, j int)

Swap swaps the elements with intexes i and j.

type GINUser

type GINUser struct {
	ID        int64  `json:"id"`
	UserName  string `json:"login"`
	FullName  string `json:"full_name"`
	Email     string `json:"email"`
	AvatarURL string `json:"avatar_url"`
}

GINUser represents a API user.

Directories

Path Synopsis
Package config handles reading of the user configuration for the client.
Package config handles reading of the user configuration for the client.
Package log handles logging for the client.
Package log handles logging for the client.

Jump to

Keyboard shortcuts

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