Skip to content

Commit

Permalink
Merge pull request #621 from pawamoy/add-state-and-closed-uda-to-github
Browse files Browse the repository at this point in the history
Complete tasks with end value, add state and closed UDAs to GitHub
  • Loading branch information
ralphbean authored Dec 3, 2018
2 parents 30e0fb2 + efce865 commit da6bdf1
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 8 deletions.
8 changes: 6 additions & 2 deletions bugwarrior/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,9 @@ def _bool_option(section, option, default):
send_notification(issue, 'Created', conf)

try:
tw.task_add(**issue)
new_task = tw.task_add(**issue)
if 'end' in issue and issue['end']:
tw.task_done(uuid=new_task['uuid'])
except TaskwarriorError as e:
log.exception("Unable to add task: %s" % e.stderr)

Expand All @@ -410,7 +412,9 @@ def _bool_option(section, option, default):
continue

try:
tw.task_update(issue)
_, updated_task = tw.task_update(issue)
if 'end' in issue and issue['end']:
tw.task_done(uuid=updated_task['uuid'])
except TaskwarriorError as e:
log.exception("Unable to modify task: %s" % e.stderr)

Expand Down
8 changes: 6 additions & 2 deletions bugwarrior/docs/services/github.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ included. To turn this off, set::
github.include_user_repos = False

If you happen to be working with a large number of projects, you
may want to pull issues from only a subset of your repositories. To
may want to pull issues from only a subset of your repositories. To
do that, you can use the ``github.include_repos`` option.

For example, if you would like to only pull-in issues from
Expand All @@ -60,7 +60,7 @@ this line to your service configuration::

Alternatively, if you have a particularly noisy repository, you can
instead choose to import all issues excepting it using the
``github.exclude_repos`` configuration option.
``github.exclude_repos`` configuration option.

In this example, ``noisy_repository`` is the repository you would
*not* like issues created for::
Expand Down Expand Up @@ -153,6 +153,8 @@ Provided UDA Fields
+---------------------+---------------------+---------------------+
| ``githubcreatedon`` | Created | Date & Time |
+---------------------+---------------------+---------------------+
| ``githubclosedon`` | Closed | Date & Time |
+---------------------+---------------------+---------------------+
| ``githubmilestone`` | Milestone | Text (string) |
+---------------------+---------------------+---------------------+
| ``githubnumber`` | Issue/PR # | Numeric |
Expand All @@ -171,3 +173,5 @@ Provided UDA Fields
+---------------------+---------------------+---------------------+
| ``githubnamespace`` | project namespace | Text (string) |
+---------------------+---------------------+---------------------+
| ``githubstate`` | Issue/PR state | Text (string) |
+---------------------+---------------------+---------------------+
21 changes: 17 additions & 4 deletions bugwarrior/services/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,15 @@ class GithubIssue(Issue):
BODY = 'githubbody'
CREATED_AT = 'githubcreatedon'
UPDATED_AT = 'githubupdatedat'
CLOSED_AT = 'githubclosedon'
MILESTONE = 'githubmilestone'
URL = 'githuburl'
REPO = 'githubrepo'
TYPE = 'githubtype'
NUMBER = 'githubnumber'
USER = 'githubuser'
NAMESPACE = 'githubnamespace'
STATE = 'githubstate'

UDAS = {
TITLE: {
Expand All @@ -150,6 +152,10 @@ class GithubIssue(Issue):
'type': 'date',
'label': 'Github Updated',
},
CLOSED_AT: {
'type': 'date',
'label': 'GitHub Closed',
},
MILESTONE: {
'type': 'string',
'label': 'Github Milestone',
Expand Down Expand Up @@ -178,6 +184,10 @@ class GithubIssue(Issue):
'type': 'string',
'label': 'Github Namespace',
},
STATE: {
'type': 'string',
'label': 'GitHub State',
}
}
UNIQUE_KEY = (URL, TYPE,)

Expand All @@ -198,16 +208,17 @@ def to_taskwarrior(self):
else:
priority = self.origin['default_priority']

created = self.record['created_at']
if created:
created = self.parse_date(self.record['created_at'])
created = self.parse_date(self.record.get('created_at'))
updated = self.parse_date(self.record.get('updated_at'))
closed = self.parse_date(self.record.get('closed_at'))

return {
'project': self.extra['project'],
'priority': priority,
'annotations': self.extra.get('annotations', []),
'tags': self.get_tags(),
'entry': created,
'end': closed,

self.URL: self.record['html_url'],
self.REPO: self.record['repo'],
Expand All @@ -218,8 +229,10 @@ def to_taskwarrior(self):
self.MILESTONE: milestone,
self.NUMBER: self.record['number'],
self.CREATED_AT: created,
self.UPDATED_AT: self.parse_date(self.record['updated_at']),
self.UPDATED_AT: updated,
self.CLOSED_AT: closed,
self.NAMESPACE: self.extra['namespace'],
self.STATE: self.record.get('state', '')
}

