Skip to content

Commit

Permalink
Merge pull request #2 from vchrombie/0.1.1-change-email-arg
Browse files Browse the repository at this point in the history
[zulip] Change `email` to zulip argument group
  • Loading branch information
vchrombie authored Sep 22, 2021
2 parents 050b2bd + 04322e0 commit fa3ef2f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 18 deletions.
26 changes: 17 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,17 @@ $ poetry shell

## Usage

**Note:** You need the `email` and the `api_token` from the server. You can create a bot and use it for the authentication,
please read the docs at [About bots (Zulip Help Center)](https://zulip.com/help/bots-and-integrations).
**Note:** You need the `email` and the `api_token` (API key) from the server. You can use the user email and API key
for authentication or create a bot and use the bot email and API key.

Reference: [About bots (Zulip Help Center)](https://zulip.com/help/bots-and-integrations).
```
$ perceval zulip --help
[2021-09-11 12:50:28,594] - Sir Perceval is on his quest.
(.venv) $ perceval zulip --help
[2021-09-20 15:57:22,523] - Sir Perceval is on his quest.
usage: perceval [-h] [--category CATEGORY] [--tag TAG] [--filter-classified] -t API_TOKEN
[--archive-path ARCHIVE_PATH] [--no-archive] [--fetch-archive]
[--archived-since ARCHIVED_SINCE] [--no-ssl-verify] [-o OUTFILE]
[--json-line] [-e EMAIL]
[--json-line] -e EMAIL
url stream
positional arguments:
Expand All @@ -64,17 +66,23 @@ positional arguments:
optional arguments:
-h, --help show this help message and exit
-e EMAIL, --email EMAIL
Zulip bot email
authentication arguments:
-t API_TOKEN, --api-token API_TOKEN
backend authentication token / API key
zulip arguments:
-e EMAIL, --email EMAIL
Zulip bot/user email
```

Fetch messages from the `importlib` stream of the [Python Zulip Server](https://python.zulipchat.com)
Fetch messages from the `importlib` stream of the [Python Zulip Server](https://python.zulipchat.com) with the
bot email `bot@zulipchat.com` and API key `xxxx`
```
$ perceval zulip https://python.zulipchat.com importlib -e bot@zulipchat.com -t xxxx
(.venv) $ perceval zulip https://python.zulipchat.com importlib -e bot@zulipchat.com -t xxxx
[2021-09-20 15:59:24,593] - Sir Perceval is on his quest.
{
...
```

## Contributing
Expand Down
21 changes: 12 additions & 9 deletions perceval/backends/zulip/zulip.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ class Zulip(Backend):
:param url: URL of the Zulip chat server
:param stream: stream from which the messages are to be fetched
:param email: bot email
:param api_token: key needed to use the API
:param email: bot/user email
:param api_token: bot/user API key
:param tag: label used to mark the data
:param archive: archive to store/retrieve items
:param ssl_verify: enable/disable SSL verification
"""

version = '0.1.0'
version = '0.1.1'

CATEGORIES = [CATEGORY_MESSAGE]

Expand Down Expand Up @@ -170,7 +170,7 @@ def metadata_updated_on(item):
ts = float(item['timestamp'])
return ts

@ staticmethod
@staticmethod
def metadata_category(item):
"""Extracts the category from a Zulip item.
Expand All @@ -193,8 +193,8 @@ class ZulipClient(HttpClient):
:param url: URL of the Zulip chat server
:param stream: stream from which the messages are to be fetched
:param email: bot email
:param api_token: key needed to use the API
:param email: bot/user email
:param api_token: bot/user API key
:param archive: archive to store/retrieve items
:param from_archive: it tells whether to write/read the archive
:param ssl_verify: enable/disable SSL verification
Expand Down Expand Up @@ -245,10 +245,13 @@ def setup_cmd_parser(cls):
action = parser.parser._option_string_actions['--api-token']
action.required = True

# # Required arguments
# Zulip options
group = parser.parser.add_argument_group('zulip arguments')
group.add_argument('-e', '--email', dest='email', required=True,
help="Zulip bot/user email")

# Required arguments
parser.parser.add_argument('url', help="Zulip chat URL")
parser.parser.add_argument('stream', help='Zulip chat stream name')
parser.parser.add_argument('-e', '--email', dest='email',
help="Zulip bot email")

return parser
12 changes: 12 additions & 0 deletions releases/unreleased/change-`email`-to-zulip-argument-group.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: Change `email` to zulip argument group
category: fixed
author: Venu Vardhan Reddy Tekula <venu@chaoss.community>
issue: 1
notes: >
The current implementation uses `token_auth` and supports
`email` as an argument. But, `email` is not an optional
argument. The auth fails if no `email` is provided.
To handle this, the email is moved to a new zulip argument
group. Now, it throws an error is `email` is missing.

0 comments on commit fa3ef2f

Please sign in to comment.