Commits

Anonymous committed 0199378

- support "description" and "homepage" fields when syncing from github->bitbucket and vice-versa

Comments (0)

Files changed (4)

bitbucket2github/bitbucket.py

     f = urllib2.urlopen(url)
     response = json.loads(f.read())
 
-    return [repo.get('slug') for repo in response.get('repositories')]
+    return [
+        {
+            "name":repo.get('slug'),
+            "description":repo.get('description', ''),
+            "homepage":repo.get('website', ''),
+        } for repo in response.get('repositories')
+    ]
+
 
 
 def repo_exists(reponame, username):
         return True
 
 
-def create_repo(reponame, username, password):
+def create_repo(repo, username, password):
     """ Creates a public repository with the given credentials """
 
+    reponame = repo['name']
+
     if not repo_exists(reponame, username):
         print "Creating " + reponame + " in BitBucket"
         # Somehow BitBucket authentication with urllib2 is not working. So using this ugly approach.
-        cmd = 'curl -d "name={reponame}" -u {username}:{password} {base_url}/repositories/'
+        cmd = 'curl -d "name={reponame}" -d "description={description}" -d "website={url}" -u {username}:{password} {base_url}/repositories/'
         cmd = cmd.format(reponame=reponame,
                          username=username,
                          password=password,
-                         base_url=base_url)
+                         base_url=base_url,
+                         description=repo['description'],
+                         url=repo['homepage'])
 
         sh(cmd)

bitbucket2github/bitbucket2github.py

 
 
 def backup(repo):
-    print "Syncing " + repo + " from BitBucket to GitHub"
+    print "Syncing %s from BitBucket to GitHub" % repo['name']
     github.create_repo(repo, github_username, github_api_token)
 
-    bitbucket_repo = bitbucket_url.format(bitbucket_username, repo)
-    github_repo = github_url.format(github_username, repo)
-    local_repo = os.path.join(tmp_dir, repo)
+    bitbucket_repo = bitbucket_url.format(bitbucket_username, repo['name'])
+    github_repo = github_url.format(github_username, repo['name'])
+    local_repo = os.path.join(tmp_dir, repo['name'])
 
     if os.path.exists(local_repo):
         sh('hg pull {0} -R {1}'.format(bitbucket_repo, local_repo))

bitbucket2github/github.py

     """ Returns the list of public repos owned by user """
 
     github = Github()
-    return [repo.name for repo in github.repos.list(username)]
+    return [{
+            "name":repo.name,
+            "description":repo.description or '',
+            "homepage":repo.homepage or ''
+        }
+        for repo in github.repos.list(username)]
 
 
 def repo_exists(reponame, username):
         return True
 
 
-def create_repo(reponame, username, api_token):
+def create_repo(repo, username, api_token):
     """ Creates a public repository with the given credentials """
 
+    reponame = repo['name']
     github = Github(username=username, api_token=api_token)
 
     if not repo_exists(reponame, username):
         print "Creating " + reponame + " in GitHub"
-        github.repos.create(reponame)
+        github.repos.create(reponame, 
+                        description=repo['description'], 
+                        homepage=repo['homepage'])
+

bitbucket2github/github2bitbucket.py

 
 
 def backup(repo):
-    print "Syncing " + repo + " from GitHub to BitBucket"
+    print "Syncing %s from GitHub to BitBucket" % repo['name']
     bitbucket.create_repo(repo, bitbucket_username, bitbucket_password)
 
-    bitbucket_repo = bitbucket_url.format(bitbucket_username, repo)
-    github_repo = github_url.format(github_username, repo)
-    local_repo = os.path.join(tmp_dir, repo)
+    bitbucket_repo = bitbucket_url.format(bitbucket_username, repo['name'])
+    github_repo = github_url.format(github_username, repo['name'])
+    local_repo = os.path.join(tmp_dir, repo['name'])
 
     if os.path.exists(local_repo):
         sh('hg fetch {0} -R {1}'.format(github_repo, local_repo))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.