Commit Graph

815 Commits

Author SHA1 Message Date
Anders Kaseorg c734bbd95d python: Modernize legacy Python 2 syntax with pyupgrade.
Generated by `pyupgrade --py3-plus --keep-percent-format` on all our
Python code except `zthumbor` and `zulip-ec2-configure-interfaces`,
followed by manual indentation fixes.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-09 16:43:22 -07:00
Abhinav 41fc7b2ae1 webhooks/semaphore: Add support for Semaphore 2.0 notifications.
Semaphore has currently has two different versions of their product -
Classic and 2.0. This commit adds support for Semaphore 2.0, along side
Semaphore Classic, using the same webhook. This would let the integration
work seamlessly for users who have already configured a Zulip integration in
their Semaphore 2.0 projects.

Semaphore 2.0 currently only supports GitHub and their payloads do not
contain URLs for common entities like commits, pull requests and tags. We
construct URLs for them using templates, but also try to support other
services by providing notifications without URLs.

Closes #14171

Co-authored-by: Puneeth Chaganti <punchagan@muse-amuse.in>
2020-04-09 12:41:40 -07:00
Tim Abbott 0599273cfa bitbucket: Fix support for pushes that update a tag.
Previously, we threw an exception if created/closed were both unset;
apparently that can happen when pushing an update to a tag.
2020-04-07 17:00:20 -07:00
Stefan Weil d2fa058cc1
text: Fix some typos (most of them found and fixed by codespell).
Signed-off-by: Stefan Weil <sw@weilnetz.de>
2020-03-27 17:25:56 -07:00
Tim Abbott cb1fb94ac8 webhooks: Fix Jira webhook constructing subject still too early.
For event types that we don't yet support, like worklog_created (and
likely many more in the future), it doesn't make sense to call a
function that only parses issue events correctly.
2020-03-27 06:19:00 -07:00
Tim Abbott 9d346673f1 webhooks: Fix handling of additional old-format Jira events.
This should hopefully get the Jira webhook working correctly again for
all event types we handle.
2020-03-26 16:39:03 -07:00
Tim Abbott d52a891858 jira: Fix handling of sprint_started events.
Now that we inspect more attributes of events in determining subjects,
we need to filter events like sprint_started before fetching the subject.
2020-03-26 16:34:02 -07:00
Tim Abbott 6df86dab3e jira: Handle comment_created events without issue details.
I'm not sure what causes some Jira webhook events to not include the
metadata that other events do, but it's definitely a format sent by
real installations of Jira (likely a very old version, since this has
fields missing from what modern Jira does) and we've seen it in
production.

The best we can do is encourage users to upgrade Jira for better data.
2020-03-22 21:43:21 -07:00
Steve Howell 1306239c16 tests: Use email/delivery_email more explicitly.
We try to use the correct variation of `email`
or `delivery_email`, even though in some
databases they are the same.

(To find the differences, I temporarily hacked
populate_db to use different values for email
and delivery_email, and reduced email visibility
in the zulip realm to admins only.)

In places where we want the "normal" realm
behavior of showing emails (and having `email`
be the same as `delivery_email`), we use
the new `reset_emails_in_zulip_realm` helper.

A couple random things:

    - I fixed any error messages that were leaking
      the wrong email

    - a test that claimed to rely on the order
      of emails no longer does (we sort user_ids
      instead)

    - we now use user_ids in some place where we used
      to use emails

    - for IRC mirrors I just punted and used
      `reset_emails_in_zulip_realm` in most places

    - for MIT-related tests, I didn't fix email
      vs. delivery_email unless it was obvious

I also explicitly reset the realm to a "normal"
realm for a couple tests that I frankly just didn't
have the energy to debug.  (Also, we do want some
coverage on the normal case, even though it is
"easier" for tests to pass if you mix up `email`
and `delivery_email`.)

In particular, I just reset data for the analytics
and corporate tests.
2020-03-19 16:04:03 -07:00
Steve Howell c235333041 test performance: Pass in users to api_* helpers.
This reduces query counts in some cases, since
we no longer need to look up the user again. In
particular, it reduces some noise when we
count queries for O(N)-related tests.

The query count is usually reduced by 2 per
API call.  We no longer need to look up Realm
and UserProfile.  In most cases we are saving
these lookups for the whole tests, since we
usually already have the `user` objects for
other reasons.  In a few places we are simply
moving where that query happens within the
test.

In some places I shorten names like `test_user`
or `user_profile` to just be `user`.
2020-03-11 14:18:29 -07:00
Steve Howell 626ad0078d tests: Add uuid_get and uuid_post.
We want a clean codepath for the vast majority
of cases of using api_get/api_post, which now
uses email and which we'll soon convert to
accepting `user` as a parameter.

These apis that take two different types of
values for the same parameter make sweeps
like this kinda painful, and they're pretty
easy to avoid by extracting helpers to do
the actual common tasks.  So, for example,
here I still keep a common method to
actually encode the credentials (since
the whole encode/decode business is an
annoying detail that you don't want to fix
in two places):

    def encode_credentials(self, identifier: str, api_key: str) -> str:
        """
        identifier: Can be an email or a remote server uuid.
        """
        credentials = "%s:%s" % (identifier, api_key)
        return 'Basic ' + base64.b64encode(credentials.encode('utf-8')).decode('utf-8')

But then the rest of the code has two separate
codepaths.

And for the uuid functions, we no longer have
crufty references to realm.  (In fairness, realm
will also go away when we introduce users.)

For the `is_remote_server` helper, I just inlined
it, since it's now only needed in one place, and the
name didn't make total sense anyway, plus it wasn't
a super robust check.  In context, it's easier
just to use a comment now to say what we're doing:

    # If `role` doesn't look like an email, it might be a uuid.
    if settings.ZILENCER_ENABLED and role is not None and '@' not in role:
        # do stuff
