Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

reviewboard: Support no target people, target groups.

Alex Vandiver7ed76fd8c1b4
diff --git a/zerver/webhooks/reviewboard/fixtures/review_request_published__with_group.json b/zerver/webhooks/reviewboard/fixtures/review_request_published__with_group.json
new file mode 100644
index 00000000000..d2bc74abead
--- /dev/null
+++ b/zerver/webhooks/reviewboard/fixtures/review_request_published__with_group.json
@@ -0,0 +1,117 @@
+{
+ "review_request":{
+ "status":"pending",
+ "last_updated":"2018-10-26T15:39:46Z",
+ "target_people":[
+
+ ],
+ "depends_on":[
+
+ ],
+ "description_text_type":"plain",
+ "issue_resolved_count":0,
+ "commit_id":"0c694b62d4cfd159e1b94b9368bc573338c7c77a",
+ "ship_it_count":0,
+ "close_description_text_type":"plain",
+ "id":2,
+ "links":{
+ "diffs":{
+ "href":"https://rbcommons.com/s/zulip/api/review-requests/2/diffs/",
+ "method":"GET"
+ },
+ "latest_diff":{
+ "href":"https://rbcommons.com/s/zulip/api/review-requests/2/diffs/1/",
+ "method":"GET"
+ },
+ "repository":{
+ "href":"https://rbcommons.com/s/zulip/api/repositories/2147/",
+ "method":"GET",
+ "title":"Scheduler"
+ },
+ "screenshots":{
+ "href":"https://rbcommons.com/s/zulip/api/review-requests/2/screenshots/",
+ "method":"GET"
+ },
+ "self":{
+ "href":"https://rbcommons.com/s/zulip/api/review-requests/2/",
+ "method":"GET"
+ },
+ "status_updates":{
+ "href":"https://rbcommons.com/s/zulip/api/review-requests/2/status-updates/",
+ "method":"GET"
+ },
+ "update":{
+ "href":"https://rbcommons.com/s/zulip/api/review-requests/2/",
+ "method":"PUT"
+ },
+ "last_update":{
+ "href":"https://rbcommons.com/s/zulip/api/review-requests/2/last-update/",
+ "method":"GET"
+ },
+ "reviews":{
+ "href":"https://rbcommons.com/s/zulip/api/review-requests/2/reviews/",
+ "method":"GET"
+ },
+ "file_attachments":{
+ "href":"https://rbcommons.com/s/zulip/api/review-requests/2/file-attachments/",
+ "method":"GET"
+ },
+ "draft":{
+ "href":"https://rbcommons.com/s/zulip/api/review-requests/2/draft/",
+ "method":"GET"
+ },
+ "diff_context":{
+ "href":"https://rbcommons.com/s/zulip/api/review-requests/2/diff-context/",
+ "method":"GET"
+ },
+ "submitter":{
+ "href":"https://rbcommons.com/s/zulip/api/users/eeshangarg/",
+ "method":"GET",
+ "title":"eeshangarg"
+ },
+ "changes":{
+ "href":"https://rbcommons.com/s/zulip/api/review-requests/2/changes/",
+ "method":"GET"
+ },
+ "delete":{
+ "href":"https://rbcommons.com/s/zulip/api/review-requests/2/",
+ "method":"DELETE"
+ }
+ },
+ "issue_dropped_count":0,
+ "bugs_closed":[
+
+ ],
+ "testing_done":"This was tested thoroughly.",
+ "branch":"master",
+ "text_type":null,
+ "time_added":"2018-10-26T15:39:46Z",
+ "extra_data":{
+ "calculated_trophies":true
+ },
+ "public":true,
+ "issue_verifying_count":0,
+ "close_description":null,
+ "blocks":[
+
+ ],
+ "description":"Initial commit",
+ "testing_done_text_type":"markdown",
+ "issue_open_count":0,
+ "approved":false,
+ "url":"/s/zulip/r/2/",
+ "absolute_url":"https://rbcommons.com/s/zulip/r/2/",
+ "target_groups":[
+ {
+ "href":"https://rbcommons.com/s/zulip/api/groups/people/",
+ "method":"GET",
+ "title":"people"
+ }
+ ],
+ "summary":"Initial commit",
+ "changenum":null,
+ "approval_failure":"The review request has not been marked \"Ship It!\""
+ },
+ "event":"review_request_published",
+ "is_new":true
+}
diff --git a/zerver/webhooks/reviewboard/tests.py b/zerver/webhooks/reviewboard/tests.py
index f49d3ee5e2c..7624b1a3792 100644
--- a/zerver/webhooks/reviewboard/tests.py
+++ b/zerver/webhooks/reviewboard/tests.py
@@ -16,6 +16,15 @@ class ReviewBoardHookTests(WebhookTestCase):
expected_message,
)
+ def test_review_request_published_with_group(self) -> None:
+ expected_topic_name = "Scheduler"
+ expected_message = "**eeshangarg** opened [#2: Initial commit](https://rbcommons.com/s/zulip/r/2/):\n\n``` quote\n**Description**: Initial commit\n**Status**: pending\n**Target groups**: **people**\n**Branch**: master\n```"
+ self.check_webhook(
+ "review_request_published__with_group",
+ expected_topic_name,
+ expected_message,
+ )
+
def test_review_request_reopened(self) -> None:
expected_topic_name = "Scheduler"
expected_message = "**eeshangarg** reopened [#1: Initial commit (first iteration)](https://rbcommons.com/s/zulip/r/1/):\n\n``` quote\n**Description**: Initial commit (first iteration)\n**Status**: pending\n**Target people**: **drsbgarg**\n**Branch**: master\n```"
diff --git a/zerver/webhooks/reviewboard/view.py b/zerver/webhooks/reviewboard/view.py
index 8ccea611a5f..cfe0180bcb0 100644
--- a/zerver/webhooks/reviewboard/view.py
+++ b/zerver/webhooks/reviewboard/view.py
@@ -37,7 +37,7 @@ REVIEW_REQUEST_DETAILS = """
``` quote
**Description**: {description}
**Status**: {status}
-**Target people**: {target_people}
+{targets}
{extra_info}
```
"""
@@ -56,19 +56,28 @@ BRANCH_TEMPLATE = "**Branch**: {branch_name}"
fixture_to_headers = default_fixture_to_headers("HTTP_X_REVIEWBOARD_EVENT")
-def get_target_people_string(payload: WildValue) -> str:
+def joined_list(targets: WildValue) -> str:
+ if len(targets) == 1:
+ return "**{title}**".format(title=targets[0]["title"].tame(check_string))
+ else:
+ output = ""
+ for elem in list(targets)[:-1]:
+ output += "**{title}**, ".format(title=elem["title"].tame(check_string))
+ output += "and **{title}**".format(title=targets[-1]["title"].tame(check_string))
+ return output
+
+
+def get_targets_string(payload: WildValue) -> str:
result = ""
target_people = payload["review_request"]["target_people"]
- if len(target_people) == 1:
- result = "**{title}**".format(title=target_people[0]["title"].tame(check_string))
- else:
- for target_index in range(len(target_people) - 1):
- result += "**{title}**, ".format(
- title=target_people[target_index]["title"].tame(check_string)
- )
- result += "and **{title}**".format(title=target_people[-1]["title"].tame(check_string))
+ if target_people:
+ result += f"**Target people**: {joined_list(target_people)}\n"
+
+ target_groups = payload["review_request"]["target_groups"]
+ if target_groups:
+ result += f"**Target groups**: {joined_list(target_groups)}\n"
- return result
+ return result.strip()
def get_review_published_body(payload: WildValue) -> str:
@@ -106,7 +115,7 @@ def get_review_request_published_body(payload: WildValue) -> str:
"user_name": payload["review_request"]["links"]["submitter"]["title"].tame(check_string),
"description": payload["review_request"]["description"].tame(check_string),
"status": payload["review_request"]["status"].tame(check_string),
- "target_people": get_target_people_string(payload),
+ "targets": get_targets_string(payload),
"extra_info": "",
}
@@ -127,7 +136,7 @@ def get_review_request_reopened_body(payload: WildValue) -> str:
"user_name": payload["reopened_by"]["username"].tame(check_string),
"description": payload["review_request"]["description"].tame(check_string),
"status": payload["review_request"]["status"].tame(check_string),
- "target_people": get_target_people_string(payload),
+ "targets": get_targets_string(payload),
"extra_info": "",
}
@@ -148,7 +157,7 @@ def get_review_request_closed_body(payload: WildValue) -> str:
"user_name": payload["closed_by"]["username"].tame(check_string),
"description": payload["review_request"]["description"].tame(check_string),
"status": payload["review_request"]["status"].tame(check_string),
- "target_people": get_target_people_string(payload),
+ "targets": get_targets_string(payload),
"extra_info": "**Close type**: {}".format(payload["close_type"].tame(check_string)),
}