Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

integrations/ClickUp: Add ClickUp integration script. #824

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

PieterCK
Copy link
Collaborator

@PieterCK PieterCK commented Apr 1, 2024

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 PieterCK force-pushed the issue-26529-clickup-integration branch 2 times, most recently from 48020ab to 2e94184 Compare April 3, 2024 12:17
@PieterCK PieterCK force-pushed the issue-26529-clickup-integration branch 5 times, most recently from fd31255 to 070853e Compare April 13, 2024 15:34
@PieterCK
Copy link
Collaborator Author

@zulipbot add "buddy review"

@zulipbot
Copy link
Member

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

@PieterCK
Copy link
Collaborator Author

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

Copy link

@sbansal1999 sbansal1999 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PieterCK I did a review on the main script file, and have left some comments on that.

I will review the test file as well as the documentation soon.

zulip/integrations/clickup/zulip_clickup.py Outdated Show resolved Hide resolved
zulip/integrations/clickup/zulip_clickup.py Outdated Show resolved Hide resolved
zulip/integrations/clickup/zulip_clickup.py Outdated Show resolved Hide resolved
zulip/integrations/clickup/zulip_clickup.py Outdated Show resolved Hide resolved
zulip/integrations/clickup/zulip_clickup.py Outdated Show resolved Hide resolved
zulip/integrations/clickup/zulip_clickup.py Outdated Show resolved Hide resolved
zulip/integrations/clickup/zulip_clickup.py Outdated Show resolved Hide resolved
zulip/integrations/clickup/zulip_clickup.py Outdated Show resolved Hide resolved
zulip/integrations/clickup/zulip_clickup.py Outdated Show resolved Hide resolved
zulip/integrations/clickup/zulip_clickup.py Outdated Show resolved Hide resolved
Copy link

@sbansal1999 sbansal1999 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PieterCK I have left some comments for the remaining files as well.

Let me know if there are any questions that you have.

zulip/integrations/clickup/test_zulip_clickup.py Outdated Show resolved Hide resolved
zulip/integrations/clickup/test_zulip_clickup.py Outdated Show resolved Hide resolved
zulip/integrations/clickup/test_zulip_clickup.py Outdated Show resolved Hide resolved
zulip/integrations/clickup/test_zulip_clickup.py Outdated Show resolved Hide resolved
zulip/integrations/clickup/test_zulip_clickup.py Outdated Show resolved Hide resolved
zulip/integrations/clickup/test_zulip_clickup.py Outdated Show resolved Hide resolved
zulip/integrations/clickup/README.md Outdated Show resolved Hide resolved
@PieterCK
Copy link
Collaborator Author

PieterCK commented Aug 9, 2024

@zulipbot add "mentor review"

@zulipbot
Copy link
Member

zulipbot commented Aug 9, 2024

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

@PieterCK PieterCK force-pushed the issue-26529-clickup-integration branch 2 times, most recently from 086d6e7 to 3e848b1 Compare August 9, 2024 14:30
@PieterCK
Copy link
Collaborator Author

PieterCK commented Aug 9, 2024

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

@PieterCK PieterCK force-pushed the issue-26529-clickup-integration branch 3 times, most recently from 4eefee5 to 2fa6bd7 Compare August 10, 2024 13:25
@PieterCK
Copy link
Collaborator Author

PieterCK commented Aug 10, 2024

@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

$ python zulip_clickup.py --clickup-team-id <clickup_team_id> \
--clickup-client-id <clickup_client_id> \
--clickup-client-secret <clickup_client_secret> \
--zulip-webhook-url "GENERATED_WEBHOOK_URL"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the "GENERATED_WEBHOOK_URL" to match the existing format.

Suggested change
--zulip-webhook-url "GENERATED_WEBHOOK_URL"
--zulip-webhook-url <zulip_webhook_url>

@PieterCK PieterCK force-pushed the issue-26529-clickup-integration branch 2 times, most recently from 2db6547 to cb86d35 Compare August 19, 2024 03:38
@PieterCK
Copy link
Collaborator Author

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

$ python zulip_clickup.py --clickup-team-id <clickup_team_id> \
--clickup-client-id <clickup_client_id> \
--clickup-client-secret <clickup_client_secret> \
--zulip-webhook-url "<zulip_webhook_url>"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quotes can be removed here.

Suggested change
--zulip-webhook-url "<zulip_webhook_url>"
--zulip-webhook-url <zulip_webhook_url>

Copy link
Collaborator Author

@PieterCK PieterCK Sep 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the webhook URL, we have to use quotes so it's registered as a string. Without them, the command will run in the background due to the ampersand (&) in the URL. This is also the case for the Trello integration script.

I totally had a great time debugging that the first time around 😃 😃

https://phoenixnap.com/kb/linux-run-command-background

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh the ampersand will mess things up, thanks for the clarification.

@sbansal1999
Copy link

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

Thanks!

@PieterCK
Copy link
Collaborator Author

PieterCK commented Sep 10, 2024

@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:

Add a python script to help integrate Zulip
with Clickup.

Urlopen is used instead of the usual requests
library inorder to make the script standalone.

Fixes zulip#26529
@PieterCK PieterCK force-pushed the issue-26529-clickup-integration branch from cb86d35 to cce823e Compare September 11, 2024 06:42
@sbansal1999
Copy link

LGTM. Thanks for working on this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ClickUp integration
3 participants