Skip to content

Commit

Permalink
Adding draft status for GH and Gerrit (#1035)
Browse files Browse the repository at this point in the history
* Adding new UDAs to github and gerrit

These show the draft/wip status for both services

Signed-off-by: Jorge Gallegos <kad@blegh.net>

* Updating test cases to account for new UDAs

Signed-off-by: Jorge Gallegos <kad@blegh.net>

* wip/draft should be a numeric, make it like gitlab

Signed-off-by: Jorge Gallegos <kad@blegh.net>

* add tests for draft/wip status and update UDA

Signed-off-by: Jorge Gallegos <kad@blegh.net>

---------

Signed-off-by: Jorge Gallegos <kad@blegh.net>
  • Loading branch information
thekad committed Mar 2, 2024
1 parent f6e9dc3 commit 1096ed6
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 12 deletions.
12 changes: 12 additions & 0 deletions bugwarrior/services/gerrit.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class GerritIssue(Issue):
FOREIGN_ID = 'gerritid'
BRANCH = 'gerritbranch'
TOPIC = 'gerrittopic'
STATUS = 'gerritstatus'
WORK_IN_PROGRESS = 'gerritwip'

UDAS = {
SUMMARY: {
Expand All @@ -46,6 +48,14 @@ class GerritIssue(Issue):
'type': 'string',
'label': 'Gerrit Topic',
},
STATUS: {
'type': 'string',
'label': 'Gerrit Status',
},
WORK_IN_PROGRESS: {
'type': 'numeric',
'label': 'Gerrit Work in Progress',
},
}
UNIQUE_KEY = (URL, )

Expand All @@ -61,6 +71,8 @@ def to_taskwarrior(self):
self.SUMMARY: self.record['subject'],
self.BRANCH: self.record['branch'],
self.TOPIC: self.record.get('topic', 'notopic'),
self.STATUS: self.record.get('status', ''),
self.WORK_IN_PROGRESS: int(self.record.get('work_in_progress', 0)),
}

def get_default_description(self):
Expand Down
10 changes: 8 additions & 2 deletions bugwarrior/services/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ class GithubIssue(Issue):
USER = 'githubuser'
NAMESPACE = 'githubnamespace'
STATE = 'githubstate'
DRAFT = 'githubdraft'

UDAS = {
TITLE: {
Expand Down Expand Up @@ -260,7 +261,11 @@ class GithubIssue(Issue):
STATE: {
'type': 'string',
'label': 'GitHub State',
}
},
DRAFT: {
'type': 'numeric',
'label': 'GitHub Draft',
},
}
UNIQUE_KEY = (URL, TYPE,)

Expand Down Expand Up @@ -293,7 +298,8 @@ def to_taskwarrior(self):
self.UPDATED_AT: updated,
self.CLOSED_AT: closed,
self.NAMESPACE: self.extra['namespace'],
self.STATE: self.record.get('state', '')
self.STATE: self.record.get('state', ''),
self.DRAFT: int(self.record.get('draft', 0)),
}

def get_tags(self):
Expand Down
2 changes: 2 additions & 0 deletions tests/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ def test_udas(self):
'uda.githubclosedon.type=date',
'uda.githubcreatedon.label=Github Created',
'uda.githubcreatedon.type=date',
'uda.githubdraft.label=GitHub Draft',
'uda.githubdraft.type=numeric',
'uda.githubmilestone.label=Github Milestone',
'uda.githubmilestone.type=string',
'uda.githubnamespace.label=Github Namespace',
Expand Down
45 changes: 36 additions & 9 deletions tests/test_gerrit.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,21 @@ class TestGerritIssue(AbstractServiceTest, ServiceTest):
'_number': 1,
'branch': 'master',
'topic': 'test-topic',
'status': 'new',
'work_in_progress': False,
'subject': 'this is a title',
'messages': [{'author': {'username': 'Iam Author'},
'message': 'this is a message',
'_revision_number': 1}],
}

extra = {
'annotations': [
# TODO - test annotations?
],
'url': 'https://one.com/#/c/1/',
}

def setUp(self):
super().setUp()

Expand All @@ -36,29 +45,45 @@ def setUp(self):
self.service = self.get_mock_service(GerritService)

def test_to_taskwarrior(self):
extra = {
'annotations': [
# TODO - test annotations?
],
'url': 'this is a url',
}

issue = self.service.get_issue_for_record(self.record, extra)
issue = self.service.get_issue_for_record(self.record, self.extra)
actual = issue.to_taskwarrior()
expected = {
'annotations': [],
'priority': 'M',
'project': 'nova',
'gerritid': 1,
'gerritstatus': 'new',
'gerritsummary': 'this is a title',
'gerriturl': 'this is a url',
'gerriturl': 'https://one.com/#/c/1/',
'gerritbranch': 'master',
'gerrittopic': 'test-topic',
'gerritwip': 0,
'tags': [],
}

