Skip to content

earentir/gitearelease

Repository files navigation

gitearelease

A package to access details for repositories and releases in gitea, it includes various helpers including the comparison of the current and leatest released version

Usage/Examples

Check version of current and compare to latest release

import (
	"fmt"

	"github.com/earentir/gitearelease"
)

var (
	appversion = "1.1.14"
)

func checkVersion() {
	// Setup the release to fetch
	var releasetofetch gitearelease.ReleaseToFetch
	releasetofetch.BaseURL = "https://gitea.earentir.dev"
	releasetofetch.User = "earentir"
	releasetofetch.Repo = "dns"

	// Latest release
	releasetofetch.Latest = true

	rels, err := gitearelease.GetReleases(releasetofetch)
	if err != nil {
		fmt.Println(err)
	}

	var versionstrings gitearelease.VersionStrings
	versionstrings.Own = appversion
	versionstrings.Current = rels[0].TagName
        // Example of custom comparison messages
	versionstrings.VersionStrings.Older = "Upgrade this ASAP"
	versionstrings.VersionStrings.Newer = "You are ahead of the game"
        versionstrings.VersionStrings.Equal = "You are up to date"

        // Optionally we could terminate the applicaiton if we are older than latest release
	// versionstrings.VersionOptions.DieIfOlder = true

	fmt.Println(gitearelease.CompareVersionsHelper(versionstrings))
}

Func Reference

GetRepositories

func GetRepositories(repositoriestofetch RepositoriesToFetch) ([]Repository, error)
Parameter Type Description
repositoriestofetch struct Required

GetRepositories returns all repositories of a user from a gitea instance can be filtered by release if withrelease is true only repositories with releases will be returned

GetReleases

func GetReleases(releasetofetch ReleaseToFetch) ([]Release, error)
Parameter Type Description
releasetofetch struct Required

GetReleases will return the all the releases or just the latest release of a repository

CompareVersions

  func CompareVersions(versionstrings VersionStrings) int
Parameter Type Description
versionstrings struct Required

CompareVersions compares two version strings and returns -1 if own is older than current, 0 if own is equal to current and 1 if own is newer than current

CompareVersionsHelper

  func CompareVersionsHelper(versionstrings VersionStrings) string
Parameter Type Description
versionstrings struct Required

CompareVersionsHelper is a helper function for CompareVersions that returns a string instead of an integer

Helpers

  func DownloadBinary(url, outputDir, filename string) (string, error)

Simple Binary downloader to fetch the selected release (Not Tested)

  func TrimVersionPrefix(version string) string

Trivial Version String Cleaner

Exported structs

type Release
type ReleaseToFetch
type RepositoriesToFetch
type Repository
type VersionStrings

Dependancies & Documentation

Go Mod

Go Reference

Dependancies

OpenSSF Best Practices

OpenSSF Scorecard

Code Climate issues

Contributing

Contributions are always welcome! All contributions are required to follow the https://google.github.io/styleguide/go/

All code contributed must include its tests in (_test) and have a minimum of 80% coverage

Vulnerability Reporting

Please report any security vulnerabilities to the project using issues or directly to the owner.

Code of Conduct

This project follows the go project code of conduct, please refer to https://go.dev/conduct for more details

Roadmap

  • Create a finalised version 1 of the package
  • Add support for downloading binaries from releases
  • Add support for github releases
  • Add support for gitlab releases

Authors

License

I will always follow the Linux Kernel License as primary, if you require any other OPEN license please let me know and I will try to accomodate it.

License