How to push a Git server repository issues to Github repository?

111 views Asked by At

I have a repository on the Git Server like Bitbucket and now I want to switch to Github. So I make a copy of my repository on the Github successfully, but the my repository issues (Nearly 200 issue) not copied on the Github repository!

Exist a way to copy all issues on the Github repository without inserting one by one manually !?

1

There are 1 answers

0
andy-berry-dev On BEST ANSWER

As choroba has said above you can use the BitBucket API to retrieve your current list of issues, or details on a specific issue. Have a look at https://confluence.atlassian.com/display/BITBUCKET/Use+the+Bitbucket+REST+APIs for more info on this. In a nutshell, you can make a request to https://api.bitbucket.org/2.0/repositories/<repo-owner-username>/<repo-name>/issues/<ID> and get back a JSON response of the issue details. You can go to https://api.bitbucket.org/2.0/repositories/tutorials/tutorials.bitbucket.org/issues/1 in your browser to see an example of what the response looks like.

Since you wan't to migrate all your issues you can repeatedly make a request to https://api.bitbucket.org/2.0/repositories/tutorials/tutorials.bitbucket.org/issues/<ID>, where ID ranges from 1 to however many issues you have.

Once you have the existing issue details you'll need to write some code to parse the JSON and then use the information provided by BitBucket to make a request to GitHub's API to create the new issue.

You can read up on GitHub's API at https://developer.github.com/v3/issues/#create-an-issue. Basically for this you'll make a POST request to https://api.github.com/repos/<repo-owner-username>/<repo-name>/issues and provide the necessary parameters along with the request. Exactly how you do this will depend on the library you use to make the request. Using CURL the request might look like curl -H "Content-Type: application/json" -X POST -d '{"title":"Found an issue","body":"I'm having a problem with this."}' https://api.github.com/repos/behzad-khosravifar/myRepo/issues.

So putting it all together the pseudocode might look something like:

for (id = 1 to 100)
    issueRawData = http_get('https://api.bitbucket.org/2.0/repositories/<owner>/<repo>/issues/'+id)
    issueJson = JSON.parse(issueRawData);
    postData = { "title" : issue.title, "body" : issue.content.raw }
    http_post('https://api.github.com/repos/<repo-owner-username>/<repo-name>/issues/'+id, postData)
}

Extra & Gotchas

  • Iterating over all the issues will mean you're creating issues in GitHub based on issues that have been closed in BitBucket. You can check the 'state' field returned from BitBucket to conditionally create the issue in GitHub. Alternatively create the issue anyway and then use GitHub's API to close the issue after its' been created.
  • You'll need to authenticate with GitHub (and possibly BitBucket). https://developer.github.com/v3/auth/ gives details on how to provide auth details when creating the issues in GitHub.