Hello again, this is Hiroki (@kompiro) from Astah development team. In my last post, I introduced several tools that we use to develop Astah.
How we use Jenkins, Trello, Raspberry Pi, etc. to build our Product, Astah
Do you use Hubot in your team? Hubot is an excellent robot which can automatically help solving impediments and moving tasks along automatically in the project. For instance, by using Hubot in the chat room, he will carry on the following tasks:
- Reminds us when it’s time for a daily standup or retrospective meeting
- Asks Jenkins for building and uploading new builds (ChatOps)
- Gives us a link of ticket if any ticket number is mentioned on the chat
- Update the ticket status of GitHub to Trello…etc.
Didn’t get the last one,
Update the ticket status of GitHub to Trello..? This is one of the usages of Hubot in our team.
Do you want to know how Hubot can be a hub of each service, work between them to run your projects effectively?
robot#respond() & robot#hear()
There are two commands to ask Hubot for run. One is
"robot#respond()" and another is
"robot#respond()" is something you set the command in advance and by calling Hubot like below, Hubot will make an action accordingly.
Hubot> hubot ping PONG
In this sample code, Hubot receives the
"ping" command and returns
"robot#hear()" which lets Hubot monitor all the messages on the chat and makes actions when he catches certain messages.
There was something that bugged me often which is when people talk about issues just with the ticket number – which leaves the rest of the team who are not familiar with the ticket not knowing what they are talking about. At least I did not want to make that happen on the chat. So this is what I did with Hubot.
On chat, Kamura told Yuri that her fix of #6257 was good. Right after that, Hubot mentions the URL of the ticket and the summary of it (the title of ticket) so that others can know which issue they are talking about without trying to find them by themselves. The Hubot’s action is made by the command below.
robot.hear /trac \#(\d+)(?=[^\w]|$)/ig, fetchTicket
First parameter is the regular expression of the condition of the monitoring, the second is the function that implements the operation. (Here’s the code if you are interested.)
Service integration by using robot.hear
Hubot monitors every single message posted on chat. So I thought that I can let Hubot make actions automatically based on the messages that are coming from other service. For example, when a Pull request is made on GitHub, a message appears on the chat automatically. So what I wanted was to update the review status of the pull-requested-ticket onto the cards on Trello (the Kanban board we used in our project) when Hubot sees the message on chat. This is the Sequence diagram of my idea.
To be strict, the messages between Idobata and Hubot are more complicated, but this is just a rough one for now. (The flow between GitHub and Idobata can be made by Webhook in each repository or Organization level too.)
The idobata outputs the message below in the chat room when it receives a change of ticket label from Github.
which consists of below:
"Username" labeled "label name" to "target PR(Pull Request) info" "issue title"
When we make a pull request on Github, we always put ticket number in its title like “#6131 xxxxx (title)”. (Ticket number I say here is Trac’s ticket number. We use several repositories for developing Astah and we manage all the entire backlogs in Trac.)
So in this example, “
refs #6131” is the ticket number and Hubot can get Github issue number by using regular expression. This is very simplified, but this regular expression,
/.*\s+labeled (\w+).*#(\d+).*/i can match
Target Pull Request info for the 1st and
ticket number for the 2nd. When we create Trello cards, we always put ticket number and ticket’s title, so that Hubot can identify related Trello card by ticket number and move the card to the “labeled” status on the Trello automatically.
Here’s the sample code:
robot.hear /.*\s+labeled (\w+).*#(\d+).*/i,(msg)-> label = msg.match ticket_id = msg.match trello.get_board target_board_name,(err,board)-> if err throw err trello.get_list board, label.capitalize(), (err,list)-> if err throw err trello.get_cards_on_board board, (err,cards)-> for card in cards re = /#(\d+).*/i match = card.name.match(re) if match card_id = match if card_id == ticket_id trello.move_card card, list, (err)-> if err throw err
Java is my main language so I don’t really know how to write clean coffeescript. (Should I use Promise instead of using callbacks….?)
So this was an introduction how we use Hubot as a hub of each service and run between them automatically. In my next blog, I will write about the development process of Astah!