3636# Local Modules
3737import sync2jira .downstream_issue as d_issue
3838import sync2jira .downstream_pr as d_pr
39- from sync2jira .intermediary import matcher
39+ import sync2jira .handler .github as gh_handler
40+ import sync2jira .handler .github_upstream_issue as u_issue
41+ import sync2jira .handler .github_upstream_pr as u_pr
4042from sync2jira .mailer import send_mail
41- import sync2jira .upstream_issue as u_issue
42- import sync2jira .upstream_pr as u_pr
4343
4444# Set up our logging
4545FORMAT = "[%(asctime)s] %(levelname)s: %(message)s"
@@ -148,20 +148,18 @@ def callback(msg):
148148 idx = msg .id
149149 suffix = "." .join (topic .split ("." )[3 :])
150150
151- if suffix not in issue_handlers and suffix not in pr_handlers :
152- log .info ("No handler for %r %r %r" , suffix , topic , idx )
153- return
154-
155- config = load_config ()
156- body = msg .body .get ("body" ) or msg .body
157- try :
158- handle_msg (body , suffix , config )
159- except GithubException as e :
160- log .error ("Unexpected GitHub error: %s" , e )
161- except JIRAError as e :
162- log .error ("Unexpected Jira error: %s" , e )
163- except Exception as e :
164- log .exception ("Unexpected error." , exc_info = e )
151+ handler = gh_handler .get_handler_for (suffix , topic , idx )
152+ if handler :
153+ config = load_config ()
154+ body = msg .body .get ("body" ) or msg .body
155+ try :
156+ handler (body , suffix , config )
157+ except GithubException as e :
158+ log .error ("Unexpected GitHub error: %s" , e )
159+ except JIRAError as e :
160+ log .error ("Unexpected Jira error: %s" , e )
161+ except Exception as e :
162+ log .exception ("Unexpected error." , exc_info = e )
165163
166164
167165def listen (config ):
@@ -188,18 +186,26 @@ def listen(config):
188186 "arguments" : {},
189187 },
190188 }
189+
190+ # The topics that should be delivered to the queue
191+ github_topics = [
192+ # New style
193+ "org.fedoraproject.prod.github.issues" ,
194+ "org.fedoraproject.prod.github.issue_comment" ,
195+ "org.fedoraproject.prod.github.pull_request" ,
196+ # Old style
197+ "org.fedoraproject.prod.github.issue.#" ,
198+ "org.fedoraproject.prod.github.pull_request.#" ,
199+ ]
200+ gitlab_topics = [
201+ # mytodo: add all topics here
202+ "org.fedoraproject.prod.gitlab.merge_request" ,
203+ ]
204+
191205 bindings = {
192206 "exchange" : "amq.topic" , # The AMQP exchange to bind our queue to
193207 "queue" : queue ,
194- "routing_keys" : [ # The topics that should be delivered to the queue
195- # New style
196- "org.fedoraproject.prod.github.issues" ,
197- "org.fedoraproject.prod.github.issue_comment" ,
198- "org.fedoraproject.prod.github.pull_request" ,
199- # Old style
200- "org.fedoraproject.prod.github.issue.#" ,
201- "org.fedoraproject.prod.github.pull_request.#" ,
202- ],
208+ "routing_keys" : github_topics + gitlab_topics ,
203209 }
204210
205211 log .info ("Waiting for a relevant fedmsg message to arrive..." )
@@ -299,46 +305,6 @@ def initialize_pr(config, testing=False, repo_name=None):
299305 log .info ("Done with GitHub PR initialization." )
300306
301307
302- def handle_msg (body , suffix , config ):
303- """
304- Function to handle incoming message
305- :param Dict body: Incoming message body
306- :param String suffix: Incoming suffix
307- :param Dict config: Config dict
308- """
309- if handler := issue_handlers .get (suffix ):
310- # GitHub '.issue*' is used for both PR and Issue; check if this update
311- # is actually for a PR
312- if "pull_request" in body ["issue" ]:
313- if body ["action" ] == "deleted" :
314- # I think this gets triggered when someone deletes a comment
315- # from a PR. Since we don't capture PR comments (only Issue
316- # comments), we don't need to react if one is deleted.
317- log .debug ("Not handling PR 'action' == 'deleted'" )
318- return
319- # Handle this PR update as though it were an Issue, if that's
320- # acceptable to the configuration.
321- if not (pr := handler (body , config , is_pr = True )):
322- log .info ("Not handling PR issue update -- not configured" )
323- return
324- # PRs require additional handling (Issues do not have suffix, and
325- # reporter needs to be reformatted).
326- pr .suffix = suffix
327- pr .reporter = pr .reporter .get ("fullname" )
328- setattr (pr , "match" , matcher (pr .content , pr .comments ))
329- d_pr .sync_with_jira (pr , config )
330- else :
331- if issue := handler (body , config ):
332- d_issue .sync_with_jira (issue , config )
333- else :
334- log .info ("Not handling Issue update -- not configured" )
335- elif handler := pr_handlers .get (suffix ):
336- if pr := handler (body , config , suffix ):
337- d_pr .sync_with_jira (pr , config )
338- else :
339- log .info ("Not handling PR update -- not configured" )
340-
341-
342308def main (runtime_test = False , runtime_config = None ):
343309 """
344310 Main function to check for initial sync
0 commit comments