Skip to content

Instantly share code, notes, and snippets.

@lrecknagel
Created September 17, 2019 13:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lrecknagel/cdb5f85f150f5f15d882651b6119157e to your computer and use it in GitHub Desktop.
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
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