Repository: zulip/zulip

Issue:
GitHub bot should leave out branch names on pull request events
Here's an [example message](https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/zulip-flutter/near/1515826) from the GitHub bot:
> gnprice updated [PR #17 Start writing unit tests](https://github.com/zulip/zulip-flutter/pull/17) from `pr-tests` to `main`.

This wording is confusing to the point of being wrong: despite the use of the verb "updated", it's not the case that in any sense the PR was `pr-tests`, and became `main` instead.

We should remove these branch names from the pull-request events. The "from" branch is never interesting. The "to" branch could be relevant on the "PR created" events, but isn't essential there, and never belongs on any of the other events.

@timabbott writes:
> The only place we use that language is in the `get_pull_request_event_message`, with this block:

and quotes:
```py
PULL_REQUEST_BRANCH_INFO_TEMPLATE = "from `{target}` to `{base}`"

if target_branch and base_branch:
    branch_info = PULL_REQUEST_BRANCH_INFO_TEMPLATE.format(
        target=target_branch,
        base=base_branch,
    )
    main_message = f"{main_message} {branch_info}"
```

So the simplest fix is to just delete that code.

See [chat thread](https://chat.zulip.org/#narrow/stream/9-issues/topic/GitHub.20bot.20wording/near/1515830).


Discussion:
@zulipbot claim

Hello @Aryanryn09!

Thanks for your interest in Zulip! You have attempted to claim an issue without the label "help wanted". You can only claim and submit pull requests for issues with the [help wanted](https://github.com/zulip/zulip/issues?q=is%3Aopen+is%3Aissue+no%3Aassignee+label%3A%22help+wanted%22) label.

If this is your first time here, we recommend reading our [guide for new contributors](https://zulip.readthedocs.io/en/latest/overview/contributing.html) before getting started.

Hey @gnprice  **I want to contribute in it should I have to replace the main_message or remove this line form the code PULL_REQUEST_BRANCH_INFO_TEMPLATE = "from `{target}` to `{base}`" or should I have to delete these four all code including the if conditions to fix this problem ?** Please Guide me its my first time.

> **should I have to replace the main_message or remove this line form the code PULL_REQUEST_BRANCH_INFO_TEMPLATE = "from `{target}` to `{base}`" or should I have to delete these four all code including the if conditions to fix this problem ?** Please Guide me its my first time.

The goal is to stop including the text "from `…` to `…`" in the output. You should first make sure you have your development environment set up, and that you can reproduce the wrong behavior where it includes that text. Then make changes to the code mentioned above, and confirm that what you do causes it to stop having that behavior. See the [Zulip contributing guide](https://zulip.readthedocs.io/en/latest/contributing/contributing.html) for how to get help on any of that.

@gnprice  should I proceed for the PR?
See our guide to picking an issue to work on:
https://zulip.readthedocs.io/en/latest/contributing/contributing.html#picking-an-issue-to-work-on

If you have questions, better to ask them [in chat](https://zulip.com/development-community/) — more people will be able to answer there, and it's a better place for discussions anyway.
@zulipbot claim
@zulipbot claim

@Aryanryn09 This issue cannot be claimed, as someone else is already working on it. Please see our [contributor guide](https://zulip.readthedocs.io/en/latest/overview/contributing.html#your-first-codebase-contribution) for advice on finding an issue to work on. Thanks!


Resolving patch:
diff --git a/zerver/webhooks/github/view.py b/zerver/webhooks/github/view.py
--- a/zerver/webhooks/github/view.py
+++ b/zerver/webhooks/github/view.py
@@ -73,13 +73,18 @@ def get_opened_or_update_pull_request_body(helper: Helper) -> str:
     changes = payload.get("changes", {})
     if "body" in changes or action == "opened":
         description = pull_request["body"].tame(check_none_or(check_string))
+    target_branch = None
+    base_branch = None
+    if action == "opened" or action == "merged":
+        target_branch = pull_request["head"]["label"].tame(check_string)
+        base_branch = pull_request["base"]["label"].tame(check_string)
 
     return get_pull_request_event_message(
         get_sender_name(payload),
         action,
         pull_request["html_url"].tame(check_string),
-        target_branch=pull_request["head"]["ref"].tame(check_string),
-        base_branch=pull_request["base"]["ref"].tame(check_string),
+        target_branch=target_branch,
+        base_branch=base_branch,
         message=description,
         assignee=assignee,
         number=pull_request["number"].tame(check_int),


Test patch:
diff --git a/zerver/webhooks/github/tests.py b/zerver/webhooks/github/tests.py
--- a/zerver/webhooks/github/tests.py
+++ b/zerver/webhooks/github/tests.py
@@ -157,12 +157,12 @@ def test_member_msg(self) -> None:
         self.check_webhook("member", TOPIC_REPO, expected_message)
 
     def test_pull_request_opened_msg(self) -> None:
-        expected_message = "baxterthehacker opened [PR #1](https://github.com/baxterthehacker/public-repo/pull/1) from `changes` to `master`:\n\n~~~ quote\nThis is a pretty simple change that we need to pull into master.\n~~~"
+        expected_message = "baxterthehacker opened [PR #1](https://github.com/baxterthehacker/public-repo/pull/1) from `baxterthehacker:changes` to `baxterthehacker:master`:\n\n~~~ quote\nThis is a pretty simple change that we need to pull into master.\n~~~"
         self.check_webhook("pull_request__opened", TOPIC_PR, expected_message)
 
     def test_pull_request_opened_with_preassigned_assignee_msg(self) -> None:
         expected_topic = "Scheduler / PR #4 Improve README"
-        expected_message = "eeshangarg opened [PR #4](https://github.com/eeshangarg/Scheduler/pull/4) (assigned to eeshangarg) from `improve-readme-2` to `master`."
+        expected_message = "eeshangarg opened [PR #4](https://github.com/eeshangarg/Scheduler/pull/4) (assigned to eeshangarg) from `eeshangarg:improve-readme-2` to `eeshangarg:master`."
         self.check_webhook(
             "pull_request__opened_with_preassigned_assignee", expected_topic, expected_message
         )
@@ -170,11 +170,11 @@ def test_pull_request_opened_with_preassigned_assignee_msg(self) -> None:
     def test_pull_request_opened_msg_with_custom_topic_in_url(self) -> None:
         self.url = self.build_webhook_url(topic="notifications")
         expected_topic = "notifications"
-        expected_message = "baxterthehacker opened [PR #1 Update the README with new information](https://github.com/baxterthehacker/public-repo/pull/1) from `changes` to `master`:\n\n~~~ quote\nThis is a pretty simple change that we need to pull into master.\n~~~"
+        expected_message = "baxterthehacker opened [PR #1 Update the README with new information](https://github.com/baxterthehacker/public-repo/pull/1) from `baxterthehacker:changes` to `baxterthehacker:master`:\n\n~~~ quote\nThis is a pretty simple change that we need to pull into master.\n~~~"
         self.check_webhook("pull_request__opened", expected_topic, expected_message)
 
     def test_pull_request_synchronized_msg(self) -> None:
-        expected_message = "baxterthehacker updated [PR #1](https://github.com/baxterthehacker/public-repo/pull/1) from `changes` to `master`."
+        expected_message = "baxterthehacker updated [PR #1](https://github.com/baxterthehacker/public-repo/pull/1)."
         self.check_webhook("pull_request__synchronized", TOPIC_PR, expected_message)
 
     def test_pull_request_closed_msg(self) -> None:
@@ -282,15 +282,17 @@ def test_push_tag_msg(self) -> None:
         self.check_webhook("push__tag", TOPIC_REPO, expected_message)
 
     def test_pull_request_edited_msg(self) -> None:
-        expected_message = "baxterthehacker edited [PR #1](https://github.com/baxterthehacker/public-repo/pull/1) from `changes` to `master`."
+        expected_message = (
+            "baxterthehacker edited [PR #1](https://github.com/baxterthehacker/public-repo/pull/1)."
+        )
         self.check_webhook("pull_request__edited", TOPIC_PR, expected_message)
 
     def test_pull_request_edited_with_body_change(self) -> None:
-        expected_message = "cozyrohan edited [PR #1](https://github.com/cozyrohan/public-repo/pull/1) from `issue-#1` to `main`:\n\n~~~ quote\nPR EDITED\n~~~"
+        expected_message = "cozyrohan edited [PR #1](https://github.com/cozyrohan/public-repo/pull/1):\n\n~~~ quote\nPR EDITED\n~~~"
         self.check_webhook("pull_request__edited_with_body_change", TOPIC_PR, expected_message)
 
     def test_pull_request_synchronized_with_body(self) -> None:
-        expected_message = "baxterthehacker updated [PR #1](https://github.com/baxterthehacker/public-repo/pull/1) from `changes` to `master`."
+        expected_message = "baxterthehacker updated [PR #1](https://github.com/baxterthehacker/public-repo/pull/1)."
         self.check_webhook("pull_request__synchronized_with_body", TOPIC_PR, expected_message)
 
     def test_pull_request_assigned_msg(self) -> None: