github

package
v0.0.0-...-c995953 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2024 License: Apache-2.0 Imports: 15 Imported by: 1

Documentation

Index

Constants

View Source
const (
	API_URL = "https://api.github.com"
	GH_URL  = "https://github.com"
)
View Source
const (
	RELEASE_LIST_URI    = "/repos/%s/%s/releases%s"
	RELEASE_LATEST_URI  = "/repos/%s/%s/releases/latest%s"
	RELEASE_DATE_FORMAT = "02/01/2006 at 15:04"
)
View Source
const (
	ASSET_DOWNLOAD_URI = "/repos/%s/%s/releases/assets/%d"
)
View Source
const (
	TAGS_URI = "/repos/%s/%s/tags%s"
)

Variables

This section is empty.

Functions

func ApiURL

func ApiURL() string

func DoAuthRequest

func DoAuthRequest(log *logging.Logger, method, url, bodyType, token string, headers map[string]string, body io.Reader) (*http.Response, error)

func GetFileSize

func GetFileSize(f *os.File) (int64, error)

func GithubGet

func GithubGet(log *logging.Logger, uri string, v interface{}) error

func IdOfTag

func IdOfTag(log *logging.Logger, user, repo, tag, token string) (int, error)

find the release-id of the specified tag

func LoadGithubToken

func LoadGithubToken() (string, error)

LoadGithubToken tries to load a github access token from: - GITHUB_TOKEN environment variable - ~/.pulcy/github-token file

func Mark

func Mark(ok bool) string

func NewAuthRequest

func NewAuthRequest(log *logging.Logger, method, url, bodyType, token string, headers map[string]string, body io.Reader) (*http.Request, error)

create a new request that sends the auth token

Types

type Asset

type Asset struct {
	Url         string    `json:"url"`
	Id          int       `json:"id"`
	Name        string    `json:"name"`
	ContentType string    `json:"content_type"`
	State       string    `json:"state"`
	Size        uint64    `json:"size"`
	Downloads   uint64    `json:"download_count"`
	Created     time.Time `json:"created_at"`
	Published   time.Time `json:"published_at"`
}

type Commit

type Commit struct {
	Sha string `json:"sha"`
	Url string `json:"url"`
}

type GithubError

type GithubError struct {
	Resource string `json:"resource"`
	Code     string `json:"code"`
	Field    string `json:"field"`
}

type GithubService

type GithubService struct {
	Logger     *logging.Logger
	User       string // Github username
	Repository string // Github repository name
	Token      string // Github access token
}

func (GithubService) CreateRelease

func (s GithubService) CreateRelease(options ReleaseCreate) error

func (GithubService) UploadAsset

func (s GithubService) UploadAsset(opt UploadAssetOptions) error

func (GithubService) ValidateCredentials

func (s GithubService) ValidateCredentials() error

type Message

type Message struct {
	Message string        `json:"message"`
	Errors  []GithubError `json:"errors"`
}

usually when something goes wrong, github sends something like this back

func ToMessage

func ToMessage(r io.Reader) (*Message, error)

transforms a stream into a Message, if it's valid json

func (*Message) String

func (m *Message) String() string

type Release

type Release struct {
	Url         string     `json:"url"`
	PageUrl     string     `json:"html_url"`
	UploadUrl   string     `json:"upload_url"`
	Id          int        `json:"id"`
	Name        string     `json:"name"`
	Description string     `json:"body"`
	TagName     string     `json:"tag_name"`
	Draft       bool       `json:"draft"`
	Prerelease  bool       `json:"prerelease"`
	Created     *time.Time `json:"created_at"`
	Published   *time.Time `json:"published_at"`
	Assets      []Asset    `json:"assets"`
}

func LatestRelease

func LatestRelease(log *logging.Logger, user, repo, token string) (*Release, error)

func ReleaseOfTag

func ReleaseOfTag(log *logging.Logger, user, repo, tag, token string) (*Release, error)

func Releases

func Releases(log *logging.Logger, user, repo, token string) ([]Release, error)

func (*Release) CleanUploadUrl

func (r *Release) CleanUploadUrl() string

func (*Release) String

func (r *Release) String() string

type ReleaseCreate

type ReleaseCreate struct {
	TagName         string `json:"tag_name"`
	TargetCommitish string `json:"target_commitish,omitempty"`
	Name            string `json:"name"`
	Body            string `json:"body"`
	Draft           bool   `json:"draft"`
	Prerelease      bool   `json:"prerelease"`
}

type Tag

type Tag struct {
	Name       string `json:"name"`
	Commit     Commit `json:"commit"`
	ZipBallUrl string `json:"zipball_url"`
	TarBallUrl string `json:"tarball_url"`
}

func Tags

func Tags(log *logging.Logger, user, repo, token string) ([]Tag, error)

get the tags associated with a repo

func (*Tag) String

func (t *Tag) String() string

type UploadAssetOptions

type UploadAssetOptions struct {
	TagName  string // Name of release tag to attach asset to
	FileName string // Name of file
	Label    string // Label of file (optional)
	Path     string // Local path of file
}

Jump to

Keyboard shortcuts

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