2020-03-11 14:18:29 -07:00
Sourabh Singh 1b3cfecf2a
webhooks: Add team reviewers support in github webhook.
The github webhook implementation previously ignored the "team reviewers"
part of pull_request events, resulting in inaccurate output.

Fixes: #14096.
2020-03-10 16:29:59 -07:00
orientor 7d2bb707e7 integrations: Improved Taiga Integration.
This adds links to the users and other small improvements.

Progress towards #13698.
2020-03-04 16:52:52 -08:00
Chris Heald 18e3982acd integrations: Add AlertManager webhook. 2020-02-14 17:43:15 -08:00
Chris Heald a91358e186 webhooks: Fix hellosign webhook.
Hellosign now posts their callback as form/multipart, which Django only
permits to be read once. Attempts to access request.body after the
initial read throw "django.http.request.RawPostDataException: You
cannot access body after reading from request's data stream".

Fixes #13847.
2020-02-12 22:36:11 -08:00
Hemanth V. Alluri 7858e5ee40 webhooks/ansibletower: Update for AWX 9.1.1.
Add a simple compatibility function for AWX 9.x.x. Before AWX 9.x.x
a "friendly_name" key was sent by default. Afterwards it was removed
from being a default key but we can still more or less determine if
the triggering event was a job from the REST-style URL.

Note: It is also technically possible to add the key back by defining
a custom notification template in AWX/Tower.

Resolves #13295.
2020-02-02 20:21:03 -08:00
Mateusz Mandera 90bc2ad8ce webhooks: Fix typo in test_stream_error_pm_to_bot_owner comment. 2020-01-30 12:13:54 -08:00
Jonathan Cobb c7433c83ff integrations: Add errbit integration.
Fixes #13685.
2020-01-16 15:33:51 -08:00
Tim Abbott c10cc24ee8 python: Sort webhooks imports with isort. 2020-01-14 13:07:47 -08:00
shubhamgupta2956 92817e147d webhooks: Remove TrelloWebhookException classes.
This removes zerver/webhooks/trello/view/exceptions.py, which
contained legacy Trello webhook exception related classes.  We replace
them with UnexpectedWebhookEventType, which results in our standard
exception handling for unknown event types running (avoiding too-high
priority error logging).

Fixes #13467.
2020-01-07 18:02:40 -08:00
Tim Abbott 2e6e187c16 integrations: Deduplicate gogs and gitea integrations. 2019-11-18 12:08:09 -08:00
Jan Koscisz b88192d5bb integrations: Add Gitea integration.
Gitea integration adopted from Gogs integration with minor
adjusting. More events are now handled.

Fixes #13346
2019-11-18 11:55:24 -08:00
Jan Koscisz ace1503cb6 integrations: Add missing event handling to Gogs.
Issues event where not handled by Gogs integrations.
This added them to supported events.
2019-11-18 11:54:44 -08:00
Anders Kaseorg cafac83676 request: Tighten type checking on REQ.
Then, find and fix a predictable number of previous misuses.

With a small change by tabbott to preserve backwards compatibility for
sending `yes` for the `forged` field.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2019-11-13 12:35:55 -08:00
Jan Koscisz 12bd3c04c0 integration: Fix missing taiga test action.
Previously testing webhook from taiga site would result in error.
This adds missing 'test' action to taiga webhooks.

Fixes #13317.
2019-10-28 14:58:24 -07:00
chgl bea9e41fbd webhooks: Add Harbor webhook integration. 2019-10-21 15:51:35 -07:00
Mateusz Mandera bbf2474bd0 tests: setUp overrides should call super().setUp().
MigrationsTestCase is intentionally omitted from this, since migrations
tests are different in their nature and so whatever setUp()
ZulipTestCase may do in the future, MigrationsTestCase may not
necessarily want to replicate.
2019-10-19 17:27:01 -07:00
Rishi Gupta 3646936cfb integrations: Advertise our native Zapier integration. 2019-09-22 18:47:42 -07:00
Rishi Gupta 74d5d3db26 integration docs: Remove angle brackets from trello bash command.
If you accidentally leave them in, you'll get a confusing error message.
2019-09-19 17:48:16 -07:00
Puneeth Chaganti df134be235 webhooks/papertrail: Requests from Papertrail are not JSON requests.
Papertrail sends requests with the content type
`application/x-www-form-urlencoded`, with the payload parameter holding the
JSON body. This commit fixes the papertrail integration to use the payload
parameter in the request's POST data instead of trying to parse the
request's entire body as JSON.

Papertrail documentation here:
https://help.papertrailapp.com/kb/how-it-works/web-hooks#encoding
2019-09-04 13:16:17 -07:00
Rishi Gupta e1848e83bc integrations: Update instructions for AppFollow. 2019-08-22 13:17:06 -07:00
Hemanth V. Alluri 2e20dcc053 webhooks/jira: Update webhook to support improved comment events.
Atlassian announced that it will no longer provide information about
comments along with their "issue" type event payloads for Jira. So
we must now update the Jira integration to appropriately respond to
"comment" type events (the reason why we didn't do this before was
that initially, the "comment" type event payloads didn't contain
sufficient information about their issues, but this payload has
since been improved).

Note: This commit does *not* remove support for the older "issue"
type event payloads where information about comments was included.
This way we can maintain compatibility with old self-hosted versions
of self hosted Jira (2016 and before).

Source:
https://developer.atlassian.com/cloud/jira/platform/change-notice-
removal-of-comments-from-issue-webhooks/

