Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,558,746
Community Members
 
Community Events
184
Community Groups

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

Edited
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