Skip to content

Commit

Permalink
DEVPROD-3201 Add id to PatchCreationDetails model. (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahartschen authored Jan 10, 2024
1 parent 3291a19 commit 1868632
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# Changelog

## 3.6.18 - 2024-01-10

- Added `id` field to `PatchCreationDetails`.

## 3.6.17 - 2024-01-08
- added error handling for missing config.

- Added error handling for missing config.

## 3.6.16 - 2023-11-14

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "evergreen.py"
version = "3.6.17"
version = "3.6.18"
description = "Python client for the Evergreen API"
authors = [
"Dev Prod DAG <[email protected]>",
Expand Down
14 changes: 9 additions & 5 deletions src/evergreen/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@
START_WAIT_TIME_SEC = 2
MAX_WAIT_TIME_SEC = 5

EVERGREEN_URL_REGEX = "(https?)://evergreen..*?(?=\\\\n)"
EVERGREEN_URL_REGEX = re.compile(r"(https?)://evergreen\..*?(?=\\n)")
EVERGREEN_PATCH_ID_REGEX = re.compile(r"(?<=ID : )\w{24}")


class EvergreenApi(object):
Expand Down Expand Up @@ -967,14 +968,17 @@ def _execute_patch_file_command(
command = f"{command} --author {author}"

process = subprocess.run(command, shell=True, capture_output=True)
output = str(process.stderr)

match = re.search(EVERGREEN_URL_REGEX, str(process.stderr))
if match is None:
url_match = EVERGREEN_URL_REGEX.search(output)
id_match = EVERGREEN_PATCH_ID_REGEX.search(output)

if url_match is None or id_match is None:
raise Exception(
f"Unable to parse URL from command output: {str(process.stderr)}. \nExecuted command: {command}"
f"Unable to parse URL or ID from command output: {output}. \nExecuted command: {command}"
)

return PatchCreationDetails(url=match.group(0))
return PatchCreationDetails(url=url_match.group(0), id=id_match.group(0))

def patch_from_diff(
self,
Expand Down
1 change: 1 addition & 0 deletions src/evergreen/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class PatchCreationDetails(NamedTuple):
"""Details of a patch creation."""

url: str
id: str


class Patch(_BaseEvergreenObject):
Expand Down
3 changes: 3 additions & 0 deletions tests/evergreen/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ def test_patch_from_diff_valid_no_author(self, mock_run, mocked_api):
result.url
== "https://evergreen.mongodb.com/patch/64387ca457e85ac95a3da12f?redirect_spruce_users=true"
)
assert result.id == "64387ca457e85ac95a3da12f"

@patch("evergreen.api.subprocess.run",)
def test_patch_from_diff_valid_with_author(self, mock_run, mocked_api):
Expand Down Expand Up @@ -616,6 +617,7 @@ def test_patch_from_diff_valid_with_author(self, mock_run, mocked_api):
result.url
== "https://evergreen.mongodb.com/patch/64387ca457e85ac95a3da12f?redirect_spruce_users=true"
)
assert result.id == "64387ca457e85ac95a3da12f"

@patch("evergreen.api.subprocess.run",)
def test_patch_from_diff_invalid(self, mock_run, mocked_api):
Expand Down Expand Up @@ -648,6 +650,7 @@ def test_patch_from_patch_id(self, mock_run, mocked_api):
result.url
== "https://evergreen.mongodb.com/patch/64387ca457e85ac95a3da12f?redirect_spruce_users=true"
)
assert result.id == "64387ca457e85ac95a3da12f"


class TestTaskApi(object):
Expand Down

0 comments on commit 1868632

Please sign in to comment.