diff --git a/cpt/ci_manager.py b/cpt/ci_manager.py index a9958d32..567a608f 100644 --- a/cpt/ci_manager.py +++ b/cpt/ci_manager.py @@ -270,7 +270,10 @@ def get_commit_id(self): return os.getenv("BUILD_SOURCEVERSION", None) def get_branch(self): - return os.getenv("BUILD_SOURCEBRANCHNAME", None) + branch = os.getenv("BUILD_SOURCEBRANCH", None) + if branch.startswith("refs/heads/"): + branch = branch[11:] + return branch def is_pull_request(self): return os.getenv("BUILD_REASON", "false") == "PullRequest" diff --git a/cpt/test/unit/ci_manager_test.py b/cpt/test/unit/ci_manager_test.py index bff69e27..edc6c994 100644 --- a/cpt/test/unit/ci_manager_test.py +++ b/cpt/test/unit/ci_manager_test.py @@ -121,7 +121,7 @@ def test_azure_instance(self): with tools.environment_append({"SYSTEM_TEAMFOUNDATIONCOLLECTIONURI": "https://dev.azure.com/", "BUILD_SOURCEVERSIONMESSAGE": "msg", "BUILD_SOURCEVERSION": "506c89117650bb12252db26d35b8c2385411f175", - "BUILD_SOURCEBRANCHNAME": "mybranch", + "BUILD_SOURCEBRANCH": "mybranch", "BUILD_REASON": "manual", }): manager = CIManager(self.printer) @@ -130,6 +130,30 @@ def test_azure_instance(self): self.assertEquals(manager.get_commit_id(), "506c89117650bb12252db26d35b8c2385411f175") self.assertEquals(manager.is_pull_request(), False) + with tools.environment_append({"SYSTEM_TEAMFOUNDATIONCOLLECTIONURI": "https://dev.azure.com/", + "BUILD_SOURCEVERSIONMESSAGE": "msg", + "BUILD_SOURCEVERSION": "506c89117650bb12252db26d35b8c2385411f175", + "BUILD_SOURCEBRANCH": "refs/heads/testing/version", + "BUILD_REASON": "PullRequest", + }): + manager = CIManager(self.printer) + self.assertEquals(manager.get_branch(), "testing/version") + self.assertEquals(manager.get_commit_msg(), "msg") + self.assertEquals(manager.get_commit_id(), "506c89117650bb12252db26d35b8c2385411f175") + self.assertEquals(manager.is_pull_request(), True) + + with tools.environment_append({"SYSTEM_TEAMFOUNDATIONCOLLECTIONURI": "https://dev.azure.com/", + "BUILD_SOURCEVERSIONMESSAGE": "msg", + "BUILD_SOURCEVERSION": "506c89117650bb12252db26d35b8c2385411f175", + "BUILD_SOURCEBRANCH": "refs/heads/stable/version", + "BUILD_REASON": "IndividualCI", + }): + manager = CIManager(self.printer) + self.assertEquals(manager.get_branch(), "stable/version") + self.assertEquals(manager.get_commit_msg(), "msg") + self.assertEquals(manager.get_commit_id(), "506c89117650bb12252db26d35b8c2385411f175") + self.assertEquals(manager.is_pull_request(), False) + def test_shippable_instance(self): shippable_env = { "SHIPPABLE": "true", "COMMIT_MESSAGE": "foobar [qux]",