add jira support

This commit is contained in:
Aleksander Cynarski 2019-08-08 11:08:24 +02:00
parent c23b845605
commit 272970c280
3 changed files with 48 additions and 6 deletions

16
README.md Normal file
View File

@ -0,0 +1,16 @@
# Todoist integrator
## Install
```
pip3 install -r requirements.txt
```
## Jira intergration
Set system env:
```
export JIRA_API_TOKEN=<token>
```

View File

@ -3,6 +3,9 @@ gitea_url = https://git.cynarski.pl
gitea_token = gitea_token =
todoist_login = todoist_login =
todoist_pass = todoist_pass =
jira_url =
jira_username =
[gitea_projects] [gitea_projects]
sCRM/apiServer = sCRM sCRM/apiServer = sCRM

View File

@ -8,6 +8,7 @@ import json
import configparser import configparser
import marshmallow.validate import marshmallow.validate
import re import re
import os
from dataclasses import field from dataclasses import field
from marshmallow_dataclass import dataclass from marshmallow_dataclass import dataclass
@ -16,12 +17,14 @@ from pytodoist import todoist
from pprint import pprint from pprint import pprint
from types import SimpleNamespace as Namespace from types import SimpleNamespace as Namespace
from jira import JIRA from jira import JIRA
from pprint import pprint
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read('./config.ini') config.read('./config.ini')
logging.basicConfig(stream=sys.stderr, level=logging.INFO, format='%(asctime)s %(levelname)s %(filename)s: %(message)s') logging.basicConfig(stream=sys.stderr, level=logging.INFO, format='%(asctime)s %(levelname)s %(filename)s: %(message)s')
logger = logging.getLogger("todoist-im") logger = logging.getLogger("todoist-im")
@dataclass @dataclass
class GiteaUser: class GiteaUser:
avatar_url: str avatar_url: str
@ -49,12 +52,36 @@ class GiteaIssue:
gitea = pytea.API(config['auth']['gitea_url'], token=config['auth']['gitea_token']) gitea = pytea.API(config['auth']['gitea_url'], token=config['auth']['gitea_token'])
todo = todoist.login(config['auth']['todoist_login'], config['auth']['todoist_pass']) todo = todoist.login(config['auth']['todoist_login'], config['auth']['todoist_pass'])
jiraOptions = {'server': config['auth']['jira_url']}
jira = JIRA(options=jiraOptions, basic_auth=(config['auth']['jira_username'], os.environ['JIRA_API_TOKEN'] ))
userJson = gitea.get("/user").json() userJson = gitea.get("/user").json()
user, _ = GiteaUser.Schema().load(userJson) user, _ = GiteaUser.Schema().load(userJson)
for jiraProject in config['jira_projects']:
logger.info("Jira.... " + jiraProject)
totdoistProject = config['jira_projects'][jiraProject]
for issue in jira.search_issues('project='+jiraProject.upper()+' and (assignee = currentUser() or assignee = unassigned) and status = "In Progress" and status = "To Do" '):
addTask = True
#print('{}: {} === {} ==== {} === {}'.format(issue.key, issue.fields.summary, issue.fields.status, totdoistProject, issue.fields.description))
todoProject = todo.get_project(totdoistProject)
tasks = todoProject.get_tasks()
for task in tasks:
if ("["+issue.key +"] "+ issue.fields.summary) == task.content:
logger.info("Task exists in todoist ... %r", issue.fields.summary)
addTask = False
if addTask:
logger.info("Adding ... %r", issue.fields.summary)
task = todoProject.add_task("["+issue.key +"] "+ issue.fields.summary)
task.add_note(config['auth']['jira_url']+'/browse/'+issue.key)
task.add_note("Description: "+str(issue.fields.description))
for giteaProject in config['gitea_projects']: for giteaProject in config['gitea_projects']:
logger.info("Scanning ... "+ config['auth']['gitea_url'] + giteaProject) logger.info("Scanning ... "+ config['auth']['gitea_url'] + "/" + giteaProject)
totdoistProject = config['gitea_projects'][giteaProject] totdoistProject = config['gitea_projects'][giteaProject]
issuesJson = json.loads(gitea.get("/repos/"+giteaProject.strip()+"/issues" , params={"state": "open", "page": 0}).text) issuesJson = json.loads(gitea.get("/repos/"+giteaProject.strip()+"/issues" , params={"state": "open", "page": 0}).text)
todoProject = todo.get_project(totdoistProject) todoProject = todo.get_project(totdoistProject)
@ -71,11 +98,7 @@ for giteaProject in config['gitea_projects']:
if addTask: if addTask:
pprint(addTask)
pprint(issue.title)
logger.info("Adding ... %r", issue.title) logger.info("Adding ... %r", issue.title)
task = todoProject.add_task(issue.title) task = todoProject.add_task(issue.title)
task.add_note(config['auth']['gitea_url']+giteaProject+"/issues/"+str(issue.number)) task.add_note(config['auth']['gitea_url']+giteaProject+"/issues/"+str(issue.number))