updater

package
v1.20250907.1 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsNewer

func IsNewer(v1, v2 string) bool

IsNewer compares two version strings and returns true if v1 is newer than v2

Types

type ActionReference

type ActionReference struct {
	Owner           string
	Name            string
	Version         string
	CommitHash      string
	Path            string
	Line            int
	Comments        []string
	VersionComment  string // Comment indicating version (e.g., "# v3")
	OriginalVersion string // For tracking version history
}

ActionReference represents a GitHub Action reference in a workflow file

func CreateActionReference added in v1.20250601.1

func CreateActionReference(owner, name, version, commitHash string) ActionReference

Test data factories

func CreateActionWithHash added in v1.20250601.1

func CreateActionWithHash(version, commitHash string) ActionReference

func CreateSimpleAction added in v1.20250601.1

func CreateSimpleAction(version string) ActionReference

type AuthTestCase added in v1.20250601.1

type AuthTestCase struct {
	Name     string
	Token    string
	WantAuth bool
}

AuthTestCase represents a test case for authentication tests

func GetAuthTestCases added in v1.20250601.1

func GetAuthTestCases() []AuthTestCase

type DefaultPRCreator

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

DefaultPRCreator implements the PRCreator interface

func NewPRCreator

func NewPRCreator(token, owner, repo string) *DefaultPRCreator

NewPRCreator creates a new instance of DefaultPRCreator

func SetupPRTestServer added in v1.20250321.1

func SetupPRTestServer(t *testing.T, serverType PRTestServerType) (*httptest.Server, *DefaultPRCreator)

SetupPRTestServer creates a test server and PR creator for testing based on the provided type

func (*DefaultPRCreator) CreatePR

func (c *DefaultPRCreator) CreatePR(ctx context.Context, updates []*Update) error

CreatePR creates a pull request with the given updates

func (*DefaultPRCreator) SetWorkflowsPath added in v1.20250303.1

func (c *DefaultPRCreator) SetWorkflowsPath(path string)

SetWorkflowsPath sets the path to workflow files

type DefaultUpdateManager

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

DefaultUpdateManager implements the UpdateManager interface

func NewUpdateManager

func NewUpdateManager(baseDir string) *DefaultUpdateManager

NewUpdateManager creates a new instance of DefaultUpdateManager

func (*DefaultUpdateManager) ApplyUpdates

func (m *DefaultUpdateManager) ApplyUpdates(ctx context.Context, updates []*Update) error

ApplyUpdates applies the given updates to workflow files

func (*DefaultUpdateManager) CreateUpdate

func (m *DefaultUpdateManager) CreateUpdate(ctx context.Context, file string, action ActionReference, latestVersion string, commitHash string) (*Update, error)

CreateUpdate creates an update for a given action and its latest version

func (*DefaultUpdateManager) PreserveComments

func (m *DefaultUpdateManager) PreserveComments(action ActionReference) []string

PreserveComments preserves existing comments when updating an action

type DefaultVersionChecker

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

DefaultVersionChecker implements the VersionChecker interface using GitHub API

func NewDefaultVersionChecker

func NewDefaultVersionChecker(token string) *DefaultVersionChecker

NewDefaultVersionChecker creates a new DefaultVersionChecker instance

func SetupVersionTestServer added in v1.20250321.1

func SetupVersionTestServer(t *testing.T, serverType VersionTestServerType) (*httptest.Server, *DefaultVersionChecker)

SetupVersionTestServer creates a test server for version checker tests

func (*DefaultVersionChecker) GetCommitHash

func (c *DefaultVersionChecker) GetCommitHash(ctx context.Context, action ActionReference, version string) (string, error)

GetCommitHash returns the commit hash for a specific version of an action

func (*DefaultVersionChecker) GetLatestVersion

func (c *DefaultVersionChecker) GetLatestVersion(ctx context.Context, action ActionReference) (string, string, error)

GetLatestVersion returns the latest version and its commit hash for a given action

func (*DefaultVersionChecker) IsUpdateAvailable

func (c *DefaultVersionChecker) IsUpdateAvailable(ctx context.Context, action ActionReference) (bool, string, string, error)

IsUpdateAvailable checks if a newer version is available

type EndpointConfig added in v1.20250321.1

type EndpointConfig struct {
	Path       string
	StatusCode int
	Response   string
}

EndpointConfig represents configuration for a specific endpoint

type PRCreator

type PRCreator interface {
	// CreatePR creates a pull request with the given updates
	CreatePR(ctx context.Context, updates []*Update) error
}

PRCreator creates pull requests for GitHub Action updates

type PRTestServerType added in v1.20250321.1

type PRTestServerType string

PRTestServerType defines the type of test server to create

const (
	// NormalServer represents a standard server with all endpoints working correctly
	NormalServer PRTestServerType = "normal"
	// ErrorServer represents a server with repo endpoint returning an error
	ErrorServer PRTestServerType = "error"
	// BranchErrorServer represents a server with branch creation returning an error
	BranchErrorServer PRTestServerType = "branch_error"
	// ContentsErrorServer represents a server with contents endpoint returning an error
	ContentsErrorServer PRTestServerType = "contents_error"
	// BlobErrorServer represents a server with blob creation returning an error
	BlobErrorServer PRTestServerType = "blob_error"
	// PRErrorServer represents a server with PR creation returning an error
	PRErrorServer PRTestServerType = "pr_error"
)

type Scanner

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

Scanner handles scanning and parsing of workflow files

func NewScanner

func NewScanner(baseDir string) *Scanner

NewScanner creates a new Scanner instance

func (*Scanner) ParseActionReferences

func (s *Scanner) ParseActionReferences(path string) ([]ActionReference, error)

ParseActionReferences extracts action references from a workflow file

func (*Scanner) ScanWorkflows

func (s *Scanner) ScanWorkflows(dir string) ([]string, error)

ScanWorkflows finds all GitHub Actions workflow files in the repository

func (*Scanner) SetRateLimit

func (s *Scanner) SetRateLimit(limit int, duration time.Duration)

SetRateLimit configures the rate limiting for the scanner

type SimpleTestCase added in v1.20250601.1

type SimpleTestCase struct {
	Name    string
	Input   interface{}
	Want    interface{}
	WantErr bool
}

SimpleTestCase represents a simple test case with name and expectation

func GetHexStringTestCases added in v1.20250601.1

func GetHexStringTestCases() []SimpleTestCase

Common test data generators

func GetVersionComparisonTestCases added in v1.20250601.1

func GetVersionComparisonTestCases() []SimpleTestCase

type TestCaseRunner added in v1.20250601.1

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

TestCaseRunner provides utilities for running version checker test cases

func NewTestCaseRunner added in v1.20250601.1

func NewTestCaseRunner(t *testing.T) *TestCaseRunner

NewTestCaseRunner creates a new test case runner

func (*TestCaseRunner) RunGetCommitHashTest added in v1.20250601.1

func (r *TestCaseRunner) RunGetCommitHashTest(name string, action ActionReference, version string, serverType VersionTestServerType, wantHash string, wantErr bool)

RunGetCommitHashTest runs a GetCommitHash test case with version parameter

func (*TestCaseRunner) RunGetLatestVersionTest added in v1.20250601.1

func (r *TestCaseRunner) RunGetLatestVersionTest(tc VersionTestCase)

RunGetLatestVersionTest runs a GetLatestVersion test case

func (*TestCaseRunner) RunIsUpdateAvailableTest added in v1.20250601.1

func (r *TestCaseRunner) RunIsUpdateAvailableTest(tc VersionTestCase)

RunIsUpdateAvailableTest runs an IsUpdateAvailable test case

type Update

type Update struct {
	Action          ActionReference
	OldVersion      string
	NewVersion      string
	OldHash         string
	NewHash         string
	FilePath        string
	LineNumber      int
	Description     string
	Comments        []string // Preserved comments
	VersionComment  string   // New version comment
	OriginalVersion string   // For tracking version history
}

Update represents a pending update for a GitHub Action

func CreateTestUpdate added in v1.20250321.1

func CreateTestUpdate(owner, name, oldVersion, newVersion, filePath string) *Update

CreateTestUpdate creates a test update object with the given parameters

func CreateTestUpdates added in v1.20250321.1

func CreateTestUpdates(count int, owner, name, oldVersion, newVersion, filePath string) []*Update

CreateTestUpdates creates a slice of test updates with the given parameters

type UpdateManager

type UpdateManager interface {
	// CreateUpdate creates an update for a given action and its latest version
	// Now includes commit hash and preserves comments
	CreateUpdate(ctx context.Context, file string, action ActionReference, latestVersion string, commitHash string) (*Update, error)

	// ApplyUpdates applies the given updates to workflow files
	// Now handles comment preservation and hash updates
	ApplyUpdates(ctx context.Context, updates []*Update) error

	// PreserveComments preserves existing comments when updating an action
	PreserveComments(action ActionReference) []string
}

UpdateManager manages the process of updating GitHub Actions

type VersionChecker

type VersionChecker interface {
	// GetLatestVersion returns the latest version and its commit hash for a given action
	GetLatestVersion(ctx context.Context, action ActionReference) (version string, hash string, err error)

	// IsUpdateAvailable checks if a newer version is available
	// Returns: available, new version, new hash, error
	IsUpdateAvailable(ctx context.Context, action ActionReference) (bool, string, string, error)

	// GetCommitHash returns the commit hash for a specific version of an action
	GetCommitHash(ctx context.Context, action ActionReference, version string) (string, error)
}

VersionChecker checks for newer versions of GitHub Actions

type VersionServerConfig added in v1.20250321.1

type VersionServerConfig struct {
	LatestRelease EndpointConfig
	TagsList      *EndpointConfig // Optional depending on server type
	TagRef        EndpointConfig
	AnnotatedTag  *EndpointConfig // Optional for annotated tags
}

VersionServerConfig represents configuration for all endpoints in a version test server

type VersionTestCase added in v1.20250321.1

type VersionTestCase struct {
	Name          string
	Action        ActionReference
	ServerType    VersionTestServerType
	WantVersion   string
	WantHash      string
	WantAvailable bool
	WantError     bool
}

VersionTestCase represents a test case for version checker tests

type VersionTestServerType added in v1.20250321.1

type VersionTestServerType string

VersionTestServerType defines types of version checker test servers

const (
	// NormalVersionServer is a server that returns valid version data
	NormalVersionServer VersionTestServerType = "normal"
	// EmptyReleaseServer returns no releases but valid tags
	EmptyReleaseServer VersionTestServerType = "empty_release"
	// ErrorReleaseServer returns errors for release endpoint
	ErrorReleaseServer VersionTestServerType = "error_release"
	// EmptyTagsServer returns no tags data
	EmptyTagsServer VersionTestServerType = "empty_tags"
	// ErrorTagsServer returns errors for tag endpoint
	ErrorTagsServer VersionTestServerType = "error_tags"
	// InvalidRefServer returns invalid ref data
	InvalidRefServer VersionTestServerType = "invalid_ref"
	// AnnotatedTagServer returns tag object for annotated tags
	AnnotatedTagServer VersionTestServerType = "annotated_tag"
	// MissingObjectServer returns ref without object
	MissingObjectServer VersionTestServerType = "missing_object"
	// MissingSHAServer returns object without SHA
	MissingSHAServer VersionTestServerType = "missing_sha"
	// AnnotatedTagErrorServer returns error for annotated tag requests
	AnnotatedTagErrorServer VersionTestServerType = "annotated_tag_error"
	// MissingTagObjectServer returns annotated tag without object
	MissingTagObjectServer VersionTestServerType = "missing_tag_object"
)

Jump to

Keyboard shortcuts

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