Is it possible to use the python-jira to create an issue with a code snippet?

Filip Panovski
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 19, 2023

Hello! I'm writing a simple script to automatically create an issue when something in our codebase occurs and show a small diff of the relevant files.

I would like to include a code block in the created issue for formatting reasons.

I've tried this so far (excerpt/code snippet):

issue_description = f"""
There has been a change in branch {repo.active_branch.name}.

The following is a list of changes:
* File modifications:
```
{modifications_content if modifications else 'None'}
```
* File additions:
```
{additions_content if additions else 'None'}
```
* File deletions:
```
{deletions_content if deletions else 'None'}
```
"""
jira_token = '...'
jira = JIRA('https://.../', basic_auth=('...', jira_token))
jira.create_issue(project='KEY', summary=f'Change for {date.today()}',
description=issue_description, issuetype={'name': 'Task'})  

 However this does not insert a code block and instead interprets the backticks literally. I've already looked extensively through the documentation, but haven't seen this functionality mentioned at all.

Is it possible to do this using python-jira? 

Note: I've found this question that is asking the same thing using the REST API, but I would very much prefer it if I could stick to the python library and not needing to dig a level deeper.

1 answer

1 accepted

2 votes
Answer accepted
Filip Panovski
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 19, 2023

Hold the phone! 

It seems I was a bit too hasty. The triple backticks seem to only be a convenience, and the actual code snippet macro is `{code}`. So, using:

  * File modifications:
{{code}}
{modifications_content if modifications else 'None'}
{{code}}

achieves the desired effect (note that I'm using an f-string above, hence the need to escape the curly braces).

I'll leave this question up in case it might help someone else out.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events