Skip to content
This repository was archived by the owner on Sep 25, 2024. It is now read-only.

Commit f081961

Browse files
Merge pull request #66 from jpopelka/handle_existing_dist-git_pr
Improve code added in #62 I initially wanted to attach these refactoring commits to some other PR, but I think they'll be better on their own. Reviewed-by: None <None> Reviewed-by: Jiri Popelka <None>
2 parents d4e7601 + 86fde45 commit f081961

File tree

2 files changed

+36
-22
lines changed

2 files changed

+36
-22
lines changed

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ check-in-container:
4747
--env COV_REPORT \
4848
--env TEST_TARGET \
4949
--env COLOR \
50-
-v $(CURDIR):/src \
50+
-v $(CURDIR):/src:Z \
5151
-w /src \
52-
--security-opt label=disable \
5352
$(TEST_IMAGE) make check "TEST_TARGET=$(TEST_TARGET)"

hardly/handlers/distgit.py

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -108,18 +108,52 @@ def packit(self) -> PackitAPI:
108108
)
109109
return self._packit
110110

111+
def handle_existing_dist_git_pr(self) -> bool:
112+
"""Sync changes in source-git PR to already existing dist-git PR.
113+
114+
Returns:
115+
was the sync successful
116+
"""
117+
logger.info(
118+
f"{self.source_git_pr_model} already has corresponding {self.dist_git_pr_model}"
119+
)
120+
if self.dist_git_pr:
121+
msg = ""
122+
if self.action == GitlabEventAction.closed.value:
123+
msg = f"[Source-git MR]({self.mr_url}) has been closed."
124+
self.dist_git_pr.close()
125+
elif self.action == GitlabEventAction.reopen.value:
126+
msg = f"[Source-git MR]({self.mr_url}) has been reopened."
127+
# https://github.com/packit/ogr/pull/714
128+
# self.dist_git_pr.reopen()
129+
elif self.action == GitlabEventAction.update.value:
130+
msg = f"[Source-git MR]({self.mr_url}) has been updated."
131+
# TODO: update the dist-git PR?
132+
elif self.action == GitlabEventAction.opened.value:
133+
# Are you trying to re-send a webhook payload to the endpoint manually?
134+
# If so and you expect a new dist-git PR being opened, you first
135+
# have to remove the old relation from db.
136+
logger.error(f"[Source-git MR]({self.mr_url}) opened. (again???)")
137+
return False
138+
logger.info(msg)
139+
self.dist_git_pr.comment(msg)
140+
return True
141+
111142
def run(self) -> TaskResults:
112143
"""
113144
If user creates a merge-request on the source-git repository,
114145
create a matching merge-request to the dist-git repository.
115146
"""
116147
if not self.handle_target():
117148
logger.debug(
118-
"Not creating a dist-git MR from "
149+
"Not creating/updating a dist-git MR from "
119150
f"{self.target_repo}:{self.target_repo_branch}"
120151
)
121152
return TaskResults(success=True)
122153

154+
if self.dist_git_pr_model:
155+
return TaskResults(success=self.handle_existing_dist_git_pr())
156+
123157
if not self.package_config:
124158
logger.debug("No package config found.")
125159
return TaskResults(success=True)
@@ -137,25 +171,6 @@ def run(self) -> TaskResults:
137171
logger.info(msg)
138172
return TaskResults(success=True)
139173

140-
if self.dist_git_pr_model:
141-
logger.info(
142-
f"{self.source_git_pr_model} already has corresponding {self.dist_git_pr_model}"
143-
)
144-
if self.dist_git_pr:
145-
if self.action == GitlabEventAction.closed.value:
146-
msg = f"[Source-git MR]({self.mr_url}) has been closed."
147-
self.dist_git_pr.close()
148-
elif self.action == GitlabEventAction.reopen.value:
149-
msg = f"[Source-git MR]({self.mr_url}) has been reopened."
150-
# https://github.com/packit/ogr/pull/714
151-
# self.dist_git_pr.reopen()
152-
else:
153-
logger.error(f"Unknown action {self.action}")
154-
return TaskResults(success=False)
155-
logger.info(msg)
156-
self.dist_git_pr.comment(msg)
157-
return TaskResults(success=True)
158-
159174
dg_mr_info = f"""###### Info for package maintainer
160175
This MR has been automatically created from
161176
[this source-git MR]({self.mr_url})."""

0 commit comments

Comments
 (0)