Documentation
¶
Overview ¶
Package gitlab provides an HTTP client for the GitLab API.
Overview ¶
This package provides GitLab integration for metadata enrichment, complementing the GitHub provider for packages hosted on GitLab.
Usage ¶
client, err := gitlab.NewClient(token, 24 * time.Hour)
if err != nil {
log.Fatal(err)
}
Authentication ¶
A GitLab personal access token is optional. Without a token, only public repositories can be accessed.
URL Extraction ¶
ExtractURL parses GitLab repository URLs from package metadata:
owner, repo, ok := gitlab.ExtractURL(pkg.ProjectURLs, pkg.HomePage)
if ok {
// Found GitLab repository: gitlab.com/owner/repo
}
This is useful for identifying GitLab-hosted packages and fetching their repository metrics.
Current Limitations ¶
The GitLab client currently focuses on URL extraction. Full metrics fetching (stars, contributors, etc.) is planned for future releases.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractURL ¶
ExtractURL extracts GitLab repository owner and name from package URLs.
This function searches through urls map and homepage for GitLab URLs. It looks for patterns like "https://gitlab.com/owner/repo".
Parameters:
- urls: Map of URL keys to URL values from package metadata (may be nil)
- homepage: Fallback homepage URL (may be empty)
Returns:
- owner: Repository owner username (empty if not found)
- repo: Repository name (empty if not found)
- ok: true if a GitLab URL was found, false otherwise
This function is safe for concurrent use.
Types ¶
type Client ¶
type Client struct {
*integrations.Client
}
Client provides access to the GitLab API for repository metadata enrichment. It handles HTTP requests with caching, automatic retries, and optional authentication.
All methods are safe for concurrent use by multiple goroutines.
Note: Full metrics fetching (stars, contributors, etc.) is not yet implemented. Currently, this client focuses on URL extraction. Use ExtractURL to identify GitLab-hosted packages.
func NewClient ¶
NewClient creates a GitLab API client with optional authentication.
The token parameter is a GitLab personal access token for authentication. Pass an empty string to use unauthenticated requests (public repositories only).
The cacheTTL parameter sets how long responses are cached. Typical values: 1-24 hours for production, 0 for testing (no cache).
Returns an error if the cache directory cannot be created or accessed. The returned Client is safe for concurrent use.