commit:     aabf8d88350b0346f617f8d4d5fd500c48fff2ac
Author:     Thomas Bracht Laumann Jespersen <t <AT> laumann <DOT> xyz>
AuthorDate: Sat Feb  7 18:18:39 2026 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Mon Feb  9 11:32:11 2026 +0000
URL:        
https://gitweb.gentoo.org/proj/repo-mirror-ci.git/commit/?id=aabf8d88

pull-request: pull github PR scanning into own function

This is the beginning of a rework of scan-pull-requests.py where it
should eventually scan both Codeberg and GitHub PRs.

Signed-off-by: Thomas Bracht Laumann Jespersen <t <AT> laumann.xyz>
Part-of: https://github.com/gentoo/repo-mirror-ci/pull/10
Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>

 pull-request/scan-pull-requests.py | 33 +++++++++++++++++++++++----------
 1 file changed, 23 insertions(+), 10 deletions(-)

diff --git a/pull-request/scan-pull-requests.py 
b/pull-request/scan-pull-requests.py
index aa58505..81a920c 100755
--- a/pull-request/scan-pull-requests.py
+++ b/pull-request/scan-pull-requests.py
@@ -12,23 +12,19 @@ import sys
 import github
 
 
-def main():
+def scan_github(db: dict):
+    """
+    Given a db of knowns PRs, inspect open PRs, update commit
+    statuses, and update the db accordingly. Return a list of
+    outstanding PRs to process.
+    """
     GITHUB_USERNAME = os.environ['GITHUB_USERNAME']
     GITHUB_TOKEN_FILE = os.environ['GITHUB_TOKEN_FILE']
     GITHUB_REPO = os.environ['GITHUB_REPO']
-    PULL_REQUEST_DB = os.environ['PULL_REQUEST_DB']
 
     with open(GITHUB_TOKEN_FILE) as f:
         token = f.read().strip()
 
-    db = {}
-    try:
-        with open(PULL_REQUEST_DB, 'rb') as f:
-            db = pickle.load(f)
-    except (IOError, OSError) as e:
-        if e.errno != errno.ENOENT:
-            raise
-
     g = github.Github(GITHUB_USERNAME, token, per_page=250)
     r = g.get_repo(GITHUB_REPO)
 
@@ -99,10 +95,27 @@ def main():
                 state='pending',
                 description=desc)
 
+        print(f"{pr.number}: {db.get(pr.number, '(none)')} -> {pr.head.sha}", 
file=sys.stderr)
         print('{}: {} -> {}'.format(pr.number,
                 db.get(pr.number, '') or '(none)', pr.head.sha),
               file=sys.stderr)
 
+    return to_process
+
+
+def main():
+    PULL_REQUEST_DB = os.environ['PULL_REQUEST_DB']
+
+    db = {}
+    try:
+        with open(PULL_REQUEST_DB, 'rb') as f:
+            db = pickle.load(f)
+    except (IOError, OSError) as e:
+        if e.errno != errno.ENOENT:
+            raise
+
+    to_process = scan_github(db)
+
     with open(PULL_REQUEST_DB + '.tmp', 'wb') as f:
         pickle.dump(db, f)
     os.rename(PULL_REQUEST_DB + '.tmp', PULL_REQUEST_DB)

Reply via email to