This project is a GitLab Contributions Exporter that connects to GitLab instances, retrieves user events, projects, and commits, and processes them into a uniform format. The processed contributions are then committed to a new Git repository.
- Connects to multiple GitLab instances
- Authenticates users using private tokens
- Retrieves user events, projects, and commits
- Processes contributions into a uniform format
- Creates a new Git repository and commits the contributions
- Python 3.6+
- Git
- GitLab API access tokens
- Environment variables for GitLab instances and tokens
-
Clone the repository:
git clone <repository-url> cd <repository-directory>
-
Create a virtual environment and activate it:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install the required packages:
pip install -r requirements.txt
-
Create a
.env
file in the root directory with the following content:GITLAB-INSTANCE=<your-gitlab-instance-urls-comma-separated> GITLAB-TOKEN=<your-gitlab-tokens-comma-separated>
-
Run the application:
python main.py
-
The application will:
- Check for existing exports and load them if available
- Establish connections to the GitLab instances
- Authenticate the user
- Retrieve user events, projects, and commits
- Process the contributions into a uniform format
- Create a new Git repository and commit the contributions
main.py
: The main application scriptdb/
: Directory containing exported JSON filesrequirements.txt
: List of required Python packages
__init__(self, instance: str, token: str) -> None
: Initializes the GitLabAPI instanceestablish_connection(self) -> None
: Establishes a connection to the GitLab API using the private tokenauthenticate(self) -> None
: Authenticates the user and sets the user attribute to the authenticated userget_valid_user_events(self) -> list
: Gets events for the user and filters to only include specificaction_name
sget_projects(self) -> list
: Gets all projects for the userget_user_commits_for_projects(self, projects: list) -> list
: Gets all commits for the user in the specified projects_get_commits(self, project_id: int, project_created_at: str) -> list
: Gets all commits for a project by the author
__init__(self, instances: list, tokens: list) -> None
: Initializes the App instancecheck_for_existing_exports(self) -> None
: Checks for existing exports and updates instance attributes if foundcreate_repo(self) -> Repo
: Creates a new repository. If a repository already exists, it will be deleted and a new one will be createdcreate_commit(self, contribution: dict) -> None
: Creates a commit from the contributioncreate_commits_from_contributions(self) -> None
: Creates commits from the contributionsexport_dicts_to_file(self, dicts: list[dict], filename: str) -> None
: Exports the list of dictionaries to a fileprocess_contributions(self) -> None
: Processes the contributions into uniform dictionaries sorted by contribution timerun(self) -> None
: Runs the application
This project is licensed under the MIT License. See the LICENSE
file for details.