(Steve Dougherty)
2013-07-26: Give local directory matching target for pull requests. bab-reviewedGive local directory matching target for pull requests.
diff --git a/infocalypse/config.py b/infocalypse/config.py --- a/infocalypse/config.py +++ b/infocalypse/config.py @@ -179,6 +179,31 @@ class Config: repo_dir = norm_path(repo_dir) self.request_usks[repo_dir] = usk + def get_repo_dir(self, request_uri): + """ + Return the normalized path for a repo with the given request URI. + Abort if the request URI does not match exactly one directory. + """ + normalized = normalize(request_uri) + match = None + + for repo_dir, uri in self.request_usks.iteritems(): + if normalized == normalize(uri): + if match: + raise util.Abort("Multiple directories match {0}." + .format(request_uri)) + else: + match = repo_dir + + if not match: + raise util.Abort("No repository matches {0}.".format(request_uri)) + + # Assuming path has not become un-normalized since being set with + # update_dir(). + assert norm_path(match) == match + + return match + def get_request_uri(self, for_dir): """ Get the repo USK used to pull changes into for_dir or None. """ uri = self.request_usks.get(norm_path(for_dir)) diff --git a/infocalypse/wot.py b/infocalypse/wot.py --- a/infocalypse/wot.py +++ b/infocalypse/wot.py @@ -209,6 +209,8 @@ def read_message_yaml(ui, from_address, end_token = '...' yaml_end = body.rfind(end_token) + cfg = Config.from_ui(ui) + if not yaml_end == -1: # Better to point to the end of the end token, but don't confuse # failure. @@ -256,7 +258,7 @@ def read_message_yaml(ui, from_address, ui.status("To accept this request, pull from: %s\n" " To your repository: %s\n" % - (request['source'], request['target'])) + (request['source'], cfg.get_repo_dir(request['target']))) return ui.status("Notification '%s' has an unrecognized request of type '%s'"