Skip to content

Commit a9268a1

Browse files
pemonttotimabbott
authored andcommitted
jira: Add JQL search command.
1 parent a46dae3 commit a9268a1

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

zulip_bots/zulip_bots/bots/jira/doc.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,25 @@ Jira Bot:
4949
5050
---
5151

52+
### jql
53+
54+
`jql` takes in a jql search string and returns matching issues. For example,
55+
56+
you:
57+
58+
> @**Jira Bot** jql "issuetype = Engagement ORDER BY created DESC"
59+
60+
Jira Bot:
61+
62+
> **Search results for "issuetype = vulnerability ORDER BY created DESC"**
63+
>
64+
> *Found 53 results*
65+
>
66+
> - ***BOTS-1:*** External Website Test **[In Progress]**
67+
> - ***BOTS-3:*** Network Vulnerability Scan **[Draft]**
68+
69+
---
70+
5271
### create
5372

5473
`create` creates an issue using its

zulip_bots/zulip_bots/bots/jira/jira.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
'$'
2929
)
3030
SEARCH_REGEX = re.compile('search "(?P<search_term>.+)"$')
31+
JQL_REGEX = re.compile('jql "(?P<jql_query>.+)"$')
3132
HELP_REGEX = re.compile('help$')
3233

3334
HELP_RESPONSE = '''
@@ -70,6 +71,23 @@
7071
7172
---
7273
74+
**jql**
75+
76+
`jql` takes in a jql search string and returns matching issues. For example,
77+
78+
you:
79+
80+
> @**Jira Bot** jql "issuetype = Engagement ORDER BY created DESC"
81+
82+
Jira Bot:
83+
84+
> **Search results for *"issuetype = Engagement ORDER BY created DESC"*:**
85+
>
86+
> - ***BOTS-1:*** External Website Test **[In Progress]**
87+
> - ***BOTS-3:*** Network Vulnerability Scan **[Draft]**
88+
89+
---
90+
7391
**create**
7492
7593
`create` creates an issue using its
@@ -188,6 +206,7 @@ def handle_message(self, message: Dict[str, str], bot_handler: Any) -> None:
188206
create_match = CREATE_REGEX.match(content)
189207
edit_match = EDIT_REGEX.match(content)
190208
search_match = SEARCH_REGEX.match(content)
209+
jql_match = JQL_REGEX.match(content)
191210
help_match = HELP_REGEX.match(content)
192211

193212
if get_match:
@@ -277,6 +296,10 @@ def handle_message(self, message: Dict[str, str], bot_handler: Any) -> None:
277296
search_term = search_match.group('search_term')
278297
search_results = self.jql_search("summary ~ {}".format(search_term))
279298
response = '**Search results for "{}"**\n\n{}'.format(search_term, search_results)
299+
elif jql_match:
300+
jql_query = jql_match.group('jql_query')
301+
search_results = self.jql_search(jql_query)
302+
response = '**Search results for "{}"**\n\n{}'.format(jql_query, search_results)
280303
elif help_match:
281304
response = HELP_RESPONSE
282305
else:

zulip_bots/zulip_bots/bots/jira/test_jira.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,23 @@ class TestJiraBot(BotTestCase, DefaultTests):
8080
8181
---
8282
83+
**jql**
84+
85+
`jql` takes in a jql search string and returns matching issues. For example,
86+
87+
you:
88+
89+
> @**Jira Bot** jql "issuetype = Engagement ORDER BY created DESC"
90+
91+
Jira Bot:
92+
93+
> **Search results for *"issuetype = Engagement ORDER BY created DESC"*:**
94+
>
95+
> - ***BOTS-1:*** External Website Test **[In Progress]**
96+
> - ***BOTS-3:*** Network Vulnerability Scan **[Draft]**
97+
98+
---
99+
83100
**create**
84101
85102
`create` creates an issue using its
@@ -137,6 +154,7 @@ class TestJiraBot(BotTestCase, DefaultTests):
137154
MOCK_SEARCH_RESPONSE = '**Search results for "TEST"**\n\n*Found 2 results*\n\n\n - TEST-1: [summary test 1](https://example.atlassian.net/browse/TEST-1) **[To Do]**\n - TEST-2: [summary test 2](https://example.atlassian.net/browse/TEST-2) **[To Do]**'
138155
MOCK_SEARCH_RESPONSE_URL = '**Search results for "TEST"**\n\n*Found 2 results*\n\n\n - TEST-1: [summary test 1](http://test.com/browse/TEST-1) **[To Do]**\n - TEST-2: [summary test 2](http://test.com/browse/TEST-2) **[To Do]**'
139156
MOCK_SEARCH_RESPONSE_SCHEME = '**Search results for "TEST"**\n\n*Found 2 results*\n\n\n - TEST-1: [summary test 1](http://example.atlassian.net/browse/TEST-1) **[To Do]**\n - TEST-2: [summary test 2](http://example.atlassian.net/browse/TEST-2) **[To Do]**'
157+
MOCK_JQL_RESPONSE = '**Search results for "summary ~ TEST"**\n\n*Found 2 results*\n\n\n - TEST-1: [summary test 1](https://example.atlassian.net/browse/TEST-1) **[To Do]**\n - TEST-2: [summary test 2](https://example.atlassian.net/browse/TEST-2) **[To Do]**'
140158

141159
def _test_invalid_config(self, invalid_config, error_message) -> None:
142160
with self.mock_config_info(invalid_config), \
@@ -212,6 +230,11 @@ def test_search(self) -> None:
212230
self.mock_http_conversation('test_search'):
213231
self.verify_reply('search "TEST"', self.MOCK_SEARCH_RESPONSE)
214232

233+
def test_jql(self) -> None:
234+
with self.mock_config_info(self.MOCK_CONFIG_INFO), \
235+
self.mock_http_conversation('test_search'):
236+
self.verify_reply('jql "summary ~ TEST"', self.MOCK_JQL_RESPONSE)
237+
215238
def test_search_url(self) -> None:
216239
with self.mock_config_info(self.MOCK_DISPLAY_CONFIG_INFO), \
217240
self.mock_http_conversation('test_search'):

0 commit comments

Comments
 (0)