Using the API to create a pulse with JIRA ticket details from a JIRA state change

Hi all,

This has been a real struggle to get done but with help from this community and others I’ve done it and wanted to share (plus ask for alternative/better methods).

Goal: Make creating release notes a less manual task
Environment: JIRA Cloud for day to day development workflow, Monday for housing release notes (among loads of other uses).
Constraints: JIRA not available to whole business (license costs) but Monday is.

Summary:
There is a JIRA integration but it didn’t quite do what i wanted. So, I set up a Post Function from JIRA that ran a ScriptRunner script (JIRA add on) to fire a Create_Item mutation, with Column_Values, on a particular board then updated that item using Create Update to add the JIRA ticket description as an pulse update (as i prefer this to adding a large amount of text to a column field).

Here’s my ScriptRunner script so someone else might find it useful:

import groovy.json.JsonSlurper

def apiToken = '<YOUR API TOKEN HERE>'
def slurper = new JsonSlurper()

def issueKey = issue.key
def issueSummary = issue.fields.summary
def issueType = issue.fields.issuetype
def issueDescription = issue.fields.description
def todaysDate = new Date().format( 'yyyy-MM-dd' )
def jiraURL = "<YOUR JIRA URL HERE>"



def msg1 = [
        query : 'mutation{create_item (board_id: <TARGET BOARD>,group_id:"<TARGET GROUP>",item_name: "' + issueSummary + '"' +
        ',column_values:"{'+
        '\\\"text1\\\":\\\"'+issueKey+'\\\"'+
        ',\\\"link\\\":{\\\"url\\\":\\\"'+ jiraURL + issueKey +'\\\",\\\"text\\\":\\\"'+issueKey+'\\\"}'+
        ',\\\"date\\\":{\\\"date\\\":\\\"'+todaysDate+'\\\"}'+
        '}") {id}}' 
]


HttpResponse<String> jsonResp = post('https://api.monday.com/v2')
        .header('Content-Type', 'application/json')
        .header('Authorization', "${apiToken}")
        .body(msg1)
        .asString()


def result = slurper.parseText(jsonResp.body)
Integer iid = result["data"]["create_item"]["id"] as Integer

def msg2 = [
        query : 'mutation{create_update (item_id: '+iid+', body: "'+issueDescription+'") {id}}' 
]

post('https://api.monday.com/v2')
        .header('Content-Type', 'application/json')
        .header('Authorization', "${apiToken}")
        .body(msg2)
        .asString()

So now, when a ticket moves into the appropriate state, a monday pulse is created with the core data and the description field in the JIRA ticket gets added.

I’m sure we will change this to make improvements but at the moment i’m just pleased it’s working!

I hope someone else finds this useful and if there’s any questions then i can go into more detail about the JIRA part. Or, if anyone has ideas to improve it then i’ll gladly take those too :slight_smile:

Cheers
Simon

2 Likes

Hey @simonWT :wave:

Thank you SO much for sharing this and I am sorry it took us so long to respond! An amazing effort like this definitely should be noticed :slight_smile:

I really appreciate you giving back to the community like this! I’ll also share this solution with our product team - perhaps we can work on implementing this kind of integration in our native Jira integrations.

-Alex

Hi Alex :wave:, thanks for the note, very kind of you :slight_smile:

If I make any drastic changes i’ll post the results (i can seem some result parsing inefficiency that i’ll tackle)

Cheers
Simon

1 Like

@simonWT

That’s awesome, thank you so much :slight_smile:

Have an awesome day.

-Alex

Hi @simonWT
Thanks for this script to create the connection between Jira and Monday.
I was tasked with updating the status of the JIRA ticket to monday along with the jira issue id and epic link. Tried using 3rd party tools but wasn’t working completely.

I am trying to run the script in JIRA however, I am getting an error below pointing to the jsonResp*
Can you also provide more information or if you have done any updates since to make this script run? Is there an import that I’m missing?

The script could not be compiled:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script123.groovy: 25: unable to resolve class HttpResponse
@ line 25, column 22.
HttpResponse jsonResp = post(‘https://api.monday.com/v2’)

For group_id, Monday does have data for board and item id. However I can’t find the group id, can you provide how you would find it?

Thanks!

Hi @mliang
My script is sitting in a Post Function on a transition and the only “import” i’ve had to add is the JSON one. Is yours in a PF too?

I can see you haven’t got the < String > type part so maybe try adding that in?

Cheers
S

Thank you, Simon. My business need is to copy/sync the comments between Jira issue and Monday.com item. Can you help me how to achieve this?