π OpenHands: AI-Driven Development
feat: PLTF-2968 allow per-deployment resolver macro via OH_RESOLVER_LABEL (#14895)
aivong-openhandsfdac43673611
diff --git a/enterprise/integrations/utils.py b/enterprise/integrations/utils.pyindex edae4bdc4e..560dd2cd9c 100644--- a/enterprise/integrations/utils.py+++ b/enterprise/integrations/utils.py@@ -113,14 +113,24 @@ _jinja_env = Environment(loader=FileSystemLoader(OPENHANDS_RESOLVER_TEMPLATES_DIdef get_oh_labels(web_host: str) -> tuple[str, str]:"""Get the OpenHands labels based on the web host.+ An explicit ``OH_RESOLVER_LABEL`` environment variable takes precedence and+ lets each deployment declare its own trigger macro (issue label + mention)+ without a code change. When it is unset, the macro is inferred from+ ``web_host`` for backward compatibility.+Args:web_host: The web host string to checkReturns:A tuple of (oh_label, inline_oh_label) where:- - oh_label is 'openhands-exp' for staging/local hosts, 'openhands' otherwise- - inline_oh_label is '@openhands-exp' for staging/local hosts, '@openhands' otherwise+ - oh_label is OH_RESOLVER_LABEL when set; otherwise 'openhands-exp' for+ staging/local hosts and 'openhands' for everything else+ - inline_oh_label is oh_label prefixed with '@'"""+ override = os.getenv('OH_RESOLVER_LABEL', '').strip()+ if override:+ return override, f'@{override}'+web_host = web_host.strip()is_staging_or_local = 'staging' in web_host or 'local' in web_hostoh_label = 'openhands-exp' if is_staging_or_local else 'openhands'diff --git a/enterprise/tests/unit/test_github_view.py b/enterprise/tests/unit/test_github_view.pyindex 78ebc285c0..9dd2bb2580 100644--- a/enterprise/tests/unit/test_github_view.py+++ b/enterprise/tests/unit/test_github_view.py@@ -35,6 +35,27 @@ class TestGithubLabels(TestCase):self.assertEqual(oh_label, 'openhands-exp')self.assertEqual(inline_oh_label, '@openhands-exp')+ @mock.patch.dict('os.environ', {'OH_RESOLVER_LABEL': 'openhands-dev'})+ def test_labels_with_override(self):+ """An explicit OH_RESOLVER_LABEL overrides host inference."""+ oh_label, inline_oh_label = get_oh_labels('app.all-hands.dev')+ self.assertEqual(oh_label, 'openhands-dev')+ self.assertEqual(inline_oh_label, '@openhands-dev')++ @mock.patch.dict('os.environ', {'OH_RESOLVER_LABEL': ' openhands-dev '})+ def test_labels_override_is_stripped(self):+ """The override is trimmed before use."""+ oh_label, inline_oh_label = get_oh_labels('staging.all-hands.dev')+ self.assertEqual(oh_label, 'openhands-dev')+ self.assertEqual(inline_oh_label, '@openhands-dev')++ @mock.patch.dict('os.environ', {'OH_RESOLVER_LABEL': ''})+ def test_labels_empty_override_falls_back(self):+ """An empty override falls back to host inference."""+ oh_label, inline_oh_label = get_oh_labels('staging.all-hands.dev')+ self.assertEqual(oh_label, 'openhands-exp')+ self.assertEqual(inline_oh_label, '@openhands-exp')+class TestGithubCommentCaseInsensitivity(TestCase):@mock.patch('integrations.github.github_view.INLINE_OH_LABEL', '@openhands')