Skip to content

Commit

Permalink
Use POST instead of PUT for merging Design Reviews
Browse files Browse the repository at this point in the history
This bug wasn't caught because we didn't have a test before. I've added
one to test this case.
  • Loading branch information
shrik450 committed Feb 17, 2025
1 parent 72c18a4 commit ad2682e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
10 changes: 5 additions & 5 deletions allspice/apiobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -2042,7 +2042,7 @@ class DesignReview(ApiObject):
base: str
body: str
changed_files: int
closed_at: Any
closed_at: Optional[str]
comments: int
created_at: str
deletions: int
Expand All @@ -2055,11 +2055,11 @@ class DesignReview(ApiObject):
is_locked: bool
labels: List[Any]
merge_base: str
merge_commit_sha: Any
merge_commit_sha: Optional[str]
mergeable: bool
merged: bool
merged_at: Any
merged_by: Any
merged_at: Optional[str]
merged_by: Optional["User"]
milestone: Any
number: int
patch_url: str
Expand Down Expand Up @@ -2165,7 +2165,7 @@ def merge(self, merge_type: MergeType):
:param merge_type: The type of merge to perform. See the MergeType enum.
"""

self.allspice_client.requests_put(
self.allspice_client.requests_post(
self.MERGE_DESIGN_REVIEW.format(
owner=self.repository.owner.username,
repo=self.repository.name,
Expand Down
32 changes: 32 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,11 @@ def test_create_design_review(instance):
org = Organization.request(instance, test_org)
repo = Repository.request(instance, org.username, test_repo)
branch = Branch.request(instance, org.username, test_repo, "master")
repo.create_file(
"new_file.txt",
base64.b64encode(b"new file contents").decode("utf-8"),
{"branch": "test_branch"},
)
due_date = datetime.datetime.now() + datetime.timedelta(days=7)
review = repo.create_design_review(
"TestDesignReview",
Expand Down Expand Up @@ -762,6 +767,33 @@ def test_get_design_review_attachments(instance):
assert attachments[0].name == "requirements.txt"


def test_merge_design_review(instance):
org = Organization.request(instance, test_org)
repo = Repository.request(instance, org.username, test_repo)
dr = repo.get_design_reviews()[0]

assert dr.state == "open"

# The API may fail with this message. It isn't in the scope of this test to
# make sure the API can merge, so we'll keep retrying until it works or we
# retry too many times.
attempts = 0
while attempts < 5:
try:
dr.merge(DesignReview.MergeType.MERGE)
break
except Exception as e:
if "Please try again later" in str(e):
attempts += 1
time.sleep(1)
continue
else:
raise e

dr = repo.get_design_reviews()[0]
assert dr.state == "closed"


def test_repo_create_release(instance):
org = Organization.request(instance, test_org)
repo = Repository.request(instance, org.username, test_repo)
Expand Down

0 comments on commit ad2682e

Please sign in to comment.