import logging
from jira import JIRA
def get_issue_from_jira(issue_id):
jira_url = "http://10.XX.XX.XX:8090"
api_token = "XXXXXXXXXXXXXXXXX"
try:
# https://jira.readthedocs.io/examples.html#jira-self-hosted-incl-jira-server-data-center
jira = JIRA(jira_url, token_auth=api_token)
if not issue_id:
return {"error": "Issue ID is required."}
# https://jira.readthedocs.io/api.html#jira.client.JIRA.issue
issue = jira.issue(issue_id)
if issue:
print(f"Issue details for {issue.key}:")
print(f"Summary: {issue.fields.summary}")
print(f"Description: {issue.fields.description}")
print(f"Status: {issue.fields.status.name}")
print(f"Type: {issue.fields.issuetype.name}")
else:
return {"error": f"Issue {issue_id} not found."}
except Exception as e:
logging.error(f"An error occurred: {e}")
return {"error": str(e)}
if __name__ == "__main__":
get_issue_from_jira(issue_id="TEST-3")
网友评论