Rocket.chat: Jira support

Created on 31 Aug 2015  Â·  62Comments  Â·  Source: RocketChat/Rocket.Chat

i'd love to see Atlassin Jira integration

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Request integration / plugin

Most helpful comment

not yet, but maybe this weekend I'll dive into this. I'll keep you updated

All 62 comments

+1

@dennis-f , @nwsheppard - There is no Jira expertise in the current team. Can you please see if any Jira community members may be able to help out? There is no need to understand the Rocket.Chat code, they just need to contribute a 'hubot' adapter over in the Rocket.Chat Chat Ops Edition project. Thanks.

@Sing-Li - How is the Rocket.Chat Chat Ops Edition different from the hubot-rocketchat integration?

@nwsheppard It is 100% hubot / hubot-rocketchat powered! It will have ALL the features of the core Rocket.Chat plus it will have some dedicated user interface that is specific to the bot(s) that is(are) integrated. Essentially turning a chat into a chat-app. And it will be, by design, massively scalable. BTW ... it is post 1.0 - just starting up there.

Before that is ready, the very same hubot that you create will be compatible - and can be used - with the current core Rocket.Chat.

@Sing-Li - Thanks.

Raised hand (for someone who knows JIRA)

Awesome! @gabriellezbautista would you be interested in checking out Rocket.Chat.Ops and do for JIRA something like we did for GitHub?

I'm looking at it right now :+1: I'll try to put some time to it.

Upon searching npm registry, I found this https://github.com/ndaversa/hubot-jira-bot. Maybe we can hookup with the developer and see if we can re-use it.

Anything new on this Topic?

Maybe the easiest way would be to use the Jira Webhooks (https://developer.atlassian.com/jiradev/jira-apis/webhooks) and make a Mapper from Jira Json to RC Json.

I also think that using the native JIRA WebHooks may be a good option. The only thing missing here is some way to translate application specific hook payloads (JIRA in this case) into something Rocket.Chat understands. I could imagine that if there is some API support for such transformations in Rocket.Chat, adding integrations for all kind of services would be easy (see #638 and others)

Rather than providing API by rocket chat or JIRA to transform data, i think it is nice to have hubot script that will transform the data from any source lets say gitlab or jira to a format that is understand by the Rocket chat.

@pavankumarkatakam Sure, that would work. But it looks like the rocketchat hubot doesn't provide the full feature set of the web hooks. Especially it doesn't allow to change the display name and the avatar for individual integrations. Or am I missing something here?

@chkal , yes you are right. hubot is not usefull in this scenario.

So I wonder what the primary way of integrating which 3rd party application should be in the long run.

Of cause hubot will work in most cases (and with existing hubot plugins + the hubot-rocketchat) adapter. But I think this way of integrating doesn't allow the level of flexibility that users want. Like having different avatars/usernames for each system which is integrated. That's something that Slack brings out of the box.

Actually, that has very little to do with the means of integration.

There has been talks on giving "system bot users" privilege to create new 'powerless' alien-system users (complete with avatar), and once that's in place - what you mentioned will be possible.

The very same 'feature' is needed in many other scenarios - including better federation support.

Didn't look like there is an existing issue - added #2349 .

Depends on #2426

Please, the Jira web hook is a really perfect starting point. You just have to parse the JSON which rocketchat is receiving from the hook. That's all.

has anybody a working script?

gonna work on it after finishing BitBucket script

@manuelbachl let me know if you have a working repo, would like to contribute to this one

@denen99, I haven't started this yet. Have some trouble getting my hook working for Bitbucket. Once this problem is solved, I'll finish the BitBucket integration. I Think much code of this integration can be reused for JIRA. But I'll let you know once I'm starting ;-)

What problem are you having @manuelbachl ?

the probelm is, that I can't receive the payload from Bitbucket. Have been working on this with @rodrigok an this last friday. But we should meet again in chat for fixing this. Using the same hook, rodrigok reveived the payload. It seems, that there is any issue with our R.C setup.
I'm at home in about 1 and a half hour - maybe he's in then, so we could move on working on the integrations ;-)

@rodrigok will be here in the office in 1 hour too. Let's get that fixed.

thanks to @rodrigok our hook works for now. I'll do the integration tomorrow and will paste the link to the repo here

Should there be a "webhooks" repo under RocketChat org where we can keep all the contributed webhooks ?

there are plans for building a "marketplace" - as website and even inApp, but it's a little bit too early to talk about further details :-D But be sure, you'll all be informed as soon as it's working ;-)
Since then, have a look at the Wiki https://github.com/RocketChat/Rocket.Chat/wiki#technical-guides - there some integrations will be mentioned

We are trying to create our first MarketPlace version this week

@denen99 I've got the Bitbucket Server integration up and running. But I've recognized just at this moment, that there is only a possibility to receive updates on repositories. The POST receive webhooks from bitbucket server just send on receiving pushes. As far as I could figure out, there is an other behavior for Bitbucket Cloud, there you could also receive pull requests a.s.o...

Because of this, I'll split up the integration and will buld two different Scripts:

  • one for Bitbucket Cloud (I'll wkeep working on this right now)
  • one for Bitbucket Server

last one is quite done for now. If we want to receive more messages, I would need help on building an Bitbucket Server Plugin which provides a pull request webhook (and maybe others). I've no idea on how to create Atlassian Plugins, so I would love to see any contributors building the needed webhook.

thanks @manuelbachl i thought we were talking about JIRA, not BitBucket though ?

yes @denen99 you're totally right, but as stated before, I just wanted to finish the BB integration because I've already been working on this when I found this issue.

anything new on this Topic?

not yet, but maybe this weekend I'll dive into this. I'll keep you updated

I hope this topic is still activ, i loved to see jira integration in Rocket.Chat

It is, just need to renew JIRA plan, then I'm getting back on this

This would be a major selling point in convincing the rest of the team to go for rolling this out to the rest of the company

Here's a script I created to parse the Jira webhook JSON in a manner similar to what the Slack integration service does:

class Script {
  process_incoming_request({ request }) {
    if (!(request["content"] && request.content["webhookEvent"])) {
      return {
        error: {
          success: false,
          message: 'Unsupported request'
        }
      };
    }
    const ref_url = request.content.issue.self;
    const url_parts = /^(\w+\:\/\/)?([^\/]+)(.*)$/.exec(ref_url);
    const url_origin = url_parts[1] + url_parts[2];
    const user_login = request.content.user.name;
    const user_name = request.content.user.displayName;
    const avatar_url = request.content.user.avatarUrls["16x16"];
    const issue_type = request.content.issue.fields.issuetype.name;
    const issue_icon = request.content.issue.fields.issuetype.iconUrl;
    const issue_number = request.content.issue.key;
    const issue_title = request.content.issue.fields.summary;
    const issue_url = url_origin + '/browse/' + issue_number;
    const issue_link = '[' + issue_number + '](' + issue_url + ')';
    let text = user_name;
    let emoji = '';
    switch (request.content.webhookEvent) {
      case 'jira:issue_created':
        emoji = ':triangular_flag_on_post: ';
        text += ' created ' + issue_type + ' ' + issue_link;
        break;
      case 'jira:issue_updated':
        emoji = '';
        text += ' changed ' + issue_type + ' ' + issue_link;
        const actions = {
          'jira:resolution': function(item, items) {
            emoji = item.to === null ? ':triangular_flag_on_post: ' : ':white_check_mark: ';
            item = items['jira:status'];
            return ' from "' + item.fromString + '" to "' + item.toString + '"';
          }
        }
        let items = request.content.changelog.items;
        let actions_items = {};
        for (let i = 0; i < items.length; ++i) {
          let item = items[i];
          let action = item.fieldtype + ':' + item.field;
          actions_items[action] = item;
        }
        let result;
        for (let action in actions_items) {
          let item = actions_items[action];
          if (actions[action]) {
            result = actions[action](item, actions_items);
            text += result;
            break;
          }
        }
        if (result === undefined) {
          return {
            error: {
              success: false,
              message: 'Unsupported action'
            }
          };
        }
        break;
      default:
        return {
          error: {
            success: false,
            message: 'Unsupported event'
          }
        };
    }
    const attachment = {
      author_icon: issue_icon,
      author_name: issue_title,
      author_link: issue_url,
      fields: []
    };
    if (request.content.issue.fields.assignee) {
      attachment.fields.push({
        title: 'Assignee',
        value: request.content.issue.fields.assignee.displayName,
        short: true
      });
    }
    if (request.content.issue.fields.creator) {
      attachment.fields.push({
        title: 'Creator',
        value: request.content.issue.fields.creator.displayName,
        short: true
      });
    }
    // attachment.fields.push({
    //   title: 'Request',
    //   value: JSON.stringify(request.content),
    //   short: false
    // });
    return {
      content: {
        icon_url: avatar_url,
        alias: user_login,
        text: emoji + text,
        attachments: [attachment]
      }
    };
  }
}

This Script Works fine!!! But it seems that Rocket.Chat ignores the Alias and the avatar of the bot. It keeps posting it under my credentials. Thank you for this nice script

@lkraider is this script parsing all possible payloads from JIRA? In other words, is it complete? If not, I'll start working on this intergration on monday, may I use your Script as a base?

After a littlebit of Scripting i finaly managed to overwrite the credentials under wich the bot posts your Jira Tickets. You need to modify the following entrys:

  1. user_login -> I changed it to 'JiraBot'
  2. avatar_url -> I changed it to 'some_url_of_a_pic'

Notice that the Name and the Url must be written in apostrophe (' ')

With these changes the Webhook bot has a diffrent name and avatar :)

Make sure to include version/feature compatibility checks

The Script from @lkraider together with the mdoifikation from @Angl0r work fine for a start-

@manuelbachl The script is a start, I tried to replicate what Slack provides for Jira Issue updates. This could definitely be expanded to have all types of events handled and maybe have some form of configuration options.

Here are some anonymized Jira webhook JSON data so people can identify other fields to extract:
https://gist.github.com/lkraider/c0eccf6677ce5372e5528dba7274763d

They are the output for issue updates only, including Resolved, Reopened, Worklog and Assignee change.

@Angl0r You can remove icon_url and alias from the content, like this:

return {
      content: {
        text: emoji + text,
        attachments: [attachment]
      }
    };

This will make the message use the Bot details configured in the Rocket integration webhook settings.

with the script above (including lkraider's modification to the return content) I get the following error in the chat server logs:

20160426-14:11:57.612(1) rocketchat_integrations api.coffee:165 Integrations âž” Incoming WebHook.error function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var Script = (function () { function Script() { _classCallCheck(this, Script); } Script.prototype.process_incoming_request = function process_incoming_request(_ref) { ...

There are no docs (that I can find) explaining how scripts are supposed to work.. has something changed in a recent version perhaps? I'm using 0.27

yes, those integrations mentioned by @lkraider are just examples. But those are quite easy to expand to full functionality if the payloads are documented good enough. We switched from Jira and Bitbucket to Gitlab a few days agow and also want to have the full integration. So if no1 is faster than us, Gitlab will be the next Integration right after completing JIRA which is already in progress ;-)

strange, I simplified the script down to a hardcoded returned content block and still got the same error, then it suddenly started working, then after re-instating the original script it worked. Do scripts get cached quite aggressively maybe? Whatever, it seems to be OK for now, so thanks for the efforts on this - looks like it will be really useful for us. :)

If anyone's interested, I've created a JIRA integration that responds with a summary of a JIRA issue whenever it's mentioned.
You can configure some stuff such as what fields should be posted and there's an "extended" mode that shows more details if you append + to the issue.

Feel free to try it out and provide any feedback/help you can.
https://github.com/gustavkarlsson/rocketchat-jira-trigger

@gustavkarlsson Do you intend to extend this integration to incoming i.e. connecting a given JIRA project to a RocketChat room?

Also a question for everyone involved, is there a desire to get this integrated in some way, or do we think we'll all be rolling our own for the foreseeable future? :)

@antgel No plans for that. This is for outgoing messages only.

Due the Snap installation will create a read-only directory the Jira Webhook script runs into problems. Not sure if this also causes some problems with other Integrations.

https://github.com/malko/rocketchat-jira-hook/issues/1

I found this integration Rocket.chat -> Jira - https://hub.docker.com/r/gustavkarlsson/rocketchat-jira-trigger/ based on Java. It is use Outgoing webhook.

Or you can try this integration Jira -> Rocket.chat - https://blog.zemna.net/web/how-to-integrate-jira-and-bitbucket-application-with-rocket-chat/ based on Incoming webhook.

Or you can try this integration Jira -> Rocket.chat - https://blog.zemna.net/web/how-to-integrate-jira-and-bitbucket-application-with-rocket-chat/ based on Incoming webhook.

I tried, jira received a 400 response...

Sorry not sure what the status of this is, but just going to quickly pop some stuff here.

There isnt any work as far as i am aware that needs to be done on this.

The current integration script utilising the incoming webhooks with JIRA posting to it work perfect and can be customised to your liking. This is what our 'helpdesk feed' looks like in Rocket.Chat:

screen shot 2017-06-19 at 4 45 30 pm

The incoming intergration is done with this gist here

https://gist.github.com/malko/7b46696aa92d07736cc8ea9ed4041c68

To interact with JIRA you can use some great hubot plugins that are around

https://www.npmjs.com/search?q=hubot+jira

This can be done with the internal/built in Rocket.Chat hubot or your own instance.

This is the one I use https://www.npmjs.com/package/hubot-jira-bot

We use it to search for JIRA tickets, open them, transition them thru different states, comment on them, rank them up or down, start or stop watching them or change who is assigned to a ticket.

@JSzaszvari I'd like to close this as I've been doing with other bot suggestions and you've done to a few too, because they're out of scope. But this one seems to have a lot of history. If you think it's OK to handle from here as part of the collection of proposals for discussion / voting under #10174, please go ahead and close.

@rocket-cat close

@timkinnane 100% agree. This is already handled with incoming integrations, existing Hubot functionality and when released Rocket.Chat Apps will allow a much more intergrated if needed.

I'm saying that, I'll now close this issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zeigerpuppy picture zeigerpuppy  Â·  3Comments

neha1deshmukh picture neha1deshmukh  Â·  3Comments

marceloschmidt picture marceloschmidt  Â·  3Comments

Buzzele picture Buzzele  Â·  3Comments

lunitic picture lunitic  Â·  3Comments