What?
The below script will help automate the process of migrating all public projects from a GitHub user to a Gitea Organization. Before running the script, please be sure to create the organization in Gitea and create a token specifically for this script.
Why?
A number of folks have reacted negatively to GitHub’s introduction of Copilot. It’s got great possibilities for those that are primarily concerned with getting their projects out without spending all their time on the code itself. It also poses massive concerns about intellectual property theft. While I am certainly not the most adept coder, I do value privacy and giving credit where credit is due, and have largely left GitHub as a result of Copilot.
How?
This script follows the workflow below:
- Identify the UID for the gitea user and verify that UID works (required for the API).
- Identify the current GitHub rate limit and remaining allowed calls to GitHub’s API.
- Perform the migration
- Check the state file for progress. This will help if the operation is broken at some point and needs to be resumed (resume is untested)
- Gather list of the repositories and handle pagination if the user has more than 100 repos.
- Check if the repo already exists in Gitea and skip if it does.
Before running the script, you will need to specify the following values in the “User-input variables” section:
ASSUMPTION #1: This script assumes you will be using an organization to post all new repositories into. Let’s face it some folks have a ridiculous number of repos and this function will greatly assist in organizing your environment. I’ve not tested using the script without “REPO_OWNER” specified or any error handling that may result from the removal of this function.
ASSUMPTION #2: If you want the repositories to not be listed publicly, then you will need to set the Organization’s visibility to either “Private” or “Limited”. If you leave the organization “Public”, then all repos within the org will be publicly browsable. You can also edit the script “private” setting to “true” (contained in Assumption #3 screenshot below), but setting organization privacy is the recommended method.
ASSUMPTION #3: You want the local repository to be updated with any changes in the GitHub project. Most of the time, you’ll want this to ensure you’re staying up to date with the main project’s code…but you might not want it. If you don’t, please change “true” to “false” in the line that reads ‘“mirror”: true,‘
The Code!
As this code will likely change over time, I’ve placed it onto my Git server.