python-zulip-api icon indicating copy to clipboard operation
python-zulip-api copied to clipboard

integrations/ClickUp: Add ClickUp integration script.

Open PieterCK opened this issue 11 months ago • 11 comments

This script is required for the integration of ClickUp with Zulip. It is intended to be downloaded and run locally on user terminal What the script does:

  • Request ClickUp's API KEY,
  • Register new webhooks through their API endpoint.
  • Enables the user to choose which event to be received.
  • Deletes old Zulip related ClickUp webhooks when running the script multiple times.
  • Appends ClickUp API KEY and team ID to the registered Zulip webhook URL to be used for callbacks.

Fixes: Issue Main ClickUp integration: PR CZO: thread

  • zulip_clickup.py walkthrough:
# execute zulip_clickup.py command:
python3 zulip_clickup.py --clickup-team-id 25567147 --clickup-client-id V0COEU8DRNOM1J5KG6SDGIC2CQQFQOLP --clickup-client-secret GLTEHI5VC8IO83FTBV8OOQHLC836RYTWLGECLDONOR03YZB4EDIW54MYF6G9PEVH --zulip-webhook-url "https://chat.zulip.org"

Screencast from 08-19-2024 10:34:01 AM.webm

Note:

  • I ignore Ruff raising S310 because I believe it's still an open issue

PieterCK avatar Apr 01 '24 08:04 PieterCK

@zulipbot add "buddy review"

PieterCK avatar Jun 10 '24 04:06 PieterCK

ERROR: Label "buddy review" does not exist and was thus not added to this pull request.

zulipbot avatar Jun 10 '24 04:06 zulipbot

@kennethnrk I think you can also take a look at this one, thank you!

PieterCK avatar Jun 10 '24 04:06 PieterCK

@zulipbot add "mentor review"

PieterCK avatar Aug 09 '24 12:08 PieterCK

ERROR: Label "mentor review" does not exist and was thus not added to this pull request.

zulipbot avatar Aug 09 '24 12:08 zulipbot

Pushed some updates to address review. Will continue to update the PR in the coming days

PieterCK avatar Aug 09 '24 14:08 PieterCK

@sbansal1999 Thanks for the review! I've updated the PR to address your feedback. Most of the changes are self-explanatory and don't require much explanation. For the ones that do, I've pointed them out in the comments where the review is.The two failing tests is a known issue with no solid fix yet. #826 has a couple of commits that can plug off that issue temporarily once merged

PieterCK avatar Aug 10 '24 13:08 PieterCK

@sbansal1999 hey I've updated the PR as per what we've discussed. please do check them out again, thanks

PieterCK avatar Aug 19 '24 04:08 PieterCK

@PieterCK Please take a look at this comment, after that is resolved I feel we can move this PR to the next stage.

Thanks!

sbansal1999 avatar Aug 30 '24 18:08 sbansal1999

@PieterCK Please take a look at this comment, after that is resolved I feel we can move this PR to the next stage.

Thanks!

Updated the PR! Thank you

Diff:

+++ b/zulip/integrations/clickup/zulip_clickup.py
@@ -14,11 +14,11 @@ from urllib.parse import parse_qs, urlencode, urljoin, urlparse, urlunparse
 from urllib.request import Request, urlopen
 
 EVENT_CHOICES: Dict[str, Tuple[str, Tuple[str, ...]]] = {
-    "1": ("task", ("taskCreated", "taskUpdated", "taskDeleted")),
-    "2": ("list", ("listCreated", "listUpdated", "listDeleted")),
-    "3": ("folder", ("folderCreated", "folderUpdated", "folderDeleted")),
-    "4": ("space", ("spaceCreated", "spaceUpdated", "spaceDeleted")),
-    "5": ("goal", ("goalCreated", "goalUpdated", "goalDeleted")),
+    "task": ("taskCreated", "taskUpdated", "taskDeleted"),
+    "list": ("listCreated", "listUpdated", "listDeleted"),
+    "folder": ("folderCreated", "folderUpdated", "folderDeleted"),
+    "space": ("spaceCreated", "spaceUpdated", "spaceDeleted"),
+    "goal": ("goalCreated", "goalUpdated", "goalDeleted"),
 }
 
 
@@ -42,9 +42,8 @@ def process_url(input_url: str, base_url: str) -> str:
 
 def get_event_choices_string() -> str:
     choices_string = ""
-    for key, value in EVENT_CHOICES.items():
-        event, _ = value
-        choices_string += f"    {key} = {event}\n"
+    for index, key in enumerate(EVENT_CHOICES):
+        choices_string += f"    {index+1} = {key}\n"
     return choices_string
 
 
@@ -207,6 +206,7 @@ related to task, list and folder: 1,2,3
     )
     querying_user_input: bool = True
     selected_events: List[str] = []
+    code_to_event_dict = {i + 1: key for i, key in enumerate(EVENT_CHOICES)}
 
     while querying_user_input:
         input_codes_list: str = input("EVENT CODE(s): ")
@@ -215,12 +215,13 @@ related to task, list and folder: 1,2,3
         input_is_valid: bool = len(user_input) > 0
         exhausted_options: List[str] = []
         if "*" in input_codes_list:
-            all_events = [event for _, events in EVENT_CHOICES.values() for event in events]
+            all_events = [event for events in EVENT_CHOICES.values() for event in events]
             return all_events
 
         for event_code in user_input:
-            if event_code in EVENT_CHOICES and event_code not in exhausted_options:
-                _, events = EVENT_CHOICES[event_code]
+            event = code_to_event_dict.get(int(event_code))
+            if event in EVENT_CHOICES and event_code not in exhausted_options:
+                events = EVENT_CHOICES[event]
                 selected_events += events
                 exhausted_options.append(event_code)
             else:

PieterCK avatar Sep 10 '24 14:09 PieterCK

LGTM. Thanks for working on this one.

sbansal1999 avatar Sep 11 '24 10:09 sbansal1999