Skip to content

Commit ca8eb5f

Browse files
authored
Merge pull request openSUSE#1978 from dmach/git-obs-pr-dump-skip-no-update
Fix 'git-obs pr dump' to skip the dump if the target has the same updated_at timestamp as the pull request in Gitea
2 parents 141157e + fb8d1f4 commit ca8eb5f

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

osc/commands_git/pr_dump.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,17 @@ def run(self, args):
127127
# sanitize path for os.path.join()
128128
path = path.strip("/")
129129

130+
metadata_dir = os.path.join(path, "metadata")
131+
try:
132+
with open(os.path.join(metadata_dir, "pr.json")) as f:
133+
pr_data = json.load(f)
134+
if pr_data["updated_at"] == pr_obj.updated_at:
135+
# no update, skip the dump
136+
continue
137+
except FileNotFoundError:
138+
# no local metadata cached, we can't skip the dump
139+
pass
140+
130141
review_obj_list = pr_obj.get_reviews(self.gitea_conn)
131142

132143
# see https://github.com/go-gitea/gitea/blob/main/modules/structs/pull_review.go - look for "type ReviewStateType string"
@@ -238,7 +249,6 @@ def run(self, args):
238249
ET.Comment("The state='comment' attribute value is a custom extension to the OBS XML schema."),
239250
)
240251

241-
metadata_dir = os.path.join(path, "metadata")
242252
try:
243253
# remove old metadata first to ensure that we never keep any of the old files on an update
244254
shutil.rmtree(metadata_dir)

osc/gitea_api/issue_timeline_entry.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99

1010

1111
class IssueTimelineEntry(GiteaModel):
12+
def __init__(self, *args, **kwargs):
13+
super().__init__(*args, **kwargs)
14+
self._pull_request_review_cache = None
15+
1216
@property
1317
def type(self) -> str:
1418
return self._data["type"]
@@ -50,9 +54,12 @@ def review_obj(self) -> Optional[PullRequestReview]:
5054

5155
if not self.review_id:
5256
return None
57+
if self._pull_request_review_cache is None:
58+
review_obj_list = PullRequestReview.list(self._conn, self.pr_owner, self.pr_repo, self.pr_number)
59+
self._pull_request_review_cache = {i._data["id"]: i for i in review_obj_list}
5360
try:
54-
return PullRequestReview.get(self._conn, self.pr_owner, self.pr_repo, self.pr_number, str(self.review_id))
55-
except PullRequestReviewDoesNotExist:
61+
return self._pull_request_review_cache[self.review_id]
62+
except KeyError:
5663
# reviews can be removed from the database, but their IDs remain in other places
5764
return None
5865

osc/gitea_api/pr.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ def body(self) -> str:
154154
def state(self) -> str:
155155
return self._data["state"]
156156

157+
@property
158+
def updated_at(self) -> str:
159+
return self._data["updated_at"]
160+
157161
@property
158162
def user(self) -> str:
159163
return self._data["user"]["login"]

0 commit comments

Comments
 (0)