Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Humbedooh committed Mar 10, 2022
1 parent 18e9dc5 commit 4e97b85
Showing 1 changed file with 45 additions and 35 deletions.
80 changes: 45 additions & 35 deletions notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,62 +70,67 @@ def __init__(self, cfg_file: str):
contents,
)

def get_recipient(self, repository, itype, action = "comment"):
def get_recipient(self, repository, itype, action="comment"):
m = RE_PROJECT.match(repository)
if m:
project = m.group(1)
else:
project = 'infra'
project = "infra"
repo_path = None
scheme = {}
for root_dir in self.config['repository_paths']:
for root_dir in self.config["repository_paths"]:
for path in glob.glob(root_dir):
if os.path.basename(path) == f"{repository}.git":
repo_path = path
break
if repo_path:
scheme_path = os.path.join(repo_path, self.config['scheme_file'])
scheme_path = os.path.join(repo_path, self.config["scheme_file"])
if os.path.exists(scheme_path):
try:
scheme = yaml.safe_load(open(scheme_path))
except:
pass

# Check standard git config
cfg_path = os.path.join(repo_path, 'config')
cfg_path = os.path.join(repo_path, "config")
cfg = git.GitConfigParser(cfg_path)
if not 'commits' in scheme:
scheme['commits'] = cfg.get("hooks.asfgit", "recips") or self.config['refault_recipient']
if cfg.has_option('apache', 'dev'):
if not "commits" in scheme:
scheme["commits"] = (
cfg.get("hooks.asfgit", "recips")
or self.config["refault_recipient"]
)
if cfg.has_option("apache", "dev"):
default_issue = cfg.get("apache", "dev")
if not 'issues' in scheme:
scheme['issues'] = default_issue
if not 'pullrequests' in scheme:
scheme['pullrequests'] = default_issue
if cfg.has_option('apache', 'jira'):
if not "issues" in scheme:
scheme["issues"] = default_issue
if not "pullrequests" in scheme:
scheme["pullrequests"] = default_issue
if cfg.has_option("apache", "jira"):
default_jira = cfg.get("apache", "jira")
if not 'jira_options' in scheme:
scheme['jira_options'] = default_jira
if not "jira_options" in scheme:
scheme["jira_options"] = default_jira

if scheme:
if itype not in ['commit', 'jira']:
it = 'issues' if itype == 'issue' else 'pullrequests'
if action in ['comment', 'diffcomment', 'edited', 'deleted', 'created']:
if itype not in ["commit", "jira"]:
it = "issues" if itype == "issue" else "pullrequests"
if action in ["comment", "diffcomment", "edited", "deleted", "created"]:
if ("%s_comment" % it) in scheme:
return scheme["%s_comment" % it]
elif it in scheme:
return scheme.get(it, self.config['refault_recipient'])
elif action in ['open', 'close', 'merge']:
return scheme.get(it, self.config["refault_recipient"])
elif action in ["open", "close", "merge"]:
if ("%s_status" % it) in scheme:
return scheme["%s_status" % it]
elif it in scheme:
return scheme.get(it, self.config['refault_recipient'])
elif itype == 'commit' and 'commits' in scheme:
return scheme['commits']
elif itype == 'jira':
return scheme.get('jira_options', self.config['jira']['default_options'])
if itype == 'jira':
return self.config['jira']['default_options']
return scheme.get(it, self.config["refault_recipient"])
elif itype == "commit" and "commits" in scheme:
return scheme["commits"]
elif itype == "jira":
return scheme.get(
"jira_options", self.config["jira"]["default_options"]
)
if itype == "jira":
return self.config["jira"]["default_options"]
return "dev@%s.apache.org" % project

def flush(self):
Expand Down Expand Up @@ -159,7 +164,9 @@ def handle_payload(self, raw):
diff = payload.get("diff", "")
pr_id = issue_id
node_id = payload.get("node_id") # Used for message references/threading
real_action = action + "_" + (payload.get("type") == "issue" and "issue" or "pr")
real_action = (
action + "_" + (payload.get("type") == "issue" and "issue" or "pr")
)
if action == "diffcomment":
uid = f"{repository}-{pr_id}-{user}"
if uid not in self.diffcomments:
Expand All @@ -179,16 +186,20 @@ def handle_payload(self, raw):
msgid = "<%s-%s@gitbox.apache.org>" % (node_id, str(uuid.uuid4()))
msgid_OP = "<%s@gitbox.apache.org>" % node_id
if action == "open":
msgid = msgid_OP # This is the first email, make a deterministic message id
msgid = (
msgid_OP # This is the first email, make a deterministic message id
)
else:
msg_headers = {"In-Reply-To": msgid_OP} # Thread from the first PR/issue email
msg_headers = {
"In-Reply-To": msgid_OP
} # Thread from the first PR/issue email
print(real_subject)
if real_action == "diffcomment_collated_pr":
print(real_text)
#print(msgid)
#print(msg_headers)
# print(msgid)
# print(msg_headers)
if SEND_EMAIL: # NOT YET!
recipient = self.config['default_recipient']
recipient = self.config["default_recipient"]
asfpy.messaging.mail(
sender="GitBox <git@apache.org>",
recipient=recipient,
Expand All @@ -199,7 +210,7 @@ def handle_payload(self, raw):
)

def listen(self):
listener = asfpy.pubsub.Listener(self.config['pubsub_url'])
listener = asfpy.pubsub.Listener(self.config["pubsub_url"])
listener.attach(self.handle_payload, raw=True)


Expand All @@ -210,4 +221,3 @@ def main():

if __name__ == "__main__":
main()

0 comments on commit 4e97b85

Please sign in to comment.