import-gitlab-commits
import-gitlab-commits copied to clipboard
Import commits from a private GitLab repository in an anonymized way.
Import GitLab Commits
The tool to import commits from private GitLab to separate repo. Can be used to show your programming activity for another company in GitHub.
Check out this informative blog post for a practical use case on how to import GitLab commits here.
Getting Started
-
Download and install Go 1.22.
-
Install the program by running the command in a shell:
go install github.com/alexandear/import-gitlab-commits@latest -
Set environment variables and run
import-gitlab-commits:export GITLAB_BASE_URL=<your_gitlab_server_url> export GITLAB_TOKEN=<your_gitlab_token> export COMMITTER_NAME="<Name Surname>" export COMMITTER_EMAIL=<[email protected]> $(go env GOPATH)/bin/import-gitlab-commits
where
GITLAB_BASE_URLis a GitLab instance URL, e.g.https://gitlab.com,https://gitlab.gnome.orgor any GitLab server;GITLAB_TOKENis a personal access token;COMMITTER_NAMEis your GitHub name with surname, e.g.John Doe(can be passed togit config user.name);COMMITTER_EMAILis your GitHub email, e.g.[email protected](valid forgit config user.email);$(go env GOPATH)/bin/is the path whereimport-gitlab-commitsinstalled.
Example
Contributions before running import-gitlab-commits:
After:
Internals
What work the tool does:
- gets current user info by
GITLAB_TOKEN; - fetches from
GITLAB_BASE_URLprojects that the current user contributed to; - for all projects fetches commits where author's email is the current user's email;
- creates new repo
repo.gitlab.yourcompany.com.currentusernameand commits all fetched commits with messageProject: GITLAB_PROJECT_ID commit: GITLAB_COMMIT_HASH, commit dateGITLAB_COMMIT_DATE, and commit authorCOMMITTER_NAME <COMMITTER_EMAIL>.
To show the changes on GitHub you need to:
- create a new repo
yourcompany-contributionsin GitHub; - open folder
repo.gitlab.yourcompany.com.currentusername; - add remote url
git remote add origin [email protected]:username/yourcompany-contributions.git; - push changes.
Integration Tests
To run integration tests:
-
Set
GITLAB_TOKENenvironment variables with the value obtained at https://gitlab.com/-/user_settings/personal_access_tokens. Necessary scopes:read_api;read_user;read_repository.
-
Set
GITLAB_BASE_URLwithhttps://gitlab.com. -
Run
make test-integration.