Skip to content
This repository has been archived by the owner on Oct 20, 2021. It is now read-only.

Commit

Permalink
Add comment check and cleanup script
Browse files Browse the repository at this point in the history
  • Loading branch information
j-martin committed Oct 29, 2018
1 parent c7a86f4 commit f556b5b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
31 changes: 31 additions & 0 deletions extra/cleanup_comments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import argparse

import keyring

from clubhouse import ClubhouseClient


def delete_comment(start, end, message):
global story_id, comment
c = ClubhouseClient(keyring.get_password('alloy', 'clubhouse'))
for story_id in range(start, end):
print(f"Checking story {story_id}")
comments = c.get('stories', story_id).get('comments')
if not comments:
continue
for comment in comments:
if comment['text'].startswith(message):
print(f"Deleting comment {comment['id']} from story {story_id}")
c.delete("stories", story_id, 'comments', comment['id'])


if __name__ == '__main__':
parser = argparse.ArgumentParser(description="")
parser.add_argument('start', help="First story id to check")
parser.add_argument('end', help="Last story id to check")
parser.add_argument('message',
help="Last story id to check",
default='The task moved to https://app.clubhouse.io/')
args = parser.parse_args()

delete_comment(args.start, args.end, args.message)
16 changes: 9 additions & 7 deletions importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import mimetypes
import sys
import tempfile
from os import path
from pprint import pformat
from typing import Dict, List, Union, TypeVar

Expand Down Expand Up @@ -37,6 +36,8 @@


class Importer(object):
move_message = 'The task moved to '

def __init__(self, args):
asana.Client.DEFAULT_OPTIONS['page_size'] = 100
self.asana = asana.Client.access_token(
Expand All @@ -57,10 +58,10 @@ def __init__(self, args):

def import_project(self):
if self.commit:
logger.info('Commit mode enabled. Story(ies) will be created and Tasks will modified.')
logger.info('Commit mode enabled. Stories will be created and Tasks will modified.')
else:
logger.info(
'Preview mode enabled. Story(ies) will be NOT created and Tasks will NOT modified.')
'Preview mode enabled. Stories will be NOT created and Tasks will NOT modified.')

for task in self.asana.tasks.find_by_project(self.asana_project_id):
self.import_task(task)
Expand Down Expand Up @@ -138,7 +139,8 @@ def build_comments(self, task: AsanaTask, subtasks: List[AsanaTask]) -> List[Clu
def _build_comments(self, task: AsanaTask) -> List[ClubhouseComment]:
return [self.build_comment(task, comment)
for comment in self.asana.stories.find_by_task(task['id'])
if comment['type'] != 'system']
if comment['type'] != 'system' and not comment['text'].startswith(
self.move_message)]

def get_requestor(self, task):
for story in self.asana.stories.find_by_task(task['id']):
Expand Down Expand Up @@ -288,7 +290,7 @@ def update_asana_task(self, task: AsanaTask, story: ClubhouseStory) -> None:
return

self.asana.tasks.add_comment(task['id'], {
'text': f"The task moved to {story['app_url']}"
'text': f"{self.move_message}{story['app_url']}"
})
self.asana.tasks.add_tag(task['id'], {'tag': self.asana_moved_tag_id})

Expand Down Expand Up @@ -328,13 +330,13 @@ def _setup_logging():


if __name__ == '__main__':
parser = argparse.ArgumentParser(description="")
parser = argparse.ArgumentParser(description="Imports Asana tasks as Clubhouse stories.")
parser.add_argument('--asana-api-key',
default='')
parser.add_argument('--asana-project-id',
help='Source project.')
parser.add_argument('--asana-moved-tag-id',
help='Tag to apply to moved tasks.')
help='Tag to apply to moved tasks. Must be created in advance.')
parser.add_argument('--asana-skip-moved-tag',
help='Do not tag the task at the end.',
action='store_true')
Expand Down

0 comments on commit f556b5b

Please sign in to comment.