Allow defining todoist project for org rather than repo

This commit is contained in:
Jake Howard 2019-02-20 12:19:12 +00:00
parent a76a1299d3
commit 7cd7c4685c
Signed by: jake
GPG key ID: 57AFB45680EDD477
4 changed files with 60 additions and 15 deletions

View file

@ -4,11 +4,12 @@ from typing import Dict
from github import Issue
from actioner.clients import github, todoist
from actioner.utils import get_todoist_project_from_repo
REPOS = {
'srobo/tasks': 2190856871,
'srobo/core-team-minutes': 2190856871
}
REPOS = frozenset([
'srobo/tasks',
'srobo/core-team-minutes'
])
LABEL_TO_STATUS = {
'must have': 4,
@ -50,7 +51,8 @@ def todoist_assigned_issues():
me = github.get_user()
todoist.projects.sync()
todoist.items.sync()
for repo_name, project_id in REPOS.items():
for repo_name in REPOS:
project_id = get_todoist_project_from_repo(repo_name)
existing_tasks = {item['id']: item['content'] for item in todoist.state['items'] if item['project_id'] == project_id}
repo = github.get_repo(repo_name)
for issue in repo.get_issues(assignee=me.login, state='all'):

View file

@ -0,0 +1,17 @@
from typing import Dict, Optional
GH_REPO_TO_TODOIST = {
} # type: Dict[str, int]
GH_ORG_TO_TODOIST = {
'srobo': 2190856871
} # type: Dict[str, int]
def get_todoist_project_from_repo(repo_name: str) -> Optional[int]:
repo_id = GH_REPO_TO_TODOIST.get(repo_name)
if repo_id is not None:
return repo_id
org = repo_name.split('/')[0]
return GH_ORG_TO_TODOIST.get(org)

View file

@ -1,12 +1,12 @@
from collections import namedtuple
from actioner.clients import github, todoist
from actioner.scheduler.todoist_assigned_issues import (
REPOS,
get_existing_task,
get_issue_link,
issue_to_task_name,
)
from actioner.utils import get_todoist_project_from_repo
from tests import BaseTestCase
FakeIssue = namedtuple('FakeIssue', ['number', 'html_url', 'title'])
@ -29,15 +29,9 @@ class IssueTaskNameTestCase(BaseTestCase):
class ConfigurationTestCase(BaseTestCase):
def test_repos_exist(self):
for repo in REPOS.keys():
github.get_repo(repo)
def test_projects_exist(self):
todoist.projects.sync()
project_ids = {project['id'] for project in todoist.state['projects']}
for project_id in REPOS.values():
self.assertIn(project_id, project_ids)
def test_repo_is_known(self):
for repo in REPOS:
self.assertIsNotNone(get_todoist_project_from_repo(repo))
class ExistingTaskTestCase(BaseTestCase):

View file

@ -0,0 +1,32 @@
from actioner.clients import github, todoist
from actioner.utils import (
GH_ORG_TO_TODOIST,
GH_REPO_TO_TODOIST,
get_todoist_project_from_repo,
)
from tests import BaseTestCase
class TodoistProjectToRepoTestCase(BaseTestCase):
def test_repos_exist(self):
for repo_name in GH_REPO_TO_TODOIST.keys():
github.get_repo(repo_name)
def test_gets_correct_project(self):
for repo_name, project_id in GH_REPO_TO_TODOIST.items():
self.assertEqual(get_todoist_project_from_repo(repo_name), project_id)
def test_gets_correct_project_for_org(self):
for org_name, project_id in GH_ORG_TO_TODOIST.items():
self.assertEqual(get_todoist_project_from_repo("{}/test_repo".format(org_name)), project_id)
def test_organization_exists(self):
for org in GH_ORG_TO_TODOIST.keys():
github.get_organization(org)
def test_project_exists(self):
project_ids = set(GH_ORG_TO_TODOIST.values()).union(GH_REPO_TO_TODOIST.values())
todoist.projects.sync()
todoist_project_ids = {project['id'] for project in todoist.state['projects']}
for project in project_ids:
self.assertIn(project, todoist_project_ids)