gitrefs

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2023 License: MIT Imports: 6 Imported by: 1

README

gitrefs

Provides a simple way to list references from a remote git repository over HTTP, without needing a full git client or a checkout of the remote repository.

Example:

package main

import (
	"fmt"

	"github.com/csmith/gitrefs"
)

func main() {
	refs, err := gitrefs.Fetch("https://github.com/csmith/gitrefs")
	if err != nil {
		panic(err)
	}

	for r := range refs {
		fmt.Printf("Ref %s at commit %s\n", r, refs[r])
	}
}

A utility method to retrieve only the latest semver tag is included:

package main

import (
	"fmt"

	"github.com/csmith/gitrefs"
)

func main() {
	tag, hash, err := gitrefs.LatestTag("https://github.com/csmith/gitrefs")
	if err != nil {
		panic(err)
	}

	fmt.Printf("Latest tag is %s at commit %s\n", tag, hash)
}

Protocol docs:

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fetch

func Fetch(url string, options ...Option) (map[string]string, error)

Fetch retrieves a list of all refs from the remote repository at the given url.

func LatestTag

func LatestTag(url string, options ...Option) (string, string, error)

LatestTag attempts to find the highest semver tag from the repository at the given url. Returns the tag and the commit hash of that tag, or an error if no semver tags are found. Tags that can't be parsed as semver are silently ignored.

func LatestTagIgnoringPrefix added in v1.2.0

func LatestTagIgnoringPrefix(url string, prefix string, options ...Option) (string, string, error)

LatestTagIgnoringPrefix behaves the same as LatestTag, but ignores the given prefix when trying to parse tags as semver. This can be useful if releases are tagged with "release-" or similar.

Types

type Option

type Option func(*opts)

func HttpClient

func HttpClient(client *http.Client) Option

func TagsOnly

func TagsOnly() Option

Jump to

Keyboard shortcuts

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