repometrics

package
v0.8.13 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2025 License: MIT Imports: 12 Imported by: 0

README

repometrics

Package repometrics provides functionality to gather and analyze metrics from software repositories.

It collects various metrics and information including:

  • Basic repository information (name, URL, creation date)
  • Project status (CNCF status, Kubernetes SIG status)
  • License information
  • Version information
  • Security vulnerabilities
  • Activity metrics:
    • Commit frequency
    • Release frequency
    • Contributor statistics
    • Issue and PR activity
    • Community engagement (stars, forks)

Documentation

Overview

Package repometrics provides functionality to analyze software repositories and gather metrics about their health, activity, and security status.

It can collect information from multiple sources including GitHub repositories, CNCF landscape data, and security vulnerability scans. The collected metrics provide insights into project activity, community engagement, release patterns, and security status.

The package is particularly useful for: - Evaluating project health and maintenance status - Understanding community engagement and contribution patterns - Monitoring security vulnerabilities - Analyzing release frequency and version management - Tracking project growth and adoption metrics

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Contributor

type Contributor struct {
	Name    string `json:"name"`
	URL     string `json:"url"`
	Commits int    `json:"commits"`
}

Contributor represents a contributor to a repository

type Metrics

type Metrics struct {
	Name                string                `json:"name"`                 // Name of the repository
	Type                RepoType              `json:"type"`                 // Type of the repository
	URL                 string                `json:"url"`                  // URL of the repository
	CreatedAt           *time.Time            `json:"created_at"`           // Creation timestamp of the repository
	IsCNCF              bool                  `json:"is_cncf"`              // True if the repository is part of CNCF
	CNCFStatus          string                `json:"cncf_status"`          // CNCF status of the repository
	IsKubernetesSIG     bool                  `json:"is_kubernetes_sig"`    // True if the repository is a Kubernetes SIG project
	BackingOrganization string                `json:"backing_organization"` // Organization backing the repository
	License             string                `json:"license"`              // License of the repository
	CurrentVersion      string                `json:"current_version"`      // Current version of the repository
	Vulnerabilities     []types.Vulnerability `json:"vulnerabilities"`      // Vulnerabilities found in the repository
	Stats               *Stats                `json:"stats"`                // Statistics of the repository
}

Metrics represents the metrics of a repository

func New

func New(t RepoType) (*Metrics, error)

New creates a new Metrics

func (*Metrics) ProjectAge

func (m *Metrics) ProjectAge() time.Duration

ProjectAge returns the age of the project

func (*Metrics) ScanVulnerabilities

func (m *Metrics) ScanVulnerabilities(ctx context.Context, s Scanner) error

ScanVulnerabilities scans for vulnerabilities and updates the metrics

func (*Metrics) UpdateCNCFStatus

func (m *Metrics) UpdateCNCFStatus(opts UpdateCNCFOptions) error

UpdateCNCFStatus updates the CNCF status of the repository

func (*Metrics) UpdateGitHub

func (m *Metrics) UpdateGitHub(ctx context.Context, client *github.Client, owner, repository string) error

UpdateGitHub updates the metrics using data from a GitHub repository

type ReleaseMetrics

type ReleaseMetrics struct {
	PerDay   float64
	PerWeek  float64
	PerMonth float64
	PerYear  float64
}

func CalculateReleaseMetrics

func CalculateReleaseMetrics(firstRelease, lastRelease *time.Time, totalReleases int) ReleaseMetrics

CalculateReleaseMetrics calculates the release metrics based on the first and last release dates and the total number of releases.

type RepoType

type RepoType string
const (
	RepoTypeGitHub RepoType = "github"
)

func (RepoType) IsValid

func (t RepoType) IsValid() bool

type Scanner

type Scanner interface {
	// Scan scans for vulnerabilities
	Scan(context.Context) ([]types.Vulnerability, error)
}

Scanner is the interface for vulnerability scanners

type Stats

type Stats struct {
	LastCommit        *time.Time    `json:"last_commit"`          // Date of the last commit.
	CommitsPerMonth6M int           `json:"commits_per_month_6m"` // Number of commits in the last 6 months.
	Contributors1Y    int           `json:"contributors_1y"`      // Number of contributors in the last year.
	FirstRelease      *time.Time    `json:"first_release"`        // Date of the first release.
	LastRelease       *time.Time    `json:"last_release"`         // Date of the last release.
	Releases          int           `json:"releases"`             // Total number of releases.
	ReleasesPerDay    float64       `json:"releases_per_day"`     // Number of releases per day.
	ReleasesPerWeek   float64       `json:"releases_per_week"`    // Number of releases per week.
	ReleasesPerMonth  float64       `json:"releases_per_month"`   // Number of releases per month.
	ReleasesPerYear   float64       `json:"releases_per_year"`    // Number of releases per year.
	OpenIssuesNow     int           `json:"open_issues_now"`      // Number of currently open issues.
	OpenedIssues6M    int           `json:"opened_issues_6m"`     // Number of issues opened in the last 6 months.
	ClosedIssues6M    int           `json:"closed_issues_6m"`     // Number of issues closed in the last 6 months.
	OpenedPRs6M       int           `json:"opened_prs_6m"`        // Number of pull requests opened in the last 6 months.
	ClosedPRs6M       int           `json:"closed_prs_6m"`        // Number of pull requests closed in the last 6 months.
	Likes             int           `json:"likes"`                // Number of likes/hearts/stars.
	Forks             int           `json:"forks"`                // Number of forks.
	TopCommitters     []Contributor `json:"top_committers"`       // Top committers overall.
	TopCommitters1Y   []Contributor `json:"top_committers_1y"`    // Top committers in the last year.
}

Stats represents the metrics of a repository

func NewStats

func NewStats() *Stats

type UpdateCNCFOptions

type UpdateCNCFOptions struct {
	Client             cncf.HTTPClient
	ProjectName        string
	ProjectRepoURL     string
	ProjectHomepageURL string
}

UpdateCNCFOptions represents the options for updating the CNCF status of a

ProjectName, ProjectRepoURL, and ProjectHomepageURL are used to find the project.

The order of precedence is: 1. ProjectRepoURL 2. ProjectHomepageURL 3. ProjectName (case-insensitive)

Jump to

Keyboard shortcuts

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