def get_tags(self):
Expand Down
4 changes: 4 additions & 0 deletions tests/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ def test_udas(self):
self.assertEqual(udas, [
u'uda.githubbody.label=Github Body',
u'uda.githubbody.type=string',
u'uda.githubclosedon.label=GitHub Closed',
u'uda.githubclosedon.type=date',
u'uda.githubcreatedon.label=Github Created',
u'uda.githubcreatedon.type=date',
u'uda.githubmilestone.label=Github Milestone',
Expand All @@ -157,6 +159,8 @@ def test_udas(self):
u'uda.githubnumber.type=numeric',
u'uda.githubrepo.label=Github Repo Slug',
u'uda.githubrepo.type=string',
u'uda.githubstate.label=GitHub State',
u'uda.githubstate.type=string',
u'uda.githubtitle.label=Github Title',
u'uda.githubtitle.type=string',
u'uda.githubtype.label=Github Type',
Expand Down
14 changes: 14 additions & 0 deletions tests/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
ARBITRARY_CREATED = (
datetime.datetime.utcnow() - datetime.timedelta(hours=1)
).replace(tzinfo=pytz.UTC, microsecond=0)
ARBITRARY_CLOSED = (
datetime.datetime.utcnow() - datetime.timedelta(minutes=30)
).replace(tzinfo=pytz.UTC, microsecond=0)
ARBITRARY_UPDATED = datetime.datetime.utcnow().replace(
tzinfo=pytz.UTC, microsecond=0)
ARBITRARY_ISSUE = {
Expand All @@ -27,8 +30,10 @@
'milestone': {'title': 'alpha'},
'labels': [{'name': 'bugfix'}],
'created_at': ARBITRARY_CREATED.isoformat(),
'closed_at': ARBITRARY_CLOSED.isoformat(),
'updated_at': ARBITRARY_UPDATED.isoformat(),
'repo': 'arbitrary_username/arbitrary_repo',
'state': 'closed'
}
ARBITRARY_EXTRA = {
'project': 'one',
Expand Down Expand Up @@ -71,17 +76,20 @@ def test_to_taskwarrior(self):
'annotations': [],
'tags': ['bugfix'],
'entry': ARBITRARY_CREATED,
'end': ARBITRARY_CLOSED,
issue.URL: ARBITRARY_ISSUE['html_url'],
issue.REPO: ARBITRARY_ISSUE['repo'],
issue.TYPE: ARBITRARY_EXTRA['type'],
issue.TITLE: ARBITRARY_ISSUE['title'],
issue.NUMBER: ARBITRARY_ISSUE['number'],
issue.UPDATED_AT: ARBITRARY_UPDATED,
issue.CREATED_AT: ARBITRARY_CREATED,
issue.CLOSED_AT: ARBITRARY_CLOSED,
issue.BODY: ARBITRARY_ISSUE['body'],
issue.MILESTONE: ARBITRARY_ISSUE['milestone']['title'],
issue.USER: ARBITRARY_ISSUE['user']['login'],
issue.NAMESPACE: 'arbitrary_username',
issue.STATE: 'closed',
}
actual_output = issue.to_taskwarrior()

Expand Down Expand Up @@ -124,8 +132,10 @@ def test_issues(self):
'annotations': [u'@arbitrary_login - Arbitrary comment.'],
'description': u'(bw)Is#10 - Hallo .. https://github.com/arbitrary_username/arbitrary_repo/pull/1',
'entry': ARBITRARY_CREATED,
'end': ARBITRARY_CLOSED,
'githubbody': u'Something',
'githubcreatedon': ARBITRARY_CREATED,
'githubclosedon': ARBITRARY_CLOSED,
'githubmilestone': u'alpha',
'githubnamespace': 'arbitrary_username',
'githubnumber': 10,
Expand All @@ -135,6 +145,7 @@ def test_issues(self):
'githubupdatedat': ARBITRARY_UPDATED,
'githuburl': u'https://github.com/arbitrary_username/arbitrary_repo/pull/1',
'githubuser': u'arbitrary_login',
'githubstate': u'closed',
'priority': 'M',
'project': 'arbitrary_repo',
'tags': []}
Expand Down Expand Up @@ -179,8 +190,10 @@ def test_issues(self):
'annotations': [u'@arbitrary_login - Arbitrary comment.'],
'description': u'(bw)Is#10 - Hallo .. https://github.com/arbitrary_username/arbitrary_repo/pull/1',
'entry': ARBITRARY_CREATED,
'end': ARBITRARY_CLOSED,
'githubbody': u'Something',
'githubcreatedon': ARBITRARY_CREATED,
'githubclosedon': ARBITRARY_CLOSED,
'githubmilestone': u'alpha',
'githubnamespace': 'arbitrary_username',
'githubnumber': 10,
Expand All @@ -190,6 +203,7 @@ def test_issues(self):
'githubupdatedat': ARBITRARY_UPDATED,
'githuburl': u'https://github.com/arbitrary_username/arbitrary_repo/pull/1',
'githubuser': u'arbitrary_login',
'githubstate': u'closed',
'priority': 'M',
'project': 'arbitrary_repo',
'tags': []}
Expand Down

0 comments on commit da6bdf1

Please sign in to comment.