gogithubplus

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2019 License: MIT Imports: 4 Imported by: 0

README

gogithubplus

Build Status Go Report Card MIT

A Golang module for interacting with GitHub.

RepositoryInfo

RepositoryInfo represents a GitHub repository.

RepositoryInfo members
  • Name is a string which represents the name of the repository. For example, this repository's name is gogithubplus.
  • Owner is a string which represents the owner of the repository. For example, this repository's owner is cariad.
RepositoryInfo creation

You can create an instance by calling the Repository(owner string, name string) function:

  • name is a string which represents the name of the repository. For example, this repository's name is gogithubplus.
  • owner is a string which represents the owner of the repository. For example, this repository's owner is cariad.

For example:

package main

import (
    "fmt"
    "github.com/cariad/gogithubplus"
)

func main() {
    repository := gogithubplus.Repository("cariad", "gomyrds-createlambda")

    fmt.Println(repository.Owner)
    // cariad

    fmt.Println(repository.Name)
    // gomyrds-createlambda

    fmt.Println(repository)
    // cariad/gomyrds-createlambda
}
RepositoryInfo{}.URL()

The URL() function returns the URL of the repository.

For example:

package main

import (
    "fmt"
    "github.com/cariad/gogithubplus"
)

func main() {
    repository := gogithubplus.Repository("cariad", "gomyrds-createlambda")

    fmt.Println(repository.URL())
    // https://github.com/cariad/gomyrds-createlambda
}

ReleaseInfo

ReleaseInfo represents a versioned release of a project.

ReleaseInfo members
  • RepositoryInfo is a RepositoryInfo instance which represents the repository.
  • Version is a string which which represents the name of the release.
ReleaseInfo creation

You can create an instance by calling the Repository{}.Release(version string) function:

  • version is a string which which represents the name of the release.

For example:

package main

import (
    "fmt"
    "github.com/cariad/gogithubplus"
)

func main() {
    release := gogithubplus.
        Repository("cariad", "gomyrds-createlambda").
        Release("v0.1.1")

    fmt.Println(release.RepositoryInfo)
    // cariad/gomyrds-createlambda

    fmt.Println(release.Version)
    // v0.1.1

    fmt.Println(release)
    // cariad/gomyrds-createlambda@v0.1.1
}

ReleaseArtifactInfo

ReleaseArtifactInfo represents a release artifact (e.g. a build).

ReleaseArtifactInfo members
  • ReleaseInfo is a ReleaseInfo instance which represents the release.
  • Filename is a string which represents the name of the artifact.
ReleaseArtifactInfo creation

You can create an instance by calling the Release{}.ReleaseArtifact(filename string) function:

  • filename is a string which represents the name of the artifact.

For example:

package main

import (
    "fmt"
    "github.com/cariad/gogithubplus"
)

func main() {
    artifact := gogithubplus.
        Repository("cariad", "gomyrds-createlambda").
        Release("v0.1.1").
        ReleaseArtifact("gomyrds-createlambda.zip")

    fmt.Println(artifact.ReleaseInfo)
    // cariad/gomyrds-createlambda@v0.1.1

    fmt.Println(artifact.Filename)
    // gomyrds-createlambda.zip
}
ReleaseArtifactInfo{}.Download()

The Download() function will download the artifact to your local filesystem.

For example:

package main

import (
    "github.com/cariad/gogithubplus"
)

func main() {
    artifact := gogithubplus.
        Repository("cariad", "gomyrds-createlambda").
        Release("v0.1.1").
        ReleaseArtifact("gomyrds-createlambda.zip")

    artifact.Download("downloaded.zip")
}
ReleaseArtifactInfo implements io.ReadCloser

ReleaseArtifact implements io.ReadCloser so you can read the content as you wish.

For example, you can copy a release artifact to an AWS S3 Bucket without needing to explicitly download it first:

package main

import (
    "github.com/aws/aws-sdk-go/aws"
    "github.com/aws/aws-sdk-go/aws/session"
    "github.com/aws/aws-sdk-go/service/s3/s3manager"

    "github.com/cariad/gogithubplus"
)

func main() {
    artifact := gogithubplus.
      Repository("cariad", "gomyrds-createlambda").
      Release("v0.1.1").
      ReleaseArtifact("gomyrds-createlambda.zip")

    defer artifact.Close()

    sess, _ := session.NewSessionWithOptions(session.Options{
      SharedConfigState: session.SharedConfigEnable,
    })

    uploader := s3manager.NewUploader(sess)

    i := &s3manager.UploadInput{
      Body:   &artifact,
      Bucket: aws.String("my-bucket"),
      Key:    aws.String("my-lambda.zip"),
    }

    uploader.Upload(i)
}

Licence, credit & sponsorship

This project is published under the MIT Licence.

You don't owe me anything in return, but as an indie freelance coder there are two things I'd appreciate:

  • Credit. If your app or documentation has a credits page, please consider mentioning the projects you use.
  • Cash. If you want and are able to support future development, please consider becoming a patron or buying me a coffee. Thank you!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ReleaseArtifactInfo

type ReleaseArtifactInfo struct {
	// ReleaseInfo describes the release which this is an artifact of.
	ReleaseInfo

	// Filename describes the remote filename of the artifact.
	Filename string
	// contains filtered or unexported fields
}

ReleaseArtifactInfo represents a release artifact (e.g. a build).

func (*ReleaseArtifactInfo) Close

func (r *ReleaseArtifactInfo) Close() error

Close closes the artifact's read stream.

func (*ReleaseArtifactInfo) Download

func (r *ReleaseArtifactInfo) Download(localpath string) error

Download downloads the artifact to the local filesystem.

func (*ReleaseArtifactInfo) Read

func (r *ReleaseArtifactInfo) Read(b []byte) (int, error)

Read reads a series of bytes from the artifact's content.

You should Close() the artifact when finished reading.

func (ReleaseArtifactInfo) URL

func (r ReleaseArtifactInfo) URL() string

URL gets the download URL of the artifact.

type ReleaseInfo

type ReleaseInfo struct {
	RepositoryInfo
	Version string
}

ReleaseInfo represents a versioned release of a project.

func (ReleaseInfo) ReleaseArtifact

func (r ReleaseInfo) ReleaseArtifact(filename string) ReleaseArtifactInfo

ReleaseArtifact creates a new ReleaseArtifactInfo.

func (ReleaseInfo) String

func (r ReleaseInfo) String() string

type RepositoryInfo

type RepositoryInfo struct {
	Owner string
	Name  string
}

RepositoryInfo represents a Git repository published on GitHub.

func Repository

func Repository(owner string, name string) RepositoryInfo

Repository creates a new MakeRepository instance.

func (RepositoryInfo) Release

func (r RepositoryInfo) Release(version string) ReleaseInfo

Release creates a new Release instance.

func (RepositoryInfo) String

func (r RepositoryInfo) String() string

func (RepositoryInfo) URL

func (r RepositoryInfo) URL() string

URL gets the URL of the repository.

Jump to

Keyboard shortcuts

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