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.
7 Comments
Your script/website seems to have disappeared! That was quick 🙂
Any idea where I can get a copy?
Thnaks.
You caught me. I started to do a migration earlier this week and it stalled out. Give me a few minutes and I’ll get the server back online!
Hokay, code is back online. Sorry to leave you hanging!
Hahaha – sounds like me 🙂
Many thanks!!
B. Rgds
John
FYI there is a little inconsistency with variables between your notes here and your gitea repo and the script.
It reads the config file for GITHUB_USERNAME but then uses this:
“https://api.github.com/users/$USERNAME/repos”)
It also uses $GITEA_USER and checks they exist but then uses:
curl….
“uid”: ‘$USER_ID’,
Which I think should be $GITEA_USER
We also have $REPO_OWNER but that doesn’t get read as a $VAR 🙂
And then $GITEA_ORG is a floater by itself.
I’d do a patch but can’t do a PR 🙂
aight John…let’s get you that login! This was part of a project over the course of a couple of days and I did not do much (apparently any) QC on the code. You’re gonna get an email from me shortly. Thanks for offering to help improve things. <3
EDIT: I'm running around a bit today, so won't be able to dig into things until at least Monday, but let's see how we can make this tool more useful for everyone. If you've got LinkedIn, holler at me on there so I can spy on you...I mean...get to know you better!
Hi Rob,
Got that thanks 😉 NP – I understand.
Happy to help – I am no great coder but not a complete noob. I’ll open an issue with my notes from here and we can work on it thereafter.
Found you on LinkedIn – I rarely visit the spawn of the devil!!