Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix azure pipelines branch detection #346

Merged
merged 1 commit into from
Mar 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cpt/ci_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
26 changes: 25 additions & 1 deletion cpt/test/unit/ci_manager_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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]",
Expand Down