** Automation of JIRA ticket creation ** ** Create a mechanism that automatically creates JIRA tickets when you mention in Slack **
If you tweet the contents of the ticket by attaching a mention to the bot from slack as follows
Tickets are created in JIRA
Since I made such a mechanism, I will also write my own memo
Vagrant.configure(2) do |config|
config.vm.box = "bento/centos-6.7"
config.vm.define "dev" do |node|
node.vm.network "private_network", ip: "192.168.10.10"
node.vm.synced_folder "/Users/takahirono7/projects/", "/root/project"
end
end
Setting synced_folder is very convenient because you can sync directories on your local Mac and Vagrant. The method is summarized below Synchronize files between guest OS running on Vagrant and Mac
First you need to create a bot user that runs on Slack
Click "creating a new bot user" at the URL below to create a bot user https://api.slack.com/bot-users
For details, please refer to the following people who have summarized it wonderfully. Making Slackbot with Python (1)
After completing the account creation, the following article
Add functionality to bots
Please carry out to the point Create a Slack bot with Python's slackbot library
The pioneers have explained this area in detail, so I will not describe it. I really appreciate it.
Proceeding to the above part, I think that the directory structure is as follows. Below, the above article by sukesuke is quoted.
slackbot #A directory that organizes programs. Any name is fine
├─ run.py #Start the bot by running this program
├─ slackbot_settings.py #File to write settings related to bot
└─ plugins #Add bot functionality to this directory
├─ __init__.py #A file to indicate the module. Sky is fine
└─ my_mention.py #Features each file. Any name is fine
We will add a function to link to jira to my_mention.py.
The implementation used the python-jira library. I thought about implementing it with curl or urllib, but I think the python-jira library is the easiest. https://jira.readthedocs.io/en/master/
Add the following to my_mention.py
from jira import JIRA
from jira.client import JIRA
@listen_to('create_ticket')
def create_tickets(message):
options = {
'server': 'https://**jira domain**/jira'
}
body = message.body['te i xt']
jira = JIRA(options, basic_auth=('bot_test','bot_test'))
issue_dict = {
'project': {'key': 'TES'},
'summary': 'New issue from jira-python',
'description': body ,
'issuetype': {'name': 'task'}
}
new_issue = jira.create_issue(fields=issue_dict)
message.reply('Created a ticket')
#Get object in the following format
# [<JIRA Issue: key='TES-4644', id='59893'>]
last_ticket = jira.search_issues('project = "TES" AND reporter = bot_test ORDER BY createdDate DESC', maxResults = 1)
# last_ticket[0]so"TES-4659"などのticket keyが取得soきる
message.reply("https://JIRA domain/jira/projects/TES/issues/%s" %(last_ticket[0]))
jira = JIRA(options, basic_auth=('bot_test','bot_test'))
Add basic authentication information when instantiating JIRA. Don't forget to create a user on JIRA in advance
new_issue = jira.create_issue(fields=issue_dict)
You can create a ticket with the create_issue method. As an option, add project key, summary, description, and issue type information. Here, the content of the description is taken as the content of the slack message with body = message.body ['text'].
last_ticket = jira.search_issues('project = "TES" AND reporter = bot_test ORDER BY createdDate DESC', maxResults = 1)
# last_ticket[0]so"TES-4659"などのticket keyが取得soきる
message.reply("https://**jira domain**/jira/projects/TES/issues/%s" %(last_ticket[0]))
I'm searching for JIRA tickets with the jira.search_issues method. The ticket search results will be returned in the list, so set the key to [0] to get the ticket key. By adding the obtained key to the end of the URL of the jira domain, the URL of the ticket is obtained and returned.
With this kind of implementation, we were able to create tickets with slack as described at the beginning. I'm thinking of implementing more features around JIRA, so I'll post it when I have a story.
JIRA ticket with slack bot → Automation of Slack notification ~ slack bot development with python② ~
Automatically create JIRA tickets with slack bot ~ slack bot development with python ① ~ JIRA ticket with slack bot → Automation of Slack notification ~ slack bot development with python② ~ Notify slack when the switch sales page is updated ~ slack bot development with python ③ ~ Get the bot to tell you the weather (precipitation information) using the weather information API (YOLP) provided by Yahoo ~ slack bot development ④ ~ with python
Recommended Posts