Thread View: linux.gentoo.dev
4 messages
4 total messages
Started by Thomas Bracht Laumann Jespersen
Sun, 29 Nov 2026 20:10
[gentoo-dev] [PATCH proj/dev2forge 0/2] codeberg: record the last processed PR for subsequent runs
Author: Thomas Bracht Laumann Jespersen
Date: Sun, 29 Nov 2026 20:10
Date: Sun, 29 Nov 2026 20:10
25 lines
2904 bytes
2904 bytes
Instead of processing the entire history of pull requests every time
we want to update the mapping from email -> codeberg handle, we write
the number of the last processed request to a file.
To ensure we don't miss any pull requests, we process them
oldest-first and if processing fails in the middle, we simply record
how far we got, so a subsequent run can pick up where it was
left.
Signed-off-by: Thomas Bracht Laumann Jespersen <laumann@gentoo.org>
---
Thomas Bracht Laumann Jespersen (2):
codeberg: record last processed PR
codeberg: handle ConnectionError
codeberg/codebergapi.py | 19 +++++++++++++++----
codeberg/update-pr-submitter-db.py | 28 ++++++++++++++++++++++++----
2 files changed, 39 insertions(+), 8 deletions(-)
---
base-commit: b3975ba3df585264e6f54637f5a2ee226e2bc972
change-id: 20261128-record-last-pr-4b1c9afab0e3
Best regards,
--
Thomas Bracht Laumann Jespersen <laumann@gentoo.org>
[gentoo-dev] [PATCH proj/dev2forge 2/2] codeberg: handle ConnectionError
Author: Thomas Bracht Laumann Jespersen
Date: Sun, 29 Nov 2026 20:20
Date: Sun, 29 Nov 2026 20:20
29 lines
3034 bytes
3034 bytes
A Codeberg API request may fail with "Max retries exceeded" which
presents as a ConnectionError. We want to handle it the same as
HTTPError and RetryError.
Signed-off-by: Thomas Bracht Laumann Jespersen <laumann@gentoo.org>
---
codeberg/update-pr-submitter-db.py | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/codeberg/update-pr-submitter-db.py b/codeberg/update-pr-submitter-db.py
index 70a4eb3..d5b0351 100755
--- a/codeberg/update-pr-submitter-db.py
+++ b/codeberg/update-pr-submitter-db.py
@@ -107,7 +107,11 @@ def main(proxied_maints_json="proxied-maints.json", last_pr="proxied-maints-last
continue
maints[attributed_c["email"]] = attributed["login"]
last_pr_num = pr['number']
- except requests.exceptions.HTTPError, requests.exceptions.RetryError:
+ except (
+ requests.exceptions.HTTPError,
+ requests.exceptions.RetryError,
+ requests.exceptions.ConnectionError,
+ ):
import traceback
traceback.print_exc()
print('dumping found records')
--
2.56.1
[gentoo-dev] [PATCH proj/dev2forge 1/2] codeberg: record last processed PR
Author: Thomas Bracht Laumann Jespersen
Date: Sun, 29 Nov 2026 20:20
Date: Sun, 29 Nov 2026 20:20
119 lines
6588 bytes
6588 bytes
Process pull requests from oldest to newest and record the last
processed pull request number an a file.
Flip the processing order of pull requests to oldest-first so pull
requests are processed in increasing order. This way the processing
can simply be restarted if/when from a crash due to Codeberg API
connection issues, and it should pick up from the last seen PR.
It also appears that the Codeberg API has an upper limit of 50
items (at least of pull requests), so even if limit=100 is given, only
50 items are returned.
Signed-off-by: Thomas Bracht Laumann Jespersen <laumann@gentoo.org>
---
codeberg/codebergapi.py | 19 +++++++++++++++----
codeberg/update-pr-submitter-db.py | 22 +++++++++++++++++++---
2 files changed, 34 insertions(+), 7 deletions(-)
diff --git a/codeberg/codebergapi.py b/codeberg/codebergapi.py
index e6d3a28..e9510b0 100644
--- a/codeberg/codebergapi.py
+++ b/codeberg/codebergapi.py
@@ -51,8 +51,11 @@ class CodebergAPI:
def teams_baseurl(self) -> str:
return "https://codeberg.org/api/v1/teams"
- def _get_paginated(self, url, timeout=None) -> Generator[None, dict, None]:
- r = self.session.get(url, params={"limit": 100}, timeout=timeout)
+ def _get_paginated(self, url, params=None, timeout=None) -> Generator[None, dict, None]:
+ params = params or {}
+ # The limit appears to be hard-capped at 50 on Codeberg
+ params["limit"] = 50
+ r = self.session.get(url, params=params, timeout=timeout)
yield from r.json()
if "next" not in r.links:
return
@@ -64,11 +67,19 @@ class CodebergAPI:
break
next_url = r.links["next"]["url"]
- def pulls(self, state="open") -> Generator[None, dict, None]:
+ def pulls(self, state="open", sort=None, page=1) -> Generator[None, dict, None]:
"""
state must be one of: open, closed, all
+ page: Page number of results to return (1-based)
+ sort: one of oldest, recentupdate, recentclose, leastupdate, mostcomment, leastcomment, priority
"""
- return self._get_paginated(f"{self.repos_baseurl}/pulls?state={state}", timeout=61)
+ params = {
+ "state": state,
+ "page": page
+ }
+ if sort is not None:
+ params["sort"] = sort
+ return self._get_paginated(f"{self.repos_baseurl}/pulls", params=params, timeout=61)
def set_pr_title(self, pr_id: int, title: str) -> None:
self.session.patch(f"{self.repos_baseurl}/pulls/{pr_id}", json={"title": title})
diff --git a/codeberg/update-pr-submitter-db.py b/codeberg/update-pr-submitter-db.py
index 1522c2f..70a4eb3 100755
--- a/codeberg/update-pr-submitter-db.py
+++ b/codeberg/update-pr-submitter-db.py
@@ -14,20 +14,32 @@ import requests
from codebergapi import CodebergAPI
-def main(proxied_maints_json="proxied-maints.json"):
+def main(proxied_maints_json="proxied-maints.json", last_pr="proxied-maints-last-pr"):
maints = {}
try:
with open(proxied_maints_json) as pm_f:
maints = json.load(pm_f)
- except (OSError, IOError):
+ except OSError:
pass
+ start_page = 1
+ last_pr_num = 1
+ if last_pr is not None:
+ try:
+ with open(last_pr) as f:
+ last_pr_num = int(f.read().strip())
+ start_page = last_pr_num // 50
+ except OSError:
+ pass
+
with open(os.path.expanduser("~/.codeberg-token")) as f:
api_token = f.read().strip()
with CodebergAPI("gentoo", "gentoo", api_token) as cb:
try:
- for pr in cb.pulls(state="all"):
+ for pr in cb.pulls(state="all", sort="oldest", page=start_page):
+ if pr['number'] <= last_pr_num:
+ continue
print(f"PR #{pr['number']:04d}", end=" ", flush=True)
pr_user = pr["user"]["login"]
@@ -94,6 +106,7 @@ def main(proxied_maints_json="proxied-maints.json"):
if escape:
continue
maints[attributed_c["email"]] = attributed["login"]
+ last_pr_num = pr['number']
except requests.exceptions.HTTPError, requests.exceptions.RetryError:
import traceback
traceback.print_exc()
@@ -103,6 +116,9 @@ def main(proxied_maints_json="proxied-maints.json"):
with open(proxied_maints_json, "w") as pm_f:
json.dump(maints, pm_f, indent=2)
+ with open(last_pr, "w") as f:
+ f.write(str(last_pr_num))
+
print("")
return 0
--
2.56.1
Re: [gentoo-dev] [PATCH proj/dev2forge 0/2] codeberg: record the last processed PR for subsequent runs
Author: Sam James
Date: Tue, 01 Dec 2026 12:40
Date: Tue, 01 Dec 2026 12:40
46 lines
2842 bytes
2842 bytes
--=-=-= Content-Type: text/plain Thomas Bracht Laumann Jespersen <laumann@gentoo.org> writes: > Instead of processing the entire history of pull requests every time > we want to update the mapping from email -> codeberg handle, we write > the number of the last processed request to a file. > > To ensure we don't miss any pull requests, we process them > oldest-first and if processing fails in the middle, we simply record > how far we got, so a subsequent run can pick up where it was > left. > Looks OK, cc'd some people w/ possible opinions. > Signed-off-by: Thomas Bracht Laumann Jespersen <laumann@gentoo.org> > --- > Thomas Bracht Laumann Jespersen (2): > codeberg: record last processed PR > codeberg: handle ConnectionError > > codeberg/codebergapi.py | 19 +++++++++++++++---- > codeberg/update-pr-submitter-db.py | 28 ++++++++++++++++++++++++---- > 2 files changed, 39 insertions(+), 8 deletions(-) > --- > base-commit: b3975ba3df585264e6f54637f5a2ee226e2bc972 > change-id: 20261128-record-last-pr-4b1c9afab0e3 > > Best regards, --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEBBAEWCgCpFiEEJaa7iN2bdkxrVUHCc4QJ9SDfkZAFAmsOv4UbFIAAAAAABAAO bWFudTIsMi41KzEuMTIsMiwyXxSAAAAAAC4AKGlzc3Vlci1mcHJAbm90YXRpb25z Lm9wZW5wZ3AuZmlmdGhob3JzZW1hbi5uZXQyNUE2QkI4OEREOUI3NjRDNkI1NTQx QzI3Mzg0MDlGNTIwREY5MTkwDxxzYW1AZ2VudG9vLm9yZwAKCRBzhAn1IN+RkByb AP9vi0bcgdtwgWDCzFK8YDwVRMU0U7CX2Q4y1O7IOndl9wD+Jzi8qb62SW6D6ZPR LSJ5jHKly4GAYe9xGt+796RkHws= =I0lg -----END PGP SIGNATURE----- --=-=-=--
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads