Skip to content

Commit

Permalink
Aesthetic nits
Browse files Browse the repository at this point in the history
  • Loading branch information
webbnh committed Sep 27, 2024
1 parent e5612e5 commit 44d7d8d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 35 deletions.
23 changes: 10 additions & 13 deletions sync2jira/upstream_issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def handle_github_message(msg, config, pr_filter=True):
owner = msg['msg']['repository']['owner']['login']
repo = msg['msg']['repository']['name']
upstream = '{owner}/{repo}'.format(owner=owner, repo=repo)
mapped_repos = config['sync2jira']['map']['github']

mapped_repos = config['sync2jira']['map']['github']
if upstream not in mapped_repos:
log.debug("%r not in Github map: %r", upstream, mapped_repos.keys())
return None
Expand Down Expand Up @@ -121,8 +121,8 @@ def handle_pagure_message(msg, config):
log.debug("%r not in Pagure issue map: %r", upstream, mapped_repos.keys())
return None

_filter = config['sync2jira']\
.get('filters', {})\
_filter = config['sync2jira'] \
.get('filters', {}) \
.get('pagure', {}) \
.get(upstream, {})

Expand Down Expand Up @@ -338,8 +338,8 @@ def generate_github_items(api_method, upstream, config):


def get_all_github_data(url, headers):
""" Pagination utility. Obnoxious. """
link = dict(next=url)
"""A generator which returns each response from a paginated GitHub API call"""
link = {'next': url}
while 'next' in link:
response = api_call_get(link['next'], headers=headers)
for issue in response.json():
Expand All @@ -350,19 +350,16 @@ def get_all_github_data(url, headers):


def _github_link_field_to_dict(field):
"""
Utility for ripping apart github's Link header field.
It's kind of ugly.
"""
"""Utility for ripping apart GitHub's Link header field."""

if not field:
return dict()
return dict([
return {}
return dict(
(
part.split('; ')[1][5:-1],
part.split('; ')[0][1:-1],
part.split('; ')[0][1:-1]
) for part in field.split(', ')
])
)


def api_call_get(url, **kwargs):
Expand Down
2 changes: 0 additions & 2 deletions sync2jira/upstream_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,10 @@ def handle_github_message(msg, config, suffix):
:returns: Issue object
:rtype: sync2jira.intermediary.PR
"""
# Create our title (i.e. owner/repo)
owner = msg['msg']['repository']['owner']['login']
repo = msg['msg']['repository']['name']
upstream = '{owner}/{repo}'.format(owner=owner, repo=repo)

# Check if upstream is in mapped repos
mapped_repos = config['sync2jira']['map']['github']
if upstream not in mapped_repos:
log.debug("%r not in Github map: %r", upstream, mapped_repos.keys())
Expand Down
20 changes: 10 additions & 10 deletions tests/test_upstream_issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ def setUp(self):
'topic': 'io.pagure.prod.pagure.issue.drop',
}

# Mock Github Comment
# Mock GitHub Comment
self.mock_github_comment = MagicMock()
self.mock_github_comment.user.name = 'mock_username'
self.mock_github_comment.body = 'mock_body'
self.mock_github_comment.id = 'mock_id'
self.mock_github_comment.created_at = 'mock_created_at'

# Mock Github Message
# Mock GitHub Message
self.mock_github_message = {
'msg': {
'repository': {
Expand All @@ -91,11 +91,11 @@ def setUp(self):
}
}

# Mock github issue
# Mock GitHub issue
self.mock_github_issue = MagicMock()
self.mock_github_issue.get_comments.return_value = [self.mock_github_comment]

# Mock Github Issue Raw
# Mock GitHub Issue Raw
self.mock_github_issue_raw = {
'comments': ['some comment'],
'number': '1234',
Expand All @@ -109,15 +109,15 @@ def setUp(self):
}
}

# Mock Github Reporter
# Mock GitHub Reporter
self.mock_github_person = MagicMock()
self.mock_github_person.name = 'mock_name'

# Mock Github Repo
# Mock GitHub Repo
self.mock_github_repo = MagicMock()
self.mock_github_repo.get_issue.return_value = self.mock_github_issue

# Mock Github Client
# Mock GitHub Client
self.mock_github_client = MagicMock()
self.mock_github_client.get_repo.return_value = self.mock_github_repo
self.mock_github_client.get_user.return_value = self.mock_github_person
Expand Down Expand Up @@ -177,7 +177,7 @@ def test_github_issues_no_token(self,
mock_github,
mock_issue_from_github):
"""
This function tests 'github_issues' function where we have no github token
This function tests 'github_issues' function where we have no GitHub token
and no comments
"""
# Set up return values
Expand Down Expand Up @@ -452,8 +452,8 @@ def test_handle_github_message_bad_label(self,
@mock.patch(PATH + 'Github')
@mock.patch('sync2jira.intermediary.Issue.from_github')
def test_handle_github_message_no_comments(self,
mock_issue_from_github,
mock_github):
mock_issue_from_github,
mock_github):
"""
This function tests 'handle_github_message' where we have no comments
"""
Expand Down
20 changes: 10 additions & 10 deletions tests/test_upstream_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ def setUp(self):
}
}

# Mock Github Comment
# Mock GitHub Comment
self.mock_github_comment = MagicMock()
self.mock_github_comment.user.name = 'mock_username'
self.mock_github_comment.body = 'mock_body'
self.mock_github_comment.id = 'mock_id'
self.mock_github_comment.created_at = 'mock_created_at'

# Mock Github Message
# Mock GitHub Message
self.mock_github_message = {
'msg': {
'repository': {
Expand All @@ -101,11 +101,11 @@ def setUp(self):
}
}

# Mock github issue
# Mock GitHub issue
self.mock_github_pr = MagicMock()
self.mock_github_pr.get_issue_comments.return_value = [self.mock_github_comment]

# Mock Github Issue Raw
# Mock GitHub Issue Raw
self.mock_github_issue_raw = {
'comments': ['some comment'],
'number': '1234',
Expand All @@ -119,16 +119,16 @@ def setUp(self):
}
}

# Mock Github Reporter
# Mock GitHub Reporter
self.mock_github_person = MagicMock()
self.mock_github_person.name = 'mock_name'

# Mock Github Repo
# Mock GitHub Repo
self.mock_github_repo = MagicMock()
self.mock_github_repo.get_pull.return_value = self.mock_github_pr
self.mock_github_repo.get_issue.return_value = self.mock_github_pr

# Mock Github Client
# Mock GitHub Client
self.mock_github_client = MagicMock()
self.mock_github_client.get_repo.return_value = self.mock_github_repo
self.mock_github_client.get_user.return_value = self.mock_github_person
Expand Down Expand Up @@ -319,9 +319,9 @@ def test_github_issues(self,
mock_pr_from_github.assert_called_with(
'org/repo',
{'comments':
[{'author': 'mock_username', 'name': unittest.mock.ANY,
'body': 'mock_body', 'id': 'mock_id',
'date_created': 'mock_created_at', 'changed': None}],
[{'author': 'mock_username', 'name': unittest.mock.ANY,
'body': 'mock_body', 'id': 'mock_id',
'date_created': 'mock_created_at', 'changed': None}],
'number': '1234', 'user':
{'login': 'mock_login', 'fullname': 'mock_name'},
'assignees': [{'fullname': 'mock_name'}],
Expand Down

0 comments on commit 44d7d8d

Please sign in to comment.