Sign in
agent:

Add these last 50 lines of console log as a comment in the Jira ticket we created earlier

There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.

This code adds the last 50 lines of the console log as a comment in the specified Jira ticket using the Jira API.

import json import requests from requests.auth import HTTPBasicAuth # Get environment variables JIRA_USER_NAME = getEnvVar('JIRA_USER_NAME') JIRA_API_KEY = getEnvVar('JIRA_API_KEY') JIRA_BASE_URL = getEnvVar('JIRA_BASE_URL') # Print input parameters print(f"Input Parameters:\nissue_url: {issue_url}\nlast_50_lines: {last_50_lines}") # Extract issue key from issue URL issue_key = issue_url.split('/')[-1] # Jira API URL to add a comment to the issue url = f"{JIRA_BASE_URL}/rest/api/3/issue/{issue_key}/comment" # Headers for authentication headers = { 'Content-Type': 'application/json', 'Accept': 'application/json' } # Format the console log in Atlassian Document Format console_log_adf = [{ "type": "paragraph", "content": [ { "type": "text", "text": line } ] } for line in last_50_lines.split('\n')] # Payload to add a comment payload = { "body": { "type": "doc", "version": 1, "content": console_log_adf } } # Make the request to Jira API to add the comment response = requests.post(url, headers=headers, auth=HTTPBasicAuth(JIRA_USER_NAME, JIRA_API_KEY), json=payload) if response.status_code == 201: comment_id = response.json()['id'] print(f"Output:\nComment added successfully with ID: {comment_id}") else: print(f"Failed to add comment. Status code: {response.status_code}")
copied