1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-11-26 06:29:50 +01:00

Fix 'git-obs pr dump' to skip the dump if the target has the same updated_at timestamp as the pull request in Gitea

This commit is contained in:
2025-10-29 14:33:45 +01:00
parent 4170a3c251
commit fb8d1f4c72
2 changed files with 15 additions and 1 deletions

View File

@@ -127,6 +127,17 @@ class PullRequestDumpCommand(osc.commandline_git.GitObsCommand):
# sanitize path for os.path.join() # sanitize path for os.path.join()
path = path.strip("/") path = path.strip("/")
metadata_dir = os.path.join(path, "metadata")
try:
with open(os.path.join(metadata_dir, "pr.json")) as f:
pr_data = json.load(f)
if pr_data["updated_at"] == pr_obj.updated_at:
# no update, skip the dump
continue
except FileNotFoundError:
# no local metadata cached, we can't skip the dump
pass
review_obj_list = pr_obj.get_reviews(self.gitea_conn) review_obj_list = pr_obj.get_reviews(self.gitea_conn)
# see https://github.com/go-gitea/gitea/blob/main/modules/structs/pull_review.go - look for "type ReviewStateType string" # see https://github.com/go-gitea/gitea/blob/main/modules/structs/pull_review.go - look for "type ReviewStateType string"
@@ -238,7 +249,6 @@ class PullRequestDumpCommand(osc.commandline_git.GitObsCommand):
ET.Comment("The state='comment' attribute value is a custom extension to the OBS XML schema."), ET.Comment("The state='comment' attribute value is a custom extension to the OBS XML schema."),
) )
metadata_dir = os.path.join(path, "metadata")
try: try:
# remove old metadata first to ensure that we never keep any of the old files on an update # remove old metadata first to ensure that we never keep any of the old files on an update
shutil.rmtree(metadata_dir) shutil.rmtree(metadata_dir)

View File

@@ -154,6 +154,10 @@ class PullRequest(GiteaModel):
def state(self) -> str: def state(self) -> str:
return self._data["state"] return self._data["state"]
@property
def updated_at(self) -> str:
return self._data["updated_at"]
@property @property
def user(self) -> str: def user(self) -> str:
return self._data["user"]["login"] return self._data["user"]["login"]