pub struct GitLab { /* private fields */ }Expand description
GitLab API client for retrieving user activity and commit information.
This client handles authentication and data retrieval from GitLab instances, specifically focusing on user events and commit details that can be transformed into task entries for time tracking purposes.
The client is stateless and thread-safe, making it suitable for concurrent operations and long-running applications.
Implementations§
Source§impl GitLab
impl GitLab
Sourcepub fn new(config: &GitLabConfig) -> Self
pub fn new(config: &GitLabConfig) -> Self
Creates a new GitLab API client instance.
Initializes the HTTP client with default settings suitable for GitLab API interactions. The client is configured for JSON responses and includes reasonable timeout settings.
§Arguments
config- GitLab configuration containing API endpoint and authentication token
§Example
let config = GitLabConfig {
access_token: "glpat-xxxxxxxxxxxxxxxxxxxx".to_string(),
api_url: "https://gitlab.example.com".to_string(),
};
let client = GitLab::new(&config);Sourcepub async fn get_user_id(&self) -> Result<u32>
pub async fn get_user_id(&self) -> Result<u32>
Retrieves the current user’s GitLab ID.
Makes a request to GitLab’s /user endpoint to fetch the authenticated user’s
information. The user ID is required for subsequent calls to the events API.
§Returns
Result<u32>- The numeric user ID on success
§Errors
Returns an error if:
- Network request fails
- Authentication token is invalid
- GitLab returns an unexpected response format
§API Endpoint
GET /api/v4/user - Requires read_user scope
Sourcepub async fn get_today_commits(&self) -> Result<Vec<CommitInfo>>
pub async fn get_today_commits(&self) -> Result<Vec<CommitInfo>>
Fetches all commits made by the authenticated user today.
This is the primary method for discovering development activity that can be converted into time tracking tasks. It retrieves user events from yesterday to tomorrow (to handle timezone issues) and filters for push events containing commit information.
§Process Flow
- Date Range Calculation: Creates a date range around today to handle timezone differences
- User ID Retrieval: Gets the authenticated user’s ID for events API
- Events Fetching: Retrieves user events within the date range
- Event Filtering: Processes only “pushed to” events with commit data
- Commit Details: Fetches detailed commit information for each push
- Message Processing: Extracts and cleans commit messages for task names
§Error Resilience
This method is designed to be fault-tolerant in production environments:
- Network failures return empty results instead of errors
- Individual commit fetch failures are skipped
- API parsing errors are logged and don’t interrupt processing
- Missing or malformed data is handled gracefully
§Returns
Result<Vec<CommitInfo>>- List of today’s commits, or empty vector on any error
§Example
let commits = gitlab_client.get_today_commits().await?;
for commit in commits {
println!("Commit {}: {}", commit.sha, commit.message);
}