RocketChat / Rocket.Chat

The communications platform that puts data protection first.
https://rocket.chat/
Other
40.66k stars 10.66k forks source link

Jira support #637

Closed dennis-f closed 6 years ago

dennis-f commented 9 years ago

i'd love to see Atlassin Jira integration

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

nwsheppard commented 9 years ago

+1

Sing-Li commented 9 years ago

@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.

nwsheppard commented 9 years ago

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

Sing-Li commented 9 years ago

@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.

nwsheppard commented 9 years ago

@Sing-Li - Thanks.

gabriellezbautista commented 9 years ago

Raised hand (for someone who knows JIRA)

marceloschmidt commented 9 years ago

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

gabriellezbautista commented 9 years ago

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

gabriellebautista commented 9 years ago

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.

Againstreality commented 8 years ago

Anything new on this Topic?

Againstreality commented 8 years ago

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.

chkal commented 8 years ago

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)

knvpk commented 8 years ago

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.

chkal commented 8 years ago

@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?

knvpk commented 8 years ago

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

chkal commented 8 years ago

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.

Sing-Li commented 8 years ago

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 .

engelgabriel commented 8 years ago

Depends on #2426

thabbs commented 8 years ago

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.

engelgabriel commented 8 years ago

Please see initial documentation at https://github.com/RocketChat/Rocket.Chat/wiki/WebHook-Scripting---GitHub

Againstreality commented 8 years ago

has anybody a working script?

manuelbachl commented 8 years ago

gonna work on it after finishing BitBucket script

denen99 commented 8 years ago

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

manuelbachl commented 8 years ago

@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 ;-)

engelgabriel commented 8 years ago

What problem are you having @manuelbachl ?

manuelbachl commented 8 years ago

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 ;-)

engelgabriel commented 8 years ago

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

manuelbachl commented 8 years ago

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

denen99 commented 8 years ago

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

manuelbachl commented 8 years ago

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

rodrigok commented 8 years ago

We are trying to create our first MarketPlace version this week

manuelbachl commented 8 years ago

@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:

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.

manuelbachl commented 8 years ago

https://confluence.atlassian.com/bitbucketserver/draft-using-repository-hooks-776639841.html down at the bottom, there is an interesting part...

I'm not sure, wether this could be the solution: https://developer.atlassian.com/bitbucket/server/docs/latest/how-tos/repo-hook-examples/async-post-receive-config.html

denen99 commented 8 years ago

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

manuelbachl commented 8 years ago

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.

Againstreality commented 8 years ago

anything new on this Topic?

manuelbachl commented 8 years ago

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

Angl0r commented 8 years ago

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

manuelbachl commented 8 years ago

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

AirCombat commented 8 years ago

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

lkraider commented 8 years ago

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]
      }
    };
  }
}
Angl0r commented 8 years ago

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

manuelbachl commented 8 years ago

@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?

Angl0r commented 8 years ago

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 :)

konsumate commented 8 years ago

Make sure to include version/feature compatibility checks

Againstreality commented 8 years ago

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

lkraider commented 8 years ago

@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.

lkraider commented 8 years ago

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.

lkraider commented 8 years ago

@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.

davison commented 8 years ago

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