Fixes #13012
2019-08-19 14:22:42 -07:00
Brutus5000 a386e3aebb github webhook: For release events show actions and tag name. 2019-08-17 12:35:16 -07:00
Anders Kaseorg e0cf3d0e76 zerver: Accept HEAD requests wherever GET requests are accepted.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2019-08-12 16:47:41 -07:00
Anders Kaseorg 0962393933 cleanup: Delete trailing newlines.
Delete trailing newlines from all files, except
tools/ci/success-http-headers.txt and tools/setup/dev-motd, where they
are significant, and static/third, where we want to stay close to
upstream.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2019-08-06 23:29:11 -07:00
Anders Kaseorg becef760bf cleanup: Delete leading newlines.
Previous cleanups (mostly the removals of Python __future__ imports)
were done in a way that introduced leading newlines.  Delete leading
newlines from all files, except static/assets/zulip-emoji/NOTICE,
which is a verbatim copy of the Apache 2.0 license.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2019-08-06 23:29:11 -07:00
Mateusz Mandera d3d62f99e4 tests: Adjust to new changes in populate_db. 2019-07-31 16:01:37 -07:00
Tim Abbott e1d9fe84ad clubhouse: Type payload as Optional.
Apparently if you post json.dumps(None), one will end up with this
None case being possible.
2019-07-31 15:31:57 -07:00
Tim Abbott 78df15ef08 Revert "clubhouse: Remove dead code."
This reverts commit 48ea427e87.
2019-07-31 15:31:57 -07:00
Tim Abbott 48ea427e87 clubhouse: Remove dead code. 2019-07-31 12:40:01 -07:00
Wyatt Hoodes c787f0a550 webhooks/jira: Fix useless check for subject being None.
This wasn't possible since a recent rewrite of the webhook code.
2019-07-31 12:27:04 -07:00
Tim Abbott acd52be820 pivotal: Remove useless conditionals.
It isn't actually possible for these values to be None.
2019-07-31 12:26:21 -07:00
Tim Abbott 1a7fd33ddb webhooks: Fix typo in a trello error message. 2019-07-26 15:12:45 -07:00
Hemanth V. Alluri 48526b1fd6 webhooks: Fix small bug in the fixture_to_headers method of bitbucket3.
We should return an empty dictionary instead of None.
2019-07-25 16:14:14 -07:00
Tim Abbott daca742e9f email_gateway: Use html2text directly.
In the rare case that Zulip receives an email with only an HTML
format, we originally (code dating to 2013) shelled out to
html2markdown/python-html2text in order to convert the HTML into
markdown.

