Repository: zulip/zulip

Issue:
GitHub bot should leave out issue description text on "issue assigned" events
Here's an [example message](https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/zulip-flutter/near/1517324) from the GitHub bot:

> gnprice assigned [issue #21 Push PerAccountRoot under MaterialApp, into each individual page widget](https://github.com/zulip/zulip-flutter/issues/21) (assigned to gnprice):
>
> > This will let us have a single MaterialApp that can navigate between pages that are for different accounts, as well as pages like the login flow and account-switch UI that are for no particular account at all. That makes it a necessity for doing #11 in a reasonable way.
> >
> > One part of this will be to let the PerAccountRoots for a given account all point to a single PerAccountStore. That's this TODO from #20 which I just sent:
> > ```dart
> >   // TODO add a registry of [PerAccountStore]s, like the latter's of [MessageListView]
> >   //   That will allow us to have many [PerAccountRoot] widgets for a given
> >   //   account, e.g. at the top of each page; and to access server data from
> >   //   outside any [PerAccountRoot], e.g. for handling a notification.
> > ```
> > 
> > The other part to take care of will be arranging that the API we provide for ourselves to use when we're adding new routes, and navigating to routes, isn't too annoying or error-prone. I have some thoughts and we'll see how it looks after I experiment.

That would be about right for the "issue created" event. But this isn't that — it's the "issue assigned" event. The description — those multiple paragraphs of prose plus code — isn't something that is new or changed, or ever will be on this type of event. So it should be omitted.

In particular this event will commonly come immediately after the "issue created" event, which means the description gets posted twice in a row.

I don't know what the bot currently does on "PR assigned" events, but the same thing applies there: it should not include the PR description text.



Discussion:
Hello @zulip/server-integrations members, this issue was labeled with the "area: integrations" label, so you may want to check it out!

<!-- areaLabelAddition -->

@zulipbot claim
Welcome to Zulip, @AbhishekCS3459! We just sent you an invite to collaborate on this repository at https://github.com/zulip/zulip/invitations. Please accept this invite in order to claim this issue and begin a fun, rewarding experience contributing to Zulip!

Here's some tips to get you off to a good start:

- Join me on the [Zulip developers' server](https://chat.zulip.org), to get help, chat about this issue, and meet the other developers.
- [Unwatch this repository](https://help.github.com/articles/unwatching-repositories/), so that you don't get 100 emails a day.

As you work on this issue, you'll also want to refer to the [Zulip code contribution guide](https://zulip.readthedocs.io/en/latest/contributing/index.html), as well as the rest of the developer documentation on that site.

See you on the other side (that is, the pull request side)!

@gnprice can you please describe the steps to reproduce this and also what you are expecting from it?
> Here's an [example message](https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/zulip-flutter/near/1517324) from the GitHub bot:
> 
> > gnprice assigned [issue #21 Push PerAccountRoot under MaterialApp, into each individual page widget](https://github.com/zulip/zulip-flutter/issues/21) (assigned to gnprice):
> > > This will let us have a single MaterialApp that can navigate between pages that are for different accounts, as well as pages like the login flow and account-switch UI that are for no particular account at all. That makes it a necessity for doing #11 in a reasonable way.
> > > One part of this will be to let the PerAccountRoots for a given account all point to a single PerAccountStore. That's this TODO from #20 which I just sent:
> > > ```dart
> > >   // TODO add a registry of [PerAccountStore]s, like the latter's of [MessageListView]
> > >   //   That will allow us to have many [PerAccountRoot] widgets for a given
> > >   //   account, e.g. at the top of each page; and to access server data from
> > >   //   outside any [PerAccountRoot], e.g. for handling a notification.
> > > ```
> > > 
> > > 
> > >     
> > >       
> > >     
> > > 
> > >       
> > >     
> > > 
> > >     
> > >   
> > > The other part to take care of will be arranging that the API we provide for ourselves to use when we're adding new routes, and navigating to routes, isn't too annoying or error-prone. I have some thoughts and we'll see how it looks after I experiment.
> 
> That would be about right for the "issue created" event. But this isn't that — it's the "issue assigned" event. The description — those multiple paragraphs of prose plus code — isn't something that is new or changed, or ever will be on this type of event. So it should be omitted.
> 
> In particular this event will commonly come immediately after the "issue created" event, which means the description gets posted twice in a row.
> 
> I don't know what the bot currently does on "PR assigned" events, but the same thing applies there: it should not include the PR description text.
@gnprice Could You Please let me know what you expect from it , so that I can work upon it.

@zulipbot help wanted

The issue describes the desired behavior:

> The description — those multiple paragraphs of prose plus code — […] should be omitted.

For how to reproduce the issue, the `#development help` or `#integrations` streams would be good places to ask.

@AbhishekCS3459 You have been unassigned from this issue because you have not made any updates for over 14 days. Please feel free to reclaim the issue if you decide to pick up again. Thanks!

Yes it will be over tomorrow 

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
@@ -159,17 +159,27 @@ def get_issue_body(helper: Helper) -> str:
     include_title = helper.include_title
     action = payload["action"].tame(check_string)
     issue = payload["issue"]
-    assignee = issue["assignee"]
-    return get_issue_event_message(
+    has_assignee = "assignee" in payload
+    base_message = get_issue_event_message(
         user_name=get_sender_name(payload),
         action=action,
         url=issue["html_url"].tame(check_string),
         number=issue["number"].tame(check_int),
-        message=issue["body"].tame(check_none_or(check_string)),
-        assignee=assignee["login"].tame(check_string) if assignee else None,
+        message=None
+        if action in ("assigned", "unassigned")
+        else issue["body"].tame(check_none_or(check_string)),
         title=issue["title"].tame(check_string) if include_title else None,
     )
 
+    if has_assignee:
+        stringified_assignee = payload["assignee"]["login"].tame(check_string)
+        if action == "assigned":
+            return f"{base_message[:-1]} to {stringified_assignee}."
+        elif action == "unassigned":
+            return base_message.replace("unassigned", f"unassigned {stringified_assignee} from")
+
+    return base_message
+
 
 def get_issue_comment_body(helper: Helper) -> str:
     payload = helper.payload


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
@@ -142,6 +142,28 @@ def test_issue_msg_with_custom_topic_in_url(self) -> None:
         expected_message = "baxterthehacker opened [issue #2 Spelling error in the README file](https://github.com/baxterthehacker/public-repo/issues/2):\n\n~~~ quote\nIt looks like you accidentally spelled 'commit' with two 't's.\n~~~"
         self.check_webhook("issues", expected_topic, expected_message)
 
+    def test_issue_assigned(self) -> None:
+        expected_message = "sbansal1999 assigned [issue #7](https://github.com/sbansal1999/testing-gh/issues/7) to sbansal1999."
+        expected_topic = "testing-gh / issue #7 Sample Issue testing something"
+        self.check_webhook("issues__assigned", expected_topic, expected_message)
+
+    def test_issue_assigned_with_custom_topic_in_url(self) -> None:
+        self.url = self.build_webhook_url(topic="notifications")
+        expected_topic = "notifications"
+        expected_message = "sbansal1999 assigned [issue #7 Sample Issue testing something](https://github.com/sbansal1999/testing-gh/issues/7) to sbansal1999."
+        self.check_webhook("issues__assigned", expected_topic, expected_message)
+
+    def test_issue_unassigned(self) -> None:
+        expected_message = "sbansal1999 unassigned sbansal1999 from [issue #9](https://github.com/sbansal1999/testing-gh/issues/9)."
+        expected_topic = "testing-gh / issue #9 idk man"
+        self.check_webhook("issues__unassigned", expected_topic, expected_message)
+
+    def test_issue_unassigned_with_custom_topic_in_url(self) -> None:
+        self.url = self.build_webhook_url(topic="notifications")
+        expected_topic = "notifications"
+        expected_message = "sbansal1999 unassigned sbansal1999 from [issue #9 idk man](https://github.com/sbansal1999/testing-gh/issues/9)."
+        self.check_webhook("issues__unassigned", expected_topic, expected_message)
+
     def test_membership_msg(self) -> None:
         expected_message = (
             "baxterthehacker added [kdaigle](https://github.com/kdaigle) to the Contractors team."