ghrcooldown

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2026 License: MIT Imports: 5 Imported by: 0

README

ghrcooldown

A CLI tool and Go library to fetch the latest GitHub Releases respecting the cooldown period.

Latest Version test Maintainability Coverage Status GoDoc Go Report Card

Usage as a CLI tool

$ ghrcooldown latest --repo hashicorp/terraform --cooldown-days 7
v1.14.8

$ ghrcooldown has-passed --repo hashicorp/terraform --tag v1.14.8 --cooldown-days 7
Cooldown has passed.
Install

Download latest binary from https://github.com/sue445/ghrcooldown/releases

or

go install github.com/sue445/ghrcooldown/cmd/ghrcooldown@latest
Commands
ghrcooldown latest
$ ghrcooldown latest --help
NAME:
   ghrcooldown latest - Print latest release version of the specified repository, respecting the provided cooldown period.

USAGE:
   ghrcooldown latest [options]

OPTIONS:
   --cooldown-days int      Cooldown days (default: 0)
   --github-api-url string  GitHub API Endpoint (e.g. https://<your-ghes-hostname>/api/v3). Required if using GitHub Enterprise Server [$GITHUB_API_URL]
   --repo string            GitHub Repository Path (e.g. user/repo)
   --token string           GitHub token [$GITHUB_TOKEN]
   --help, -h               show help
ghrcooldown has-passed
$ ./bin/ghrcooldown has-passed --help
NAME:
   ghrcooldown has-passed - Checks whether the specified tag has passed the given cooldown period.

USAGE:
   ghrcooldown has-passed [options]

OPTIONS:
   --cooldown-days int      Cooldown days (default: 0)
   --exit-code              Exit with code 1 if the cooldown has not passed (default: false)
   --github-api-url string  GitHub API Endpoint (e.g. https://<your-ghes-hostname>/api/v3). Required if using GitHub Enterprise Server [$GITHUB_API_URL]
   --repo string            GitHub Repository Path (e.g. user/repo)
   --tag string             GitHub tag
   --token string           GitHub token [$GITHUB_TOKEN]
   --help, -h               show help

Usage as a library

Install
go get -u github.com/sue445/ghrcooldown
Example
package main

import (
	"context"
	"fmt"
	"log"
	"os"
	"time"

	"github.com/sue445/ghrcooldown"
)

func main() {
	// Initialize the client
	client, err := ghrcooldown.NewClient(&ghrcooldown.ClientParams{
		Token: os.Getenv("GITHUB_TOKEN"),
		// BaseURL: "", // Required if using GitHub Enterprise Server
	})

	// 7 days
	cooldown := 7 * 24 * time.Hour

	ctx := context.Background()

	// Example 1: Returns the latest tagName that has passed the 7-day cooldown period.
	tagName, err := client.GetLatestTagName(ctx, "hashicorp", "terraform", cooldown)
	if err != nil {
		log.Fatalf("failed to get latest tag: %v", err)
	}
	fmt.Printf("Latest tag: %s\n", tagName)

	// Example 2: Returns true if the cooldown has passed.
	hasPassed, err := client.HasCooldownPassed(ctx, "hashicorp", "terraform", "v1.14.8", cooldown)
	if err != nil {
		log.Fatalf("failed to check cooldown: %v", err)
	}
	fmt.Printf("Has v1.14.8 passed the cooldown? %v\n", hasPassed)
}

Reference

https://godoc.org/github.com/sue445/ghrcooldown

Documentation

Index

Constants

View Source
const Day = 24 * time.Hour

Day represents the duration of exactly 24 hours.

View Source
const (
	// Version represents ghrcooldown version
	Version = "v0.2.1"
)

Variables

This section is empty.

Functions

func GetDefaultUserAgent

func GetDefaultUserAgent() string

GetDefaultUserAgent returns the default User-Agent.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client represents a client for interacting with the GitHub API with cooldown support.

func NewClient

func NewClient(params *ClientParams) (*Client, error)

NewClient creates and returns a new Client instance using the provided parameters.

func (*Client) GetLatestTagName

func (c *Client) GetLatestTagName(ctx context.Context, owner string, repo string, cooldown time.Duration) (string, error)

GetLatestTagName retrieves the latest release version of the specified repository, respecting the provided cooldown period.

func (*Client) HasCooldownPassed

func (c *Client) HasCooldownPassed(ctx context.Context, owner string, repo string, tagName string, cooldown time.Duration) (bool, error)

HasCooldownPassed checks if the specified tag has passed the given cooldown period.

type ClientParams

type ClientParams struct {
	// Token is the personal access token used for authenticating with the GitHub API.
	// It is optional, but if omitted, the API request will be subject to IP-based rate limiting.
	// c.f. https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api
	Token string

	// BaseURL specifies the custom base URL for the GitHub API.
	// It is primarily used for GitHub Enterprise Server.
	BaseURL string

	// UserAgent specifies the User-Agent header used in API requests.
	// If omitted, a default User-Agent will be used.
	UserAgent string

	// CurrentTime is the reference time used to evaluate the cooldown period.
	// It is mainly used for mocking the current time in unit tests.
	CurrentTime *time.Time
}

ClientParams contains the configuration parameters required to initialize a new Client.

Directories

Path Synopsis
cmd
ghrcooldown command

Jump to

Keyboard shortcuts

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