Documentation
¶
Index ¶
- type Config
- type GitAccessToken
- type GitHubAccessToken
- type GitHubClient
- func (c *GitHubClient) CreateGitHubRepositoryCache(ctx context.Context, repos []*repository.Repository) error
- func (c *GitHubClient) ExistsGoMod(ctx context.Context, owner, repo string) (bool, error)
- func (c *GitHubClient) FindRepositoriesByOwner(ctx context.Context, owner string) ([]string, error)
- func (c *GitHubClient) GetHeadCommit(ctx context.Context, owner, repo string) (string, error)
- func (c *GitHubClient) IsArchived(ctx context.Context, owner, repo string) (bool, error)
- type GitHubRepository
- type GoModule
- type GoModuleScore
- type GoModuleStorage
- type ModRank
- func (r *ModRank) Run(ctx context.Context, repos ...*repository.Repository) ([]*GoModuleScore, error)
- func (r *ModRank) Score(ctx context.Context, repos ...*repository.Repository) ([]*GoModuleScore, error)
- func (r *ModRank) UpdateRepositoryStatusByGitHubAPI(ctx context.Context, repos ...*repository.Repository) error
- type Option
- func WithCleanupRepository() Option
- func WithGitAccessToken(issuer TokenIssuer) Option
- func WithGitHubAPICache() Option
- func WithGitHubToken(issuer TokenIssuer) Option
- func WithLogLevel(v slog.Level) Option
- func WithLogger(v *slog.Logger) Option
- func WithSQLiteDSN(dsn string) Option
- func WithStorage(s Storage) Option
- func WithTempDir(dir string) Option
- func WithWorker(v int) Option
- type RepositoryStatus
- type RepositoryStorage
- type SQLiteStorage
- func (s *SQLiteStorage) CreateGoModuleStorageIfNotExists(ctx context.Context) error
- func (s *SQLiteStorage) CreateRepositoryStorageIfNotExists(ctx context.Context) error
- func (s *SQLiteStorage) FindGoModuleByID(ctx context.Context, id string) (*GoModule, error)
- func (s *SQLiteStorage) FindRepositoryByName(ctx context.Context, nameWithOwner string) (*RepositoryStatus, error)
- func (s *SQLiteStorage) FindRootGoModules(ctx context.Context) ([]*GoModule, error)
- func (s *SQLiteStorage) InsertOrUpdateGoModules(ctx context.Context, nameWithOwner string, mods []*GoModule) error
- func (s *SQLiteStorage) InsertOrUpdateRepository(ctx context.Context, st *RepositoryStatus) error
- type Storage
- type TokenIssuer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Database string `yaml:"database"`
Organization string `yaml:"organization"`
Repositories []string `yaml:"repositories"`
ClonePath string `yaml:"clonePath"`
}
func LoadConfig ¶
type GitAccessToken ¶ added in v0.9.0
type GitAccessToken struct {
// contains filtered or unexported fields
}
func GitStaticAccessToken ¶ added in v0.9.0
func GitStaticAccessToken(tk string) *GitAccessToken
type GitHubAccessToken ¶ added in v0.9.0
type GitHubAccessToken = GitAccessToken
func GitHubStaticAccessToken ¶ added in v0.9.0
func GitHubStaticAccessToken(tk string) *GitHubAccessToken
type GitHubClient ¶
type GitHubClient struct {
// contains filtered or unexported fields
}
func NewGitHubClient ¶
func NewGitHubClient(ctx context.Context, token *GitHubAccessToken) *GitHubClient
func (*GitHubClient) CreateGitHubRepositoryCache ¶
func (c *GitHubClient) CreateGitHubRepositoryCache(ctx context.Context, repos []*repository.Repository) error
func (*GitHubClient) ExistsGoMod ¶
func (*GitHubClient) FindRepositoriesByOwner ¶ added in v0.2.0
func (*GitHubClient) GetHeadCommit ¶
func (*GitHubClient) IsArchived ¶
type GitHubRepository ¶
type GitHubRepository struct {
Repository *repository.Repository
IsArchived bool
HeadCommit string
}
type GoModule ¶
type GoModule struct {
// ID to uniquely identify a GoModule, hashed from Repository/GoModPath/Name/Version.
ID string
// Repository name of the repository using this Go module.
Repository string
// GoModPath path to the go.mod on the repository using this Go module.
GoModPath string
// Name is the Go module name. e.g.) github.com/goccy/go-modrank
Name string
// Version is the version text for the Go module. e.g.) v1.2.3
Version string
// HostedRepository is the hosted repository name of the Go module.
HostedRepository string
// Refers is the list of Modules this Go module depends on.
Refers []*GoModule
// Referers is th list of Modules on which this Go module is dependent.
Referers []*GoModule
// contains filtered or unexported fields
}
GoModule represents of the state of the Go module used in a given repository.
type GoModuleScore ¶
type GoModuleStorage ¶
type GoModuleStorage interface {
CreateGoModuleStorageIfNotExists(ctx context.Context) error
FindRootGoModules(ctx context.Context) ([]*GoModule, error)
FindGoModuleByID(ctx context.Context, id string) (*GoModule, error)
InsertOrUpdateGoModules(ctx context.Context, nameWithOwner string, mods []*GoModule) error
}
type ModRank ¶
type ModRank struct {
// contains filtered or unexported fields
}
func (*ModRank) Run ¶
func (r *ModRank) Run(ctx context.Context, repos ...*repository.Repository) ([]*GoModuleScore, error)
Run compute and return the Go module score for each specified repository. If UpdateRepositoryStatusByGitHubAPI has been called previously, precomputed statuses can be used to reduce processing time.
func (*ModRank) Score ¶ added in v0.3.0
func (r *ModRank) Score(ctx context.Context, repos ...*repository.Repository) ([]*GoModuleScore, error)
Score compute and return the Go module score for each specified repository. This method uses the data already stored in the database and calculates only the Score. If you have not yet registered your data, use the Run method to register your data in advance.
func (*ModRank) UpdateRepositoryStatusByGitHubAPI ¶
func (r *ModRank) UpdateRepositoryStatusByGitHubAPI(ctx context.Context, repos ...*repository.Repository) error
UpdateRepositoryStatusByGitHubAPI if you are working with a large number of repositories and they are all on GitHub, it is useful to skip the process of cloning the repositories by checking in advance whether they have been archived or whether they have a go.mod file, and thus shorten the process. This API checks for these things and saves them in the database.
type Option ¶
func WithCleanupRepository ¶ added in v0.8.0
func WithCleanupRepository() Option
WithCleanupRepository delete the cloned repository after scanning is complete.
func WithGitAccessToken ¶ added in v0.6.0
func WithGitAccessToken(issuer TokenIssuer) Option
WithGitAccessToken if you want to access a private module when running go mod graph command, you need permission to access the repository hosting the module. Specifically, since `git ls-remote` command is used, access rights need to be set in gitconfig. This library allows you to specify the WithGitAuthToken option, which allows access to the repository using the specified token with temporary gitconfig.
func WithGitHubAPICache ¶
func WithGitHubAPICache() Option
WithGitHubAPICache use the GitHub API to reduce the time spent scanning repositories as much as possible. If you are trying to scan private repositories, you need to set the access token in the GITHUB_TOKEN environment variable or specify the token directly in the WithGitHubToken() option.
func WithGitHubToken ¶
func WithGitHubToken(issuer TokenIssuer) Option
WithGitHubToken specify the token for using the GitHub API. If this option is not specified, the value of the GITHUB_TOKEN environment variable is used.
func WithLogLevel ¶
WithLogLevel set log level. If you configure your logger with WithLogger() option, this option is ignored.
func WithLogger ¶ added in v0.3.0
WithLogger set your logger.
func WithSQLiteDSN ¶
WithSQLiteDSN set SQLite dsn. If this option is not specified, it is stored in the file os.TempDir()/go-modrank/tmp.db. If the WithStorage() option is specified, this option is ignored.
func WithStorage ¶
WithStorage specify the storage for storing the scan results. By default, SQLite is used, but if you want to use another database, you can change this option.
func WithTempDir ¶ added in v0.7.0
WithTempDir specifies the directory to which the temporary file is written Use this directory if the database file is not specified or if the gitconfig file is written.
func WithWorker ¶
WithWorker set the number of workers scanning the repository in concurrent. Default is 1 (sequential).
type RepositoryStatus ¶
type RepositoryStorage ¶
type SQLiteStorage ¶
type SQLiteStorage struct {
// contains filtered or unexported fields
}
func NewSQLiteStorage ¶
func NewSQLiteStorage(dsn string) (*SQLiteStorage, error)
func (*SQLiteStorage) CreateGoModuleStorageIfNotExists ¶
func (s *SQLiteStorage) CreateGoModuleStorageIfNotExists(ctx context.Context) error
func (*SQLiteStorage) CreateRepositoryStorageIfNotExists ¶
func (s *SQLiteStorage) CreateRepositoryStorageIfNotExists(ctx context.Context) error
func (*SQLiteStorage) FindGoModuleByID ¶
func (*SQLiteStorage) FindRepositoryByName ¶
func (s *SQLiteStorage) FindRepositoryByName(ctx context.Context, nameWithOwner string) (*RepositoryStatus, error)
func (*SQLiteStorage) FindRootGoModules ¶
func (s *SQLiteStorage) FindRootGoModules(ctx context.Context) ([]*GoModule, error)
func (*SQLiteStorage) InsertOrUpdateGoModules ¶
func (*SQLiteStorage) InsertOrUpdateRepository ¶
func (s *SQLiteStorage) InsertOrUpdateRepository(ctx context.Context, st *RepositoryStatus) error
type Storage ¶
type Storage interface {
RepositoryStorage
GoModuleStorage
}