We long since added html2text as a reasonably managed Python
dependency of Zulip; we should just use it here.
2019-07-24 12:42:17 -07:00
Eeshan Garg 1579dc2fee webhooks/github: Add support for star events. 2019-07-22 18:20:53 -07:00
Eeshan Garg badaf28f21 webhooks/github: Ignore 'meta' events.
This event occurs when its corresponding webhook is deleted. This
isn't very useful information, so we should ignore it.
2019-07-22 18:20:53 -07:00
Hemanth V. Alluri fecf6a529e webhooks: Migrate gitlab tests to the headers fixtures system.
We use the same approach as was used for the GitHub integration.
2019-07-22 12:12:50 -07:00
Hemanth V. Alluri 24d66477ca webhooks: Migrate gogs tests to the headers fixtures system. 2019-07-13 16:02:27 -07:00
Rishi Gupta 628d9ad67d notification bot: Update error messages in send_pm_if_empty_stream. 2019-07-13 15:53:36 -07:00
Hemanth V. Alluri 9e6ab7f190 webhooks: Migrate reviewboard tests to the headers fixtures system. 2019-07-09 17:13:02 -07:00
Hemanth V. Alluri b609d25cda webhooks: Migrate netlify tests to the headers fixtures system. 2019-07-09 17:13:02 -07:00
Hemanth V. Alluri e42baff9e9 webhooks: Migrate groove tests to the headers fixtures system. 2019-07-09 17:13:02 -07:00
Hemanth V. Alluri 62bcbb433d webhooks: Migrate bitbucket3 tests to the headers fixtures system. 2019-07-09 17:10:28 -07:00
Vinit Singh 3cc790420a docs: Update docs to reflect the use of Ubuntu bionic in development. 2019-07-08 13:25:54 -07:00
Anders Kaseorg 5e97e58df3 webhooks/freshdesk/doc.md: Remove unescape_rendered_html kludge.
This reverts commit f476ec7fac (#10312)
and replaces it with a proper fix using Jinja2 raw blocks.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2019-07-03 15:05:45 -07:00
Hemanth V. Alluri ef52aa0fc1 webhooks: Eliminate the usage of a headers.py file.
For storing HTTP headers as a function of fixture name, previously
we required that the fixture_to_headers method should reside in a
separate module called headers.py.

However, as in many cases, this method will only take a few lines,
we decided to move this function into the view.py file of the
integration instead of requiring a whole new file called headers.py

This commit introduces the small change in the system architecture,
migrates the GitHub integration, and updates the docs accordingly.
2019-06-26 10:35:14 -07:00
Hemanth V. Alluri 4691028097 webhooks: Extract the '__' method of mapping to headers.
In the GitHub integration we established that for many integrations,
we can directly map the fixture filename to the set of required
headers and by following a simple naming convention we can greatly
ease the logic involved in fixture_to_headers method required .

So to prevent the need for duplicating the logic used by the GitHub
integration, we created a method called `get_http_headers_from_filename`
which will take the name of the HTTP header (key) and then return a
corresponding method (in a decorator-like fashion) which could then be
equated to fixture_to_headers in headers.py.

The GitHub integration was modified to use this method and the docs
were updated to suggest using this when possible.
2019-06-26 10:32:34 -07:00
Eeshan Garg daea9a543b webhooks/bitbucket2: Account for missing username in PR payloads.
Certain PR payloads do not have a username for the reviewer, in
such cases, we just return the reviewer's nickname or display
name.
2019-06-24 23:19:06 -07:00
Hemanth V. Alluri 37d90d9add webhooks: Migrate the GitHub integration to new http headers system.
Idea courtesy of tabbott. See PR #12515 for more details.
2019-06-20 16:37:42 -07:00
Hemanth V. Alluri b8268c66d5 webhooks/bitbucket3: Add the `diagnostics:ping` event.
Note: Unlike with the other events supported by this webhook so far,
to determine this event's event type, we need to use the X-Event-Key
HTTP Header.
2019-06-17 17:33:32 -07:00
Eeshan Garg f645de255c webhooks/jira: Avoid UnboundLocalErrors for event handler functions.
If the event key is None, the handler content_func never gets
defined, which leads to an UnboundLocalError. This can be easily
avoided by having a dedicated function that handles the case for
when the event key is None.
2019-06-16 15:19:53 -07:00
Hemanth V. Alluri 611808381f webhooks/stripe: Blacklist invoice changes under invoiceitem category. 2019-06-14 15:55:07 -07:00
Hemanth V. Alluri 325b1fd6c4 webhooks/stripe: Modify the invoice.updated event handling logic.
If the invoice was paid then the message should simply be
"Invoice is now paid." with a link to the invoice.

Also, suppress the "status_transitions" and "payment_intent"events.
2019-06-14 15:55:07 -07:00
Hemanth V. Alluri eaa89d47fa webhooks/stripe: Add fixtures for invoice and invoiceitem updates. 2019-06-14 15:55:07 -07:00
Eeshan Garg 0d519ab146 webhooks/bitbucket2: Account for missing username in user data.
Not all payloads contain the user's username. In such cases, we
should use the user's display name or nickname instead.
2019-06-03 20:00:17 -07:00
Eeshan Garg cf921d5981 webhooks/buildbot: Add missing "skipped" build result code.
The payload for when a build is cancelled was causing an error
because the build result code mapping was missing one of the
codes. This commit also fixes a minor typo in the result codes.
2019-05-31 16:59:42 -07:00
David Wood 2e9e653af1 webhooks/jira: Fix markup conversion of full links.
This commit modifies the regex used when parsing JIRA's full links of
the form `[text|link]` so that if you have two in a message, Zulip
markup conversion doesn't think that the first link extends to the
closing `]` of the second link.
2019-05-27 23:41:11 -07:00
Eeshan Garg 49ac516b50 webhooks/pivotal: Use proper punctuation. 2019-05-09 13:05:49 -07:00
Eeshan Garg 550ea64b4d webhooks/trello: Use proper punctuation. 2019-05-09 13:05:49 -07:00
Eeshan Garg b434cc7054 webhooks/taiga: Use proper punctuation and new style string formatting. 2019-05-09 13:05:49 -07:00
Eeshan Garg eaf1c4d8b2 webhooks/teamcity: Improve punctuation and message formatting. 2019-05-09 13:05:49 -07:00
Eeshan Garg 6d62522ff0 webhooks/raygun: Improve punctuation and message formatting. 2019-05-09 13:05:49 -07:00
Eeshan Garg 44038fc431 webhooks/raygun: Raise exception for unsupported event types. 2019-05-09 13:05:49 -07:00
Eeshan Garg 5a1f70f6e8 webhooks/opsgenie: Improve punctuation and message formatting. 2019-05-09 13:05:49 -07:00
Eeshan Garg 120937a1f4 webhooks/mention: Use proper message formatting. 2019-05-09 13:05:49 -07:00
Eeshan Garg 1948924cdb webhooks/jira: Improve punctuation and message formatting. 2019-05-09 13:05:49 -07:00
Eeshan Garg ef070ef019 webhooks/github: Improve punctuation. 2019-05-09 13:05:49 -07:00
Eeshan Garg 9516699c73 webhooks/front: Use proper punctuation and fix spelling errors. 2019-05-09 13:05:49 -07:00
Eeshan Garg 3af4b7d750 webhooks/freshdesk: Improve message formatting and punctuation. 2019-05-07 16:45:01 -07:00
Eeshan Garg c4e4ceadb5 webhooks/git: Use proper punctuation for branch creation templates. 2019-05-07 16:45:01 -07:00
Eeshan Garg f1228b3550 webhooks/bitbucket3: Use proper punctuation. 2019-05-07 16:45:01 -07:00
Eeshan Garg ab8aae6d0c git_webhooks: Use proper punctuation for PR/issue messages. 2019-05-07 16:45:01 -07:00
Eeshan Garg 2d4b734415 webhooks/solano: Improve message formatting and punctuation.
This commit also removes the conditional for when a build status
does not have a corresponding emoji. In such a case, it is better
to have no emoji than displaying some boilerplate text about no
appropriate emoji being available.
2019-05-07 16:45:01 -07:00
David Wood 16e9892ab2 webhooks/jira: Include issue title in messages. 2019-05-03 20:03:31 -02:30
Eeshan Garg 28109e0f9e webhooks/jira: Ignore comment_created message.
comment_created payloads may not contain the required issue data
to format a useful notification, therefore, it is better to handle
issue comments through issue_updated events (which we already do).

Fixes: #11995.
2019-05-01 16:32:58 -07:00
Mayank Madan 4c81474a4f webhooks: Add Buildbot integration.
With some minor changes by Eeshan Garg.

Fixes: #5639.
2019-04-27 15:19:16 -07:00
Eeshan Garg a73e8109b7 webhooks: Remove the legacy GitHub integration.
The github-services model for how GitHub would send requests to this
legacy integration is no longer available since earlier in 2019.
Removing this integration also allows us to finally remove
authenticated_api_view, the legacy authentication model from 2013 that
had been used for this integration (and other features long since
upgraded).

A few functions that were used by the Beanstalk webhook are moved into
that webhook's implementation directly.
2019-04-27 15:13:44 -07:00
Anders Kaseorg 9a9de156c3 lint: Fix calls to _() on computed strings.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2019-04-23 15:23:03 -07:00
Anders Kaseorg 643bd18b9f lint: Fix code that evaded our lint checks for string % non-tuple.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2019-04-23 15:21:37 -07:00
Eeshan Garg c012362fde webhooks/librato: Use proper punctuation. 2019-04-23 14:32:21 -07:00
Eeshan Garg d733cc500c webhooks/groove: Rewrite the integration and improve messages.
The initial goal was to improve message formatting and punctuation
but after a closer look, I realized that a larger refactor was
worth it for clarity and redability.
2019-04-23 14:32:21 -07:00
Eeshan Garg d8d9695087 webhooks/newrelic: Improve message formatting and punctuation. 2019-04-17 16:22:43 -07:00
Eeshan Garg f86e445fe6 webhooks/sentry: Improve message formatting and punctuation. 2019-04-17 16:22:43 -07:00
Eeshan Garg 424061a07a webhooks/papertrail: Improve message formatting and punctuation. 2019-04-17 16:22:43 -07:00
Eeshan Garg 1c1b440adf webhooks/pingdom: Improve message formatter and punctuation. 2019-04-17 16:22:43 -07:00
Eeshan Garg b44d352af6 webhooks/pagerduty: Use colons before quote blocks. 2019-04-17 16:22:43 -07:00
Eeshan Garg e682889437 webhooks/insping: Improve message formatting and punctuation. 2019-04-17 16:22:43 -07:00
Eeshan Garg 5fccf197d1 webhooks/greenhouse: Improve message formatting and punctuation. 2019-04-17 16:22:43 -07:00
Eeshan Garg 674fcfcce1 webhooks/semaphore: Improve message formatting and punctuation. 2019-04-17 16:22:43 -07:00
Eeshan Garg 9d79becc0e webhooks/splunk: Improve message formatting and punctuation. 2019-04-17 16:22:43 -07:00
Eeshan Garg 21cdb6decc webhooks/wordpress: Improve message formatting and punctuation. 2019-04-17 16:22:43 -07:00
Eeshan Garg 0a0df3bc58 webhooks/zabbix: Improve message formatting and punctuation. 2019-04-17 16:22:43 -07:00
Eeshan Garg f7fd9bd17d webhooks/statuspage: Improve message formatting and punctuation. 2019-04-14 22:20:02 -07:00
Eeshan Garg f6a601f09f webhooks/heroku: Improve message formatting and punctuation. 2019-04-14 22:20:02 -07:00
Eeshan Garg 8cf18fe4d2 webhooks/delighted: Improve message formatting and punctuation. 2019-04-14 22:20:02 -07:00
Eeshan Garg 33b0bf3cb4 webhooks/beeminder: Improve message formatting and punctuation. 2019-04-14 22:20:02 -07:00
Eeshan Garg b7ea727087 webhooks/basecamp: Improve message formatting and punctuation. 2019-04-14 22:20:02 -07:00
Eeshan Garg e7fee92463 webhooks/appveyor: Improve message formatting and punctuation. 2019-04-14 22:20:02 -07:00
Eeshan Garg 92509a0cac webhooks/ansibletower: Improve message formatting and punctuation. 2019-04-14 22:20:02 -07:00
Eeshan Garg bc430909af webhooks/intercom: Implement support for all events. 2019-04-05 15:15:52 -07:00
Eeshan Garg 0076b71411 webhooks/stripe: Ignore account updates with insufficient data.
Certain payloads for account updates do not include the
previous_attributes that allow us to figure out what was actually
updated. So, we just ignore just payloads.
2019-04-04 15:21:47 -07:00
Hemanth V. Alluri 636dad7809 webhooks/bitbucket3: Use strikethrough formatting for deleted comments. 2019-04-03 19:43:04 -02:30
Hemanth V. Alluri dffb536920 webhooks/bitbucket3: Link actor name with their profile. 2019-04-03 19:43:04 -02:30
Hemanth V. Alluri eecf95d2fd webhooks/bitbucket3: Add support for all pull-request events.
closes #11992.
2019-04-03 19:43:04 -02:30
Hemanth V. Alluri 9ed1dcc4b6 webhooks: Add Bitbucket Server integration.
This commit adds support for all "repo" events.
2019-03-24 22:06:29 -02:30
Eeshan Garg 68877dba50 webhooks/bitbucket: Support empty push payloads with no user info. 2019-03-21 17:43:35 -02:30
Eeshan Garg 623ee15bee webhooks/bitbucket: Account for missing user info.
According to our logs, some BitBucket enterprise payloads may
not contain the name of the user who pushed all the commits.
2019-03-16 15:09:03 -02:30
sameerchoubey a47edd4fc8 webhooks/jira: Use dictionary to map events to functions. 2019-03-16 14:27:00 -02:30
Tim Abbott 50dc317466 notifications: Rename notifications.py to email_notifications.py.
This library is entirely about email notifications specifically, and
this rename should help make the codebase more readable.
2019-03-15 11:02:17 -07:00
Eeshan Garg 222966b6ba webhooks/zapier: Support authentication for the Zapier Zulip app.
If the user sets up a Zap using an incoming webhook bot's API
key, the authentication goes through our webhook.
2019-03-11 10:54:55 -07:00
Eeshan Garg 7b6a37780a webhooks/github: Ignore organization and milestone events.
These events are not super useful and were cluttering up our
webhook logs.
2019-03-10 14:13:17 -07:00
Eeshan Garg 6afd02bef5 webhooks/github: Restrict membership event scope to teams.
According to GitHub's webhook docs, the scope of a membership
event can only be limited to 'teams', which holds true when a
new member is added to a team. However, we just found a payload
in our logs that indicates that when a user is removed from a
team, the scope of the membership is erroneously set to
'organization', not 'team'. This is most likely a bug on
GitHub's end because such behaviour is a direct violation of
their webhook API event specifications. We account for this
by restricting membership events to teams explicitly, at least
till GitHub's docs suggest otherwise.
2019-03-10 14:13:17 -07:00
Eeshan Garg 85f453998e webhooks/zapier: Remove code related to our official Zapier app.
Our official Zapier app now uses our JS bindings (zulip-js) to
call the API directly and doesn't need to go through the webhook
anymore for anything.
2019-02-28 22:09:35 -08:00
Eeshan Garg 8821b5a903 webhooks/pagerduty: Account for missing trigger summary data.
Some incoming payloads do not include details such as the trigger's
summary and description.
2019-02-22 15:59:28 -08:00
Eeshan Garg 912931e1bc webhooks/trello: Support updateCheckItemStateOnCard events. 2019-02-22 15:59:28 -08:00
Eeshan Garg 788dd48c93 webhooks/trello: Ignore createCheckItem events.
Notifications for every check item that is added to a card's
check list would be too noisy.
2019-02-22 15:59:28 -08:00
Eeshan Garg 9af2aa5566 webhooks/trello: Recommend wrapping webhook URL in quotes.
The ampersand in the query string of a URL can confuse bash,
leading to situations where anything in the URL beyond the
ampersand isn't parsed.
2019-02-22 15:59:28 -08:00
Eeshan Garg cfe0f6b56d webhooks/clubhouse: Account for bug in GitHub branch payloads.
This change was prompted by a possible bug on Clubhouse's end. In
general, if a branch is added, it also prompts a workflow state
transition in its primary story.

However, our webhook error logs show an erroneous payload where
the same branch is added to another story, but there is no
workflow state transition. Also, both the stories are grouped in
the same payload, which confused/broke our code. Ideally, this
shouldn't happen and is most likely a bug on Clubhouse's end.
In most cases, changes included in Clubhouse payloads never
pertain to more than one parent entity (stories) simultaneously,
and we usually operate under the assumption that the changes
included therein are related to each other in terms of their
parent object (story or epic) and not a child object (the GitHub
branch).
2019-02-20 16:32:42 -08:00
Eeshan Garg 76b1a8379b webhooks/clubhouse: Support epic_archive events. 2019-02-20 16:32:42 -08:00
Eeshan Garg 51a1b76a1f webhooks/clubhouse: Ignore story comment updates.
Comment updates in general aren't very informative.
Plus, errors for this event type were cluttering up our
webhook logs.
2019-02-20 16:32:42 -08:00
Eeshan Garg 76e58d05cb webhooks/jira: Ignore a few noisy events.
UnexpectedWebhookEventType errors for these events were cluttering
up our webhook error logs.
2019-02-20 16:32:42 -08:00
Eeshan Garg fa29006311 webhooks/github: Ignore check_suite events.
A check suite is a collection of check runs. We care a lot more
about the outcomes of check runs in this case because check_run
payloads are a lot more informative than check_suite payloads.

(And in any case, the check_suite events are primarily for notifying
tools like CI to run checks).
2019-02-20 16:32:42 -08:00
Eeshan Garg a0717e4424 webhook/github: Support check_run events.
We only support notifications for events where a check run has
completed. Notifications for when a check run has been queued or
is in progress are not very informative and may be too noisy.
2019-02-20 16:32:39 -08:00
Eeshan Garg c78c3f423c webhooks/github: Ignore project_card events.
The payloads for this event are missing some important details
about the Project's changes, such as the name of the project,
the card's column name, etc. Without such details, the resultant
notifications would not be useful at all!
2019-02-19 14:25:38 -08:00
Eeshan Garg ec81410b03 webhooks/github: Ignore repository_vulnerability_alert event.
This event isn't incredibly common/useful and errors for this
event were cluttering up our webhook logs.
2019-02-19 18:01:05 -03:30
Eeshan Garg b0c761dfb1 zapier_app: Include bot details in response to auth requests.
The bot's details (such as ID and name) are used to format a
connection label in Zapier's UI. This allows users to distinguish
between different Zapier-to-Zulip connections set up with different
bots.
2019-02-11 21:24:52 -08:00
Eeshan Garg 361d2d0688 webhooks/stripe: Add fixture and test for invoiceitem.created. 2019-02-05 18:40:38 -03:30
Eeshan Garg 20769f0fe9 zapier_app: Add support for private/huddle messages. 2019-02-05 17:25:58 -03:30
Rishi Gupta 71958fc1d8 Revert "webhooks/stripe: Add support for remaining payout events."
These ended up more noisy than helpful.

This reverts commit d4cd789213.
2019-02-04 12:34:32 -08:00
Rishi Gupta 942e419b85 Revert "webhooks/stripe: Handle invoice events explicitly."
The original commit made a number of well-meaning but suboptimal product
changes to the invoice events, such as threading them under the invoice id
rather than the customer id. It also seems to be causing 500s for
invoiceitem events, though I'm not sure why.

This reverts commit 65489b0391.
2019-02-04 12:18:47 -08:00
Anders Kaseorg 39ac378220 webhooks: Remove unused imports.
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
2019-02-02 17:05:20 -08:00
Eeshan Garg 954a98b49f webhooks/jira: Ignore issuelink_created events.
Notifications for this event aren't very useful to begin with,
plus exceptions from this event are cluttering up our webhook
error logs.
2019-02-02 14:53:15 -03:30
sameerchoubey 65489b0391 webhooks/stripe: Handle invoice events explicitly.
Closes #10909
2019-02-01 21:38:20 -03:30
Eeshan Garg bffc473ec8 webhooks/zapier: Support stream messages for the Zapier Zulip app. 2019-02-01 21:19:26 -03:30
Eeshan Garg b1ce237624 webhooks/zapier: Support authentication for the Zapier Zulip app. 2019-02-01 21:19:26 -03:30
Eeshan Garg f9ee393e4f webhooks/common: Allow suppressing exceptions for missing headers.
This is useful in cases where an event type HTTP header isn't
crucial for inferring the payload's type.
2019-02-01 21:19:26 -03:30
Pragati Agrawal e1772b3b8f tools: Upgrade Pycodestyle and fix new linter errors.
Here, we are upgrading pycodestyle version from 2.4.0 to 2.5.0.

Fixes: #11396.
2019-01-31 12:21:41 -08:00
Akshay Gupta 88ed75d06d travis_webhooks: Update the list of bad statuses.
Fixes #11259.
2019-01-28 21:37:18 -08:00
Eeshan Garg 5057406f16 webhooks/clubhouse: Extract story labels from actions.
Apparently, Clubhouse has two different payloads for story label
changes, one where the label name lives inside the "references"
object, and the other where it lives inside the "actions" object.
Their webhook API is still in beta, so this could just be a bug.
Anyhow, we should support both.
2019-01-24 20:08:59 -03:30
Eeshan Garg 2b81d66537 webhooks/clubhouse: Add support for GitHub handler events.
These events are triggered when one has Clubhouse's GitHub
integration and custom event handlers set up.
2019-01-24 10:01:17 -08:00
sameerchoubey d4cd789213 webhooks/stripe: Add support for remaining payout events.
This adds support for payout events to the Stripe
intergration.
2019-01-23 21:29:40 -03:30
Anders Kaseorg b7179f8f79 webhooks/zabbix: Don’t write unused /tmp/payload.txt file.
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
2019-01-15 16:13:30 -08:00
Eeshan Garg e9e075f6e8 webhooks/pagerduty: Stop sending raw payloads in notifications.
For unsupported or invalid payloads, we should just raise the
UnexpectedWebhookEventType exception and let our logging system
take care of recording the payload that caused the error.
2019-01-13 19:09:11 -08:00
Eeshan Garg a1994122ca webhooks/pagerduty: Refactor and make minor improvements.
This commit improves a couple of things:

* All of the message templates are now at the top, a convention
  we follow in a lot of our webhooks.
* Messages are not prefixed with any emojis. We don't do this in
  any of our other webhooks. Plus, the emojis were outdated.
* Remove some superfluous code.
* Use ```quote <quote goes here> ``` style formatting for
  quoted text instead of the `>` character.
2019-01-13 19:09:11 -08:00
Eeshan Garg 74f0d32a21 webhooks/pagerduty: Support events from webhook v2.
This commit only adds support for the four events that have sample
payloads provided for them on the Pagerduty developer website.
Support for the remaining events will be added in subsequent
commits, as we get access to more sample payloads.
2019-01-13 19:09:11 -08:00
Eeshan Garg 73eed42b3c webhooks/clubhouse: Extract story labels from references.
It looks like Clubhouse has moved where they store the label name
from the "actions" list to the "references" list.
2019-01-10 20:00:30 -08:00
Anders Kaseorg 2ad1a27b28 create-production-venv: Remove Python 2 support.
We still create a Python 2 virtualenv for thumbor but that’s
separate (/srv/zulip-thumbor-venv from
scripts/lib/create-thumbor-venv).

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
2019-01-09 17:32:05 -08:00
Eeshan Garg 539e5e5f41 webhooks/jira: Support comment_created event type.
Fixes: #11200
2019-01-07 14:55:12 -08:00
Eeshan Garg ecb506f13c webhooks/clubhouse: Support adding owners to stories. 2019-01-04 14:27:46 -08:00
Tim Abbott 1ff3dd0ef7 clubhouse: Don't 500 for unhandled event types. 2019-01-02 15:23:09 -08:00
Eeshan Garg d999e79a8b webhooks/bitbucket2: Decode improperly encoded stream names and topics. 2018-12-29 14:51:38 -08:00
Eeshan Garg 31f82705e2 webhooks/bitbucket: Decode improperly encoded stream names and topics. 2018-12-29 14:51:38 -08:00
Eeshan Garg c4fd0a659f webhooks/statuspage: Update docs, logo and screenshots. 2018-12-29 10:29:16 -08:00
Eeshan Garg 1b539a51de webhooks/opsgenie: Update docs, logo and screenshots.
Note that the word "genie" in Opsgenie is not supposed to be
capitalized.
2018-12-29 10:29:16 -08:00
Eeshan Garg 8bab4ceba4 webhooks/bitbucket2: Update docs, logo and screenshots. 2018-12-29 10:29:16 -08:00
Eeshan Garg 9c584e6bb8 webhooks/trello: Remove superflous Advanced section.
This section is largely unnecessary, doesn't convey any useful
information, and is probably a remnant from an older version of
this doc that we forgot to remove.
2018-12-29 10:29:16 -08:00
Eeshan Garg 4a2a3e3640 webhooks/gitlab: Support issues with multiple assignees.
The fixtures added in this commit were generated by Adam Birds.
2018-12-27 20:15:00 -08:00
Eeshan Garg 6d51c065d3 webhooks/gitlab: Add support for confidential issues and notes.
With some minor changes by Eeshan Garg.

Fixes #10478.
2018-12-18 14:37:44 -08:00
Eeshan Garg 124cb9cca3 webhooks/zabbix: Handle payloads with missing data properly. 2018-12-18 13:44:35 -08:00
Eeshan Garg a56dbdb0f3 webhooks/clubhouse: Ignore requests with empty request body. 2018-12-18 12:54:04 -08:00
Eeshan Garg dedf56bf31 webhooks/clubhouse: Support story/epic deletion. 2018-12-18 12:54:04 -08:00
Tim Abbott 32f24bff8d stripe: Fix exception handling for suppressed event types. 2018-12-15 14:14:09 -08:00
Tim Abbott e7746809d2 stripe: Fix exception handler for suppressed events.
Apparently, we incorrectly placed the try/except block around the
common code, not the code that can actually raise these exceptions.
2018-12-13 10:22:19 -08:00
Tim Abbott e603237010 email: Convert accounts code to use delivery_email.
A key part of this is the new helper, get_user_by_delivery_email.  Its
verbose name is important for clarity; it should help avoid blind
copy-pasting of get_user (which we'll also want to rename).
Unfortunately, it requires detailed understanding of the context to
figure out which one to use; each is used in about half of call sites.

Another important note is that this PR doesn't migrate get_user calls
in the tests except where not doing so would cause the tests to fail.
This probably deserves a follow-up refactor to avoid bugs here.
2018-12-06 16:21:38 -08:00
Rishi Gupta 82ee496efc webhooks/stripe: Update fixture for customer_subscription_created. 2018-12-06 11:29:16 -08:00
Rishi Gupta 76aebac568 webhooks/stripe: Format timestamps as dates. 2018-12-06 11:29:16 -08:00
Rishi Gupta 027d5e90c5 webhooks/stripe: Update how we handle updated events.
Also more explicitly ignores the Stripe Connect related events in the
'account' category.
2018-12-06 11:29:16 -08:00
Rishi Gupta 5fb683e788 webhooks/stripe: Use exceptions instead of json_success to exit main body. 2018-12-06 11:29:16 -08:00
Eeshan Garg 901100bebf webhooks/jira: Decode topics on our end.
The problem addressed in 006e47198c
resurfaces with topics when a user provides a custom topic in the
webhook URL.
2018-12-03 17:37:36 -08:00
Tim Abbott c740d1b093 clubhouse: Fix typoed include statement. 2018-12-03 14:31:44 -08:00
Rishi Gupta 22d8de73e9 webhooks/stripe: Change update_string to provide updated values. 2018-12-03 09:24:52 -08:00
Rishi Gupta 36f54e689b integrations/stripe: Fix bug in charge.succeeded.
There are (at least) two types of objects that could be sent with a
charge.succeeded event, a Charge (e.g. for credit cards) or a Payment (if
they pay by ACH). We were handling the first but not the second.

This commit also updates the fixture for the existing charge.succeeded event
to the latest API version.
2018-12-02 00:25:52 -08:00
Eeshan Garg 5ef86b6d22 webhooks/stripe: Handle customer.discount events properly.
Recent changes merged in #10877 didn't handle these events
correctly. The linkified_id function breaks for the `discount`
object in the JSON payload. A cursory glance at Stripe's docs
tells me that since a discount is associated with a customer
or a coupon, it makes sense for a `discount` object to not have
an ID that can necessarily be linked to. So, we can just link
to the associated coupon instead.
2018-11-28 14:16:33 -08:00
Rishi Gupta 9f471a3e7d webhooks: Update Stripe integration. 2018-11-25 23:23:50 -08:00
Tim Abbott 2fb1e51d71 dropbox: Fix incorrect placement of notify_bot_owner_on_invalid_json.
This was an error I introduced in editing
b79213d260.
2018-11-20 18:45:43 -08:00
Eeshan Garg 67d209ade9 webhooks/greenhouse: Update docs to conform to style guide. 2018-11-20 18:38:43 -08:00
Eeshan Garg 60d3e6b49b webhooks/gosquared: Support chat message events. 2018-11-20 15:59:51 -08:00
Eeshan Garg b79213d260 webhooks: Notify bot owner on invalid JSON.
There are only a handful of non-JSON webhooks that wouldn't
benefit from the notify_bot_owner_on_invalid_json feature.

Specifically, these are the webhooks where the third-party product
uses another format, whether it be HTML form-encoded, XML, or
something else.

Tweaked by tabbott to correc the list of excluded webhooks.
2018-11-20 15:59:09 -08:00
Tim Abbott 1abb1447df stripe: Be more explicit about the valid set of event types.
Previously, the Stripe webhook code was riddled with implicit
assertions that there were exactly N event types within a given
category, and we handled the last one in a final `else` clause in the
block.  This was likely to cause confusing problems in the event that
we're missing an event type (or Stripe adds a new one).

We fix this by just adding a few more conditionals and raising the
standard "unexpected event type" exception for the others.
2018-11-19 11:40:54 -08:00
Eeshan Garg 9afb1c3459 webhooks/stripe: Support customer.subscription.update events. 2018-11-19 11:33:41 -08:00
Steve Howell f3e529c694 minor: Use topic_name() in travis test. 2018-11-14 23:24:06 -08:00
Eeshan Garg ab7d0de782 webhooks/github: Enable PM notifications for non-JSON payloads. 2018-11-14 22:35:57 -08:00
Eeshan Garg 41c0e9ba47 webhooks: Add ReviewBoard integration. 2018-11-12 16:11:32 -08:00
Steve Howell 1854ddbcd0 taiga tests: Use self.TOPIC instead of "subject". 2018-11-12 15:47:11 -08:00
Steve Howell 31e328c544 webhook tests: Replace SUBJECT with TOPIC. 2018-11-12 15:47:11 -08:00
Steve Howell 1fff890b71 webhooks: Change *_SUBJECT_TEMPLATE to *_TOPIC_TEMPLATE. 2018-11-12 15:47:11 -08:00
Steve Howell ea98a44db3 webhooks: Replace SUBJECT_WITH_* with TOPIC_WITH_*. 2018-11-12 15:47:11 -08:00
Steve Howell ced4d81856 Sweep tests for expected_subject -> expected_topic.
This is all in the webhooks tests, including some
docs for how to write those tests.
2018-11-12 15:47:11 -08:00
Steve Howell 6b6001c46c Remove "subject" from test_classes.py.
We now use "topic" lingo.
2018-11-07 10:03:53 -08:00