github

package
v0.0.0-...-af3453c Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package github provides a client for checking GitHub user login status. This supports the login revalidation worker in detecting renamed and deleted accounts.

Package github provides test mocks for the GitHub client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	// CheckLogin checks if a login exists on GitHub and returns its status.
	//
	// Returns:
	//   - LoginResult with Status, optional NewLogin, and optional ErrorMsg
	//   - error if the check itself fails (network issue, malformed response, etc.)
	CheckLogin(ctx context.Context, login string) (*LoginResult, error)
}

Client defines the interface for checking GitHub login status. This allows for test mocks without making live API calls.

func NewHTTPClient

func NewHTTPClient(token string, timeout time.Duration) Client

NewHTTPClient creates a new GitHub API client.

Parameters:

  • token: GitHub personal access token for authentication
  • timeout: Request timeout (default 15s if 0)

Returns:

  • A configured Client that makes real HTTP requests to GitHub API

type HTTPClient

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

HTTPClient implements Client using the real GitHub API.

func (*HTTPClient) CheckLogin

func (c *HTTPClient) CheckLogin(ctx context.Context, login string) (*LoginResult, error)

CheckLogin checks a login against the GitHub API.

type LoginResult

type LoginResult struct {
	Status   LoginStatus // The detected status
	NewLogin *string     // The new login if Status == StatusRenamed, otherwise nil
	ErrorMsg *string     // Error message if Status == StatusRetry, otherwise nil
}

LoginResult represents the result of checking a login's status.

type LoginStatus

type LoginStatus string

LoginStatus represents the possible outcomes of checking a login's liveness.

const (
	// StatusValidated means the login exists and matches the queried login
	StatusValidated LoginStatus = "validated"
	// StatusRenamed means the login was renamed to a different login
	StatusRenamed LoginStatus = "renamed"
	// StatusDeleted means the login no longer exists (account deleted)
	StatusDeleted LoginStatus = "deleted"
	// StatusRetry means a transient error occurred and the check should be retried
	StatusRetry LoginStatus = "retry"
)

type MockClient

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

MockClient is a mock implementation of Client for testing. It returns predefined responses without making HTTP calls.

func NewMockClient

func NewMockClient() *MockClient

NewMockClient creates a new mock client with no predefined responses. By default, it returns StatusValidated for any login. Use SetResponse to configure specific responses.

func (*MockClient) CallCount

func (m *MockClient) CallCount() int

CallCount returns the number of times CheckLogin was called.

func (*MockClient) CalledLogins

func (m *MockClient) CalledLogins() []string

CalledLogins returns a list of logins that were checked, in order. This is useful for verifying that the worker processed logins in the expected sequence.

func (*MockClient) CheckLogin

func (m *MockClient) CheckLogin(ctx context.Context, login string) (*LoginResult, error)

CheckLogin checks a login and returns the configured result. If no specific result was configured for this login, returns the default result.

func (*MockClient) Reset

func (m *MockClient) Reset()

Reset clears all configured responses and call history.

func (*MockClient) SetDefaultResult

func (m *MockClient) SetDefaultResult(result *LoginResult)

SetDefaultResult configures the default result returned for logins without specific responses configured via SetResponse.

func (*MockClient) SetResponse

func (m *MockClient) SetResponse(login string, result *LoginResult)

SetResponse configures the mock to return a specific result for a given login.

Example:

mock.SetResponse("old-name", &LoginResult{
    Status:   StatusRenamed,
    NewLogin: strPtr("new-name"),
})
mock.SetResponse("deleted-user", &LoginResult{
    Status: StatusDeleted,
})

func (*MockClient) WasCalled

func (m *MockClient) WasCalled(login string) bool

WasCalled checks if a specific login was queried.

type User

type User struct {
	Login     string `json:"login"`
	ID        int64  `json:"id"`
	NodeID    string `json:"node_id"`
	Type      string `json:"type"`
	SiteAdmin bool   `json:"site_admin"`
}

User represents a GitHub user from the API response.

Jump to

Keyboard shortcuts

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