This document provides details on how the Universal Commits Migrator (UCM) interacts with the GitLab API, including fetching projects and commits, authentication, and handling rate limits.
The migrator uses the GitLab API to fetch the list of projects you have contributed to and the commits for each project. The main interactions with the GitLab API occur in the gitlab/client.go
and gitlab/fetcher.go
files.
The migrator uses a Personal Access Token to authenticate with the GitLab API. You need to provide this token in your .env
file under the key GITLAB_TOKEN
. The token should have the read_api
scope to allow the tool to fetch commit data.
If you want to fetch commits from specific projects, you can list their IDs in the CONTRIBUTED_PROJECTS
environment variable. If this variable is left empty, the migrator fetches all the projects you have access to.
The FetchProjects()
function in gitlab/client.go
handles fetching the project list:
/projects
membership=true
to filter projects that you are a member of.simple=true
to get a simplified version of the projects’ details.page
and per_page
.The FetchCommitsForProject()
function in gitlab/client.go
fetches commits for a specific project:
/projects/{projectID}/repository/commits
page
and per_page
for pagination.The function loops through the paginated results until all commits are fetched.
GitLab imposes rate limits on API requests. If you encounter rate-limiting issues, you might see errors related to exceeding these limits. In such cases, you might need to wait or adjust the frequency of your requests.
The code checks the HTTP status code of each response. Any status code other than 200 OK is considered an error, and the tool logs the error details. The logs can be found in the app.log
file for further investigation.
By understanding the interaction with the GitLab API, you can troubleshoot issues, extend the tool’s capabilities, or even contribute to its improvement. If you have any enhancements or encounter any issues, feel free to contribute to the project repository.