Created
September 17, 2019 13:28
-
-
Save lrecknagel/cdb5f85f150f5f15d882651b6119157e to your computer and use it in GitHub Desktop.
a small nodejs module to migrate a list of github repos (FROM A ORGANIZATION) to gitea
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fetch = require('node-fetch'), | |
FormData = require('form-data'); | |
// your gitea domain without trailing slash | |
const GITEA_DOMAIN = 'https://subdomain.domain.xyz'; | |
// you can find this variables when you visit your gitea installation | |
// open dev-tools and look in the Cookies section | |
const i_like_gitea = 'YOUR_I_LIKE_GITEA_STRING'; | |
const gitea_awesome = 'YOUR_GITEA_AWESOME_STRING'; | |
const gitea_incredible = 'YOUR_GITEA_INCREDIBLE_STRING'; | |
// _csrf is also listed under Cookies section but is urlencoded here | |
// you MUST use the decoded string here!!! | |
// get it via: node -e "console.log(decodeURIComponent('<URL_ENCODED_CSRF'));" | |
const _csrf = 'YOUR_DECODED_CSRF_STRING'; | |
// your github repo url(s) with added username and accessToken | |
const repoUrls = [ | |
'https://<githubUserName:githubPersonalAccessToken@github.com/<Organization|Name>/githubRepoName', | |
]; | |
async function run() { | |
try { | |
for (const url of repoUrls) { | |
// extract repoName from github url | |
const repoNameParts = url.split('/'); | |
const repoName = repoNameParts[repoNameParts.length - 1]; | |
// build the FormData | |
const form = new FormData(); | |
form.append('_csrf', _csrf); | |
form.append('clone_addr', url); | |
form.append('auth_username', ''); | |
form.append('auth_password', ''); | |
form.append('uid', '1'); | |
form.append('repo_name', repoName); | |
form.append('private', 'on'); | |
form.append('description', ''); | |
const cookie = `lang=de-DE; i_like_gitea=${ i_like_gitea }; gitea_awesome=${ gitea_awesome }; gitea_incredible=${ gitea_incredible }; _csrf=${ encodeURIComponent(_csrf) }`; | |
const headers = { | |
'Cookie': cookie, | |
'Conntent-Type': 'application/x-www-form-urlencoded', | |
'Sec-Fetch-Mode': 'navigate', | |
'Sec-Fetch-User': '?1', | |
}; | |
const migResultRes = await fetch(`${ GITEA_DOMAIN }/repo/migrate`, { | |
method: 'POST', | |
body: form, | |
headers | |
}); | |
console.log(migResultRes); | |
} | |
} catch (error) { | |
console.error(error); | |
} | |
} | |
run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment