Created
May 5, 2012 02:41
-
-
Save JaviSoto/2599214 to your computer and use it in GitHub Desktop.
Python script to create a task on Jira (You can use this with Alfred)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import webbrowser as wb | |
import simplejson as json | |
from restkit import Resource, BasicAuth, request | |
def createTask(server_base_url, user, password, project, task_summary): | |
auth = BasicAuth(user, password) | |
resource_name = "issue" | |
complete_url = "%s/rest/api/latest/%s/" % (server_base_url, resource_name) | |
resource = Resource(complete_url, filters=[auth]) | |
try: | |
data = { | |
"fields": { | |
"project": { | |
"key": project | |
}, | |
"summary": task_summary, | |
"issuetype": { | |
"name": "Task" | |
} | |
} | |
} | |
response = resource.post(headers = {'Content-Type' : 'application/json'}, payload=json.dumps(data)) | |
except Exception, ex: | |
print "EXCEPTION: %s " % ex.msg | |
return None | |
if response.status_int / 100 != 2: | |
print "ERROR: status %s" % response.status_int | |
return None | |
issue = json.loads(response.body_string()) | |
return issue | |
if __name__ == '__main__': | |
if (len(sys.argv) != 3): | |
print "Usage: %s project task_summary" % sys.argv[0] | |
sys.exit(1); | |
server_url = 'https://<jirasubdomain>.atlassian.net' | |
username = "<username>" | |
password = "<password>" | |
project = sys.argv[1] | |
task_summary = sys.argv[2] | |
issue = createTask(server_url, username, password, project, task_summary) | |
issue_code = issue["key"] | |
issue_url = "%s/browse/%s" % (server_url, issue_code) | |
if (issue != None): | |
print issue | |
wb.open(issue_url) | |
else: | |
sys.exit(2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# You should point Alfred to run this script like this: /Path/To/Script/newJiraTask.sh {query} | |
i=0 | |
task="" | |
for parameter in $@; do | |
if [ $i -eq 0 ]; then | |
projectName=$parameter | |
else | |
task="$task $parameter" | |
fi | |
let i++ | |
done | |
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
python $DIR/newJiraTask.py $projectName "$task" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
simplejson==2.5.0 | |
restkit==4.1.2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is it possible to create test run using python on JIRA-KANOAH. Also attach files to a test result. Please share some example which deals with python and KANOAH