self.assertEqual(actual, expected)

def test_work_in_progress(self):
wip_record = dict(self.record) # make a copy of the dict
wip_record['work_in_progress'] = True
issue = self.service.get_issue_for_record(wip_record, self.extra)

expected = {
'annotations': [],
'description': '(bw)PR#1 - this is a title .. https://one.com/#/c/1/',
'gerritid': 1,
'gerritsummary': 'this is a title',
'gerritstatus': 'new',
'gerriturl': 'https://one.com/#/c/1/',
'gerritbranch': 'master',
'gerrittopic': 'test-topic',
'gerritwip': 1,
'priority': 'M',
'project': 'nova',
'tags': []}

self.assertEqual(issue.get_taskwarrior_record(), expected)

@responses.activate
def test_issues(self):
self.add_response(
Expand All @@ -73,9 +98,11 @@ def test_issues(self):
'description': '(bw)PR#1 - this is a title .. https://one.com/#/c/1/',
'gerritid': 1,
'gerritsummary': 'this is a title',
'gerritstatus': 'new',
'gerriturl': 'https://one.com/#/c/1/',
'gerritbranch': 'master',
'gerrittopic': 'test-topic',
'gerritwip': 0,
'priority': 'M',
'project': 'nova',
'tags': []}
Expand Down
41 changes: 40 additions & 1 deletion tests/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
'closed_at': ARBITRARY_CLOSED.isoformat(),
'updated_at': ARBITRARY_UPDATED.isoformat(),
'repo': 'arbitrary_username/arbitrary_repo',
'state': 'closed'
'state': 'closed',
'draft': False,
}
ARBITRARY_EXTRA = {
'project': 'one',
Expand All @@ -51,6 +52,41 @@ class TestGithubIssue(AbstractServiceTest, ServiceTest):
'username': 'arbitrary_username',
}

def test_draft(self):
service = self.get_mock_service(GithubService)
draft = dict(ARBITRARY_ISSUE)
draft['draft'] = True
issue = service.get_issue_for_record(
draft,
ARBITRARY_EXTRA
)

expected = {
'annotations': [],
'description': '(bw)Is#10 - Hallo .. https://github.com/arbitrary_username/arbitrary_repo/pull/1', # noqa: E501
'entry': ARBITRARY_CREATED,
'end': ARBITRARY_CLOSED,
'githubbody': draft['body'],
'githubcreatedon': ARBITRARY_CREATED,
'githubclosedon': ARBITRARY_CLOSED,
'githubdraft': int(draft['draft']),
'githubmilestone': draft['milestone']['title'],
'githubnamespace': draft['repo'].split('/')[0],
'githubnumber': draft['number'],
'githubrepo': draft['repo'],
'githubtitle': draft['title'],
'githubtype': 'issue',
'githubupdatedat': ARBITRARY_UPDATED,
'githuburl': draft['html_url'],
'githubuser': draft['user']['login'],
'githubstate': draft['state'],
'priority': 'M',
'project': ARBITRARY_EXTRA['project'],
'tags': []
}

self.assertEqual(issue.get_taskwarrior_record(), expected)

def test_to_taskwarrior(self):
service = self.get_mock_service(GithubService, config_overrides={
'import_labels_as_tags': True})
Expand All @@ -68,6 +104,7 @@ def test_to_taskwarrior(self):
'end': ARBITRARY_CLOSED,
issue.URL: ARBITRARY_ISSUE['html_url'],
issue.REPO: ARBITRARY_ISSUE['repo'],
issue.DRAFT: ARBITRARY_ISSUE['draft'],
issue.TYPE: ARBITRARY_EXTRA['type'],
issue.TITLE: ARBITRARY_ISSUE['title'],
issue.NUMBER: ARBITRARY_ISSUE['number'],
Expand Down Expand Up @@ -126,6 +163,7 @@ def test_issues(self):
'githubbody': 'Something',
'githubcreatedon': ARBITRARY_CREATED,
'githubclosedon': ARBITRARY_CLOSED,
'githubdraft': 0,
'githubmilestone': 'alpha',
'githubnamespace': 'arbitrary_username',
'githubnumber': 10,
Expand Down Expand Up @@ -185,6 +223,7 @@ def test_issues(self):
'githubbody': 'Something',
'githubcreatedon': ARBITRARY_CREATED,
'githubclosedon': ARBITRARY_CLOSED,
'githubdraft': 0,
'githubmilestone': 'alpha',
'githubnamespace': 'arbitrary_username',
'githubnumber': 10,
Expand Down

0 comments on commit 1096ed6

Please sign in to comment.