Skip to content

Commit

Permalink
Pick lint (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
webbnh authored Dec 7, 2024
1 parent 46025c4 commit bac0647
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 29 deletions.
14 changes: 7 additions & 7 deletions sync2jira/intermediary.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self, source, title, url, upstream, comments,
self.storypoints = storypoints

# First trim the size of the content
self.content = trimString(content)
self.content = trim_string(content)

# JIRA treats utf-8 characters in ways we don't totally understand, so scrub content down to
# simple ascii characters right from the start.
Expand Down Expand Up @@ -73,7 +73,7 @@ def from_github(cls, upstream, issue, config):
comments.append({
'author': comment['author'],
'name': comment['name'],
'body': trimString(comment['body']),
'body': trim_string(comment['body']),
'id': comment['id'],
'date_created': comment['date_created'],
'changed': None
Expand Down Expand Up @@ -136,7 +136,7 @@ def __init__(self, source, jira_key, title, url, upstream, config,
# simple ascii characters right from the start.
if content:
# First trim the size of the content
self.content = trimString(content)
self.content = trim_string(content)

self.content = self.content.encode('ascii', errors='replace').decode('ascii')

Expand Down Expand Up @@ -164,7 +164,7 @@ def title(self):
return u'[%s] %s' % (self.upstream, self._title)

@classmethod
def from_github(self, upstream, pr, suffix, config):
def from_github(cls, upstream, pr, suffix, config):
"""Helper function to create intermediary object."""
# Set our upstream source
upstream_source = 'github'
Expand All @@ -175,7 +175,7 @@ def from_github(self, upstream, pr, suffix, config):
comments.append({
'author': comment['author'],
'name': comment['name'],
'body': trimString(comment['body']),
'body': trim_string(comment['body']),
'id': comment['id'],
'date_created': comment['date_created'],
'changed': None
Expand All @@ -198,7 +198,7 @@ def from_github(self, upstream, pr, suffix, config):
suffix = 'closed'

# Return our PR object
return PR(
return cls(
source=upstream_source,
jira_key=match,
title=pr['title'],
Expand Down Expand Up @@ -266,7 +266,7 @@ def matcher(content, comments):
return None


def trimString(content):
def trim_string(content):
"""
Helper function to trim a string to ensure it is not over 50000 char
Ref: https://github.com/release-engineering/Sync2Jira/issues/123
Expand Down
29 changes: 14 additions & 15 deletions sync2jira/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
INITIALIZE = os.getenv('INITIALIZE', '0')


def load_config(loader=fedmsg.config.load_config):
def load_config(loader=fedmsg.config.conf.load_config):
"""
Generates and validates the config file \
that will be used by fedmsg and JIRA client.
Expand All @@ -103,8 +103,8 @@ def load_config(loader=fedmsg.config.load_config):

# debug mode
if config.get('sync2jira', {}).get('debug', False):
hdlr = logging.FileHandler('sync2jira_main.log')
log.addHandler(hdlr)
handler = logging.FileHandler('sync2jira_main.log')
log.addHandler(handler)
log.setLevel(logging.DEBUG)

# Validate it
Expand Down Expand Up @@ -193,8 +193,8 @@ def initialize_issues(config, testing=False, repo_name=None):
raise
except Exception as e:
if "API rate limit exceeded" in e.__str__():
# If we've hit out API limit:
# Sleep for 1 hour and call our function again
# If we've hit our API limit, sleep for 1 hour, and call our
# function again.
log.info("Hit Github API limit. Sleeping for 1 hour...")
sleep(3600)
if not testing:
Expand Down Expand Up @@ -239,8 +239,8 @@ def initialize_pr(config, testing=False, repo_name=None):
raise
except Exception as e:
if "API rate limit exceeded" in e.__str__():
# If we've hit out API limit:
# Sleep for 1 hour and call our function again
# If we've hit our API limit, sleep for 1 hour, and call our
# function again.
log.info("Hit Github API limit. Sleeping for 1 hour...")
sleep(3600)
if not testing:
Expand Down Expand Up @@ -282,14 +282,14 @@ def initialize_recent(config):

def handle_msg(msg, suffix, config):
"""
Function to handle incomming message from datagrepper
Function to handle incoming message from datagrepper
:param Dict msg: Incoming message
:param String suffix: Incoming suffix
:param Dict config: Config dict
"""
issue = None
pr = None
# Github '.issue.' is used for both PR and Issue
# GitHub '.issue.' is used for both PR and Issue
# Check for that edge case
if suffix == 'github.issue.comment':
if 'pull_request' in msg['msg']['issue'] and msg['msg']['action'] != 'deleted':
Expand Down Expand Up @@ -363,7 +363,7 @@ def get(params):
def main(runtime_test=False, runtime_config=None):
"""
Main function to check for initial sync
and listen for fedmgs.
and listen for fedmsgs.
:param Bool runtime_test: Flag to indicate if we are performing a runtime test. Default false
:param Dict runtime_config: Config file to be used if it is a runtime test. runtime_test must be true
Expand All @@ -387,7 +387,7 @@ def main(runtime_test=False, runtime_config=None):
if runtime_test:
return
else:
# Pool datagrepper from the last 10 mins
# Pull from datagrepper for the last 10 minutes
log.info("Initialization False. Pulling data from datagrepper...")
initialize_recent(config)
try:
Expand All @@ -405,14 +405,13 @@ def report_failure(config):
"""
Helper function to alert admins in case of failure.
:param Dict config: Config dict for JIRA
"""
# Email our admins with the traceback
templateLoader = jinja2.FileSystemLoader(
template_loader = jinja2.FileSystemLoader(
searchpath='usr/local/src/sync2jira/sync2jira/')
templateEnv = jinja2.Environment(loader=templateLoader, autoescape=True)
template = templateEnv.get_template('failure_template.jinja')
template_env = jinja2.Environment(loader=template_loader, autoescape=True)
template = template_env.get_template('failure_template.jinja')
html_text = template.render(traceback=traceback.format_exc())

# Send mail
Expand Down
14 changes: 7 additions & 7 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def test_config_validate_missing_map(self):
loader = lambda: {'sync2jira': {}}
self._check_for_exception(loader, 'No sync2jira.map section')

def test_config_validate_mispelled_mappings(self):
def test_config_validate_misspelled_mappings(self):
loader = lambda: {'sync2jira': {'map': {'githob': {}}}, 'jira': {}}
self._check_for_exception(loader, 'Specified handlers: "githob", must')

Expand All @@ -64,7 +64,7 @@ def test_config_validate_missing_jira(self):

def test_config_validate_all_good(self):
loader = lambda: {'sync2jira': {'map': {'github': {}}, 'jira': {}}}
m.load_config(loader) # ahhh, no exception.
m.load_config(loader) # Should succeed without an exception.

@mock.patch(PATH + 'u_issue')
@mock.patch(PATH + 'd_issue')
Expand Down Expand Up @@ -366,13 +366,13 @@ def test_report_failure(self,
Tests 'report_failure' function
"""
# Set up return values
mock_templateLoader = MagicMock()
mock_templateEnv = MagicMock()
mock_template_loader = MagicMock()
mock_template_env = MagicMock()
mock_template = MagicMock()
mock_template.render.return_value = 'mock_html'
mock_templateEnv.get_template.return_value = mock_template
mock_jinja2.FileSystemLoader.return_value = mock_templateLoader
mock_jinja2.Environment.return_value = mock_templateEnv
mock_template_env.get_template.return_value = mock_template
mock_jinja2.FileSystemLoader.return_value = mock_template_loader
mock_jinja2.Environment.return_value = mock_template_env

# Call the function
m.report_failure({'sync2jira': {'mailing-list': 'mock_email'}})
Expand Down

0 comments on commit bac0647

Please sign in to comment.