Skip to content

Instantly share code, notes, and snippets.

@hawx
Created July 18, 2016 11:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hawx/7d3170b986dd35e20da7e6a7990f84d1 to your computer and use it in GitHub Desktop.
Save hawx/7d3170b986dd35e20da7e6a7990f84d1 to your computer and use it in GitHub Desktop.
'use strict';
var GitHub = require('github-api');
var fetch = require('node-fetch');
var exec = require('child_process').exec;
const gh = new GitHub({ token: 'MY_TOKEN' });
const org = gh.getOrganization('MY_ORG');
fetch('https://api.bitbucket.org/2.0/teams/MY_ORG/repositories')
.then(data => data.json())
.then(body => {
body.values.forEach(value => {
let cloneLink = value.links.clone.filter(link => link.name === 'https')[0]
migrate(value.name, cloneLink.href);
})
});
function migrate(name, remoteUrl) {
console.log('migrate: ' + remoteUrl);
doExec(`git clone ${remoteUrl} ${name}`)
.then(() => org.createRepo({
name: name,
private: false,
team_id: MY_TEAM_ID
}))
.then(resp => doExec(`git --git-dir ${name}/.git remote set-url origin ${resp.data.clone_url}`))
.then(resp => doExec(`git --git-dir ${name}/.git push --all`))
.then(resp => doExec(`git --git-dir ${name}/.git push --tags`))
.catch(console.warn);
}
function doExec(command) {
console.log('exec: ' + command);
return new Promise((resolve, reject) => {
exec(command, (err, stdout, stderr) => {
if (err) {
reject(err)
return;
}
resolve();
});
});
}
{
"name": "bitbucket-to-github-migrator",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"git": "^0.1.5",
"github-api": "^2.3.0",
"node-fetch": "^1.5.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment