taiga-back icon indicating copy to clipboard operation
taiga-back copied to clipboard

Bug: Github integration will be failed after installing slack at taigaio/taiga-contrib-slack

Open simmytruong opened this issue 7 years ago • 5 comments

Hi,

I recently installed taiga from taiga-scripts repo. My server has been functioning well.

I setup github integration by using the web GUI, and my server can receive webhook json from github without any issue. For example, If I commit like "Test by me for TG-1" and then, I can see this comment and commit link from github under my ticket (REF = 1).

After that, I installed slack as the guideline here. I can see, my taiga server is able to send notifications to slack.

BUT....... The issue happen! After installed taiga-contrib-slack plugin, my taiga server is unable to receive github commit anymore (but it is interesting that I can change ticket status from github, for example: TG-1 #ready), my comment that worked before such as "Test by me for TG-1" will not link to my ticket anymore. And under nginx logs, I can see code 500 returned and gunicorn said Index Group not found or something like that.

So, I would like to have an advice how to figure out the issue. Seems that after install this slack plugin, my github is crashed

Thanks, Simmy

simmytruong avatar May 14 '18 11:05 simmytruong

It seems we have the same problem here. I could track it down to an error which happens inside the slack plugin code when the github event is being processed:

ERROR:2018-11-14 15:31:29,844: Internal Server Error: /api/v1/github-hook
Traceback (most recent call last):
  File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/core/handlers/base.py", line 249, in _legacy_get_response
    response = self._get_response(request)
  File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/core/handlers/base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/core/handlers/base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/taiga/taiga-back/taiga/base/api/viewsets.py", line 106, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
    return view_func(*args, **kwargs)
  File "/home/taiga/taiga-back/taiga/base/api/views.py", line 460, in dispatch
    response = self.handle_exception(exc)
  File "/home/taiga/taiga-back/taiga/base/api/views.py", line 458, in dispatch
    response = handler(request, *args, **kwargs)
  File "/home/taiga/taiga-back/taiga/hooks/api.py", line 79, in create
    event_hook.process_event()
  File "/home/taiga/taiga-back/taiga/hooks/event_hooks.py", line 264, in process_event
    user=self.get_user(commit['user_id'], self.platform_slug))
  File "/usr/lib/python3.4/contextlib.py", line 30, in inner
    return func(*args, **kwds)
  File "/home/taiga/taiga-back/taiga/projects/history/services.py", line 422, in take_snapshot
    return entry_model.objects.create(**kwargs)
  File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/db/models/query.py", line 394, in create
    obj.save(force_insert=True, using=self.db)
  File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/db/models/base.py", line 806, in save
    force_update=force_update, update_fields=update_fields)
  File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/db/models/base.py", line 846, in save_base
    update_fields=update_fields, raw=raw, using=using,
  File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/dispatch/dispatcher.py", line 193, in send
    for receiver in self._live_receivers(sender)
  File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/dispatch/dispatcher.py", line 193, in <listcomp>
    for receiver in self._live_receivers(sender)
  File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/taiga_contrib_slack/signal_handlers.py", line 89, in on_new_history_entry
    task(*args)
  File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/celery/local.py", line 191, in __call__
    return self._get_current_object()(*a, **kw)
  File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/celery/app/task.py", line 379, in __call__
    return self.run(*args, **kwargs)
  File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/taiga_contrib_slack/tasks.py", line 239, in change_slackhook
    comment = re.sub(LINK_RE, _link_transform, change.comment)
  File "/home/taiga/.virtualenvs/taiga/lib/python3.4/re.py", line 175, in sub
    return _compile(pattern, flags).sub(repl, string, count)
  File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/taiga_contrib_slack/tasks.py", line 220, in _link_transform
    url_split = match.group(8).split()
IndexError: no such group

I am fairly fresh with the taiga code but will try to find a fix asap... help is appreciated though!

oderwat avatar Nov 14 '18 15:11 oderwat

From what I understand the problem is that the github comment which is generated is generating an exception by the slack plugin. It seems like the regular expression LINK_RE is generating a match but match.lastindex is none.

I digged a bit deeper and found LINK_RE to apply to ' and " and as usually: Regular expressions are evil. The github integration uses ' inside the " part of the link :)

I removed the LINK_RE import and added my own LINK_RE just above it's usage in change_slackhook()

It looks like this:

@app.task
def change_slackhook(url, channel, notify_config, obj, change):
    obj_type = _get_type(obj)

    if not _check_notify_permission(notify_config, obj_type, 'change'):
        return

    template_change = loader.get_template('taiga_contrib_slack/change.jinja')
    NOBRACKET = r'[^\]\[]*'
    NOIMG = r'(?<!\!)'
    BRK = ( r'\[('
            + (NOBRACKET + r'(\[')*6
            + (NOBRACKET+ r'\])*')*6
            + NOBRACKET + r')\]' )
    LINK_RE = NOIMG + BRK + \
    r'''\(\s*(<.*?>|((?:(?:\(.*?\))|[^\(\)]))*?)\s*((["])(.*?)\12\s*)?\)'''
    comment = re.sub(LINK_RE, _link_transform, change.comment)
    context = Context({"obj": obj, "obj_type": obj_type, "change": change, "comment": comment})

    change_text = template_change.render(context.flatten())

I may create a PR for the slack plugin later. I also don't like how it formats some stuff and even may create my own version of it eventually.

Hopefully this already helps some people to get Taiga running with Github and Slack integrations at the same time.

oderwat avatar Nov 14 '18 16:11 oderwat

Obviously this problem is fixed in the current python markdown module: https://github.com/Python-Markdown/markdown/blob/master/markdown/inlinepatterns.py which should really be used instead of hacking into it's patterns.

oderwat avatar Nov 14 '18 16:11 oderwat

thanks for your update @oderwat

Even if I gave up to install slack-intergration plugin. I tried to pass this issue by writing my own webhook when having any trigger. And my webhook (Python) will receive trigger from taiga, and then parse it and send to slack then.

simmytruong avatar Nov 15 '18 02:11 simmytruong

@simmytruong I plan something similar which also should collect updates for some time to bundle the notifications. Maybe we can join forces on that! BTW: Using a webhook may also solve the problem that the current plugin runs synchronously which introduces long delays and even timeouts in Taiga when the Slack Service is slow! We had to disable the Slack Plugin for that reason alone after me fixing it to "work" with GitHub. By now we also removed the GitHub integration, because it generates comments which is not what I want to have... I would prefer entries in the history only. Something else I am up to make possible in the future.

oderwat avatar Nov 22 '18 12:11 oderwat