Skip to content

Instantly share code, notes, and snippets.

@agea
Forked from tommorris/gist:2795214
Last active December 18, 2015 10:58
Show Gist options
  • Save agea/5771901 to your computer and use it in GitHub Desktop.
Save agea/5771901 to your computer and use it in GitHub Desktop.
import sys
import csv
import httplib, urllib, base64
def main():
# set the name of your repository, username and password
username = "test"
password = "test"
repo = "user/repo"
filename = sys.argv[1]
issues = [i for i in csv.reader(open(filename), delimiter=';')][-1:0:-1]
issues_out = []
for issue in issues:
issue_map = {
"title": issue[6].decode('iso-8859-1').encode('utf-8'),
"content": issue[17].decode('iso-8859-1').encode('utf-8')
}
if issue[4] == "Chiuso" or issue[4] == "Risolto":
issue_map["status"] = "resolved"
elif issue[4] == "Rifiutato":
issue_map["status"] = "wontfix"
elif issue[4] == "In elaborazione" or issue[4] == "Commenti":
issue_map["status"] = "open"
elif issue[4] == "Nuovo":
issue_map["status"] = "new"
if issue[2] == "Segnalazione":
issue_map["kind"] = "bug"
else:
issue_map["kind"] = "enhancement"
issues_out.append(issue_map)
for t in issues_out:
print t
#continue
base64string = base64.encodestring('%s:%s' % (username, password))[:-1]
conn = httplib.HTTPSConnection("api.bitbucket.org")
headers = {"Content-type": "application/x-www-form-urlencoded", "Authorization" : "Basic " + base64string}
url = "/1.0/repositories/%s/issues/" % (repo)
conn.request("POST", url, urllib.urlencode(t), headers)
response = conn.getresponse()
print response.status, response.reason
conn.close()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment