commit:     67d140facf7cb26d9582ad3503dbf0196fb208d2
Author:     Thomas Bracht Laumann Jespersen <t <AT> laumann <DOT> xyz>
AuthorDate: Sat Feb  7 18:26:21 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=67d140fa

pull-request: add prefix to github PRs

Prefix all new PRs from GitHub in the cache with "github/" so we have
a handle on which forge a given PR number is from. Retain backwards
compatibility with plain integers as the cache keys, but add new cache
entries with a "github/" prefix. There is currently no pruning of the
cache, so both should be supported for the time being.

The pull request scanning script now always outputs a PR identifier
prefix with "github/" so we can later support other prefixes.

Also converted all formatted printing to f-strings and ran "ruff
format" on the file scan-pull-requests.py.

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

 pull-request/pull-requests.bash    | 31 ++++++++-----
 pull-request/scan-pull-requests.py | 92 ++++++++++++++++++++------------------
 2 files changed, 67 insertions(+), 56 deletions(-)

diff --git a/pull-request/pull-requests.bash b/pull-request/pull-requests.bash
index c3a7950..f7c3138 100755
--- a/pull-request/pull-requests.bash
+++ b/pull-request/pull-requests.bash
@@ -53,14 +53,21 @@ git pull
 
 # check if we have anything to process
 mkdir -p -- "${pull}"
-prid=$( "${SCRIPT_DIR}"/pull-request/scan-pull-requests.py )
+pr=$( "${SCRIPT_DIR}"/pull-request/scan-pull-requests.py )
+forge="${pr%/*}"
+prid="${pr#*/}"
 
-if [[ -n ${prid} ]]; then
-       echo "${prid}" > "${pull}"/current-pr
+if [[ -n ${pr} ]]; then
+       echo "${pr}" > "${pull}"/current-pr
 
        cd -- "${sync}"
-       ref=refs/pull/${prid}
-       git fetch -f origin "refs/pull/${prid}/head:${ref}"
+       ref=refs/pull/${pr}
+
+       case ${forge} in
+               github) remote="origin" ;;
+               *) echo "unknown forge ${forge}"; exit 1 ;;
+       esac
+       git fetch -f "${remote}" "refs/pull/${prid}/head:${ref}"
 
        hash=$(git rev-parse "${ref}")
 
@@ -71,14 +78,14 @@ if [[ -n ${prid} ]]; then
        cd -- tmp
        git fetch "${sync}" "${ref}:${ref}"
        # start on top of last common commit, like fast-forward would do
-       git branch "pull-${prid}" "$(git merge-base "${ref}" master)"
-       git checkout -q "pull-${prid}"
+       git branch "pull-${forge}-${prid}" "$(git merge-base "${ref}" master)"
+       git checkout -q "pull-${forge}-${prid}"
        # copy existing md5-cache (TODO: try to find previous merge commit)
        rsync -rlpt --delete 
"${mirror}"/metadata/{dtd,glsa,md5-cache,news,xml-schema} metadata
 
        # merge the PR on top of cache
        git tag pre-merge
-       git merge --quiet -m "Merge PR ${prid}" "${ref}"
+       git merge --quiet -m "Merge PR ${pr}" "${ref}"
 
        # update cache
        CONFIG_DIR=${pull}/etc/portage
@@ -88,7 +95,7 @@ if [[ -n ${prid} ]]; then
        cd ..
        git clone -s "${gentooci}" gentoo-ci
        cd -- gentoo-ci
-       git checkout -b "pull-${prid}"
+       git checkout -b "pull-${forge}-${prid}"
        ( cd -- "${pull}"/tmp &&
                time HOME=${pull}/gentoo-ci \
                timeout -k 30s "${CI_TIMEOUT}" pkgcheck --config 
"${CONFIG_DIR}" \
@@ -101,12 +108,12 @@ if [[ -n ${prid} ]]; then
                -w -e -o borked.list *.xml
 
        git add -- *.xml
-       git diff --cached --quiet --exit-code || git commit -a -m "PR ${prid} @ 
$(date -u --date="@${ts}" "+%Y-%m-%d %H:%M:%S UTC")"
+       git diff --cached --quiet --exit-code || git commit -a -m "PR ${pr} @ 
$(date -u --date="@${ts}" "+%Y-%m-%d %H:%M:%S UTC")"
        pr_hash=$(git rev-parse --short HEAD)
-       git push -f origin "pull-${prid}"
+       git push -f origin "pull-${forge}-${prid}"
 
        cd -- "${gentooci}"
-       git push -f origin "pull-${prid}"
+       git push -f origin "pull-${forge}-${prid}"
        curl 
"https://qa-reports-cdn-origin.gentoo.org/cgi-bin/trigger-pull.cgi?gentoo-ci"; 
|| :
 
        # if we have any breakages...

diff --git a/pull-request/scan-pull-requests.py 
b/pull-request/scan-pull-requests.py
index 81a920c..21c378e 100755
--- a/pull-request/scan-pull-requests.py
+++ b/pull-request/scan-pull-requests.py
@@ -18,9 +18,9 @@ def scan_github(db: dict):
     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']
+    GITHUB_USERNAME = os.environ["GITHUB_USERNAME"]
+    GITHUB_TOKEN_FILE = os.environ["GITHUB_TOKEN_FILE"]
+    GITHUB_REPO = os.environ["GITHUB_REPO"]
 
     with open(GITHUB_TOKEN_FILE) as f:
         token = f.read().strip()
@@ -31,84 +31,88 @@ def scan_github(db: dict):
     to_process = []
 
     for pr in r.get_pulls():
+        # Preferred db key
+        pr_key = f"github/{pr.number}"
+        # support pr.number as implicitly a github PR, but default to pr_key
+        db_key = pr.number if pr.number in db else pr_key
         # skip PRs marked noci
-        if any(x.name == 'noci' for x in pr.labels):
-            print('{}: noci'.format(pr.number),
-                  file=sys.stderr)
+        if any(x.name == "noci" for x in pr.labels):
+            print(f"{pr_key}: noci", file=sys.stderr)
 
             # if it made it to the cache, we probably need to wipe
             # pending status
-            if pr.number in db:
+            if db_key in db:
                 commit = r.get_commit(pr.head.sha)
                 for status in commit.get_statuses():
                     # skip foreign statuses
                     if status.creator.login != GITHUB_USERNAME:
                         continue
                     # if it's pending, mark it done
-                    if status.state == 'pending':
+                    if status.state == "pending":
                         commit.create_status(
-                                context='gentoo-ci',
-                                state='success',
-                                description='Checks skipped due to [noci] 
label')
+                            context="gentoo-ci",
+                            state="success",
+                            description="Checks skipped due to [noci] label",
+                        )
                     break
-                del db[pr.number]
+                del db[db_key]
 
             continue
 
         # if it's not cached, get its status
-        if pr.number not in db:
-            print('{}: updating status ...'.format(pr.number), file=sys.stderr)
+        if db_key not in db:
+            print(f"{pr_key}: updating status ...", file=sys.stderr)
             commit = r.get_commit(pr.head.sha)
             for status in commit.get_statuses():
                 # skip foreign statuses
                 if status.creator.login != GITHUB_USERNAME:
                     continue
                 # if it's not pending, mark it done
-                if status.state != 'pending':
-                    db[pr.number] = commit.sha
-                    print('{}: at {}'.format(pr.number, commit.sha),
-                          file=sys.stderr)
+                if status.state != "pending":
+                    db[pr_key] = commit.sha
+                    print(f"{pr_key}: at {commit.sha}", file=sys.stderr)
                 else:
-                    db[pr.number] = ''
-                    print('{}: found pending'.format(pr.number),
-                          file=sys.stderr)
+                    db[pr_key] = ""
+                    print(f"{pr_key}: found pending", file=sys.stderr)
                 break
             else:
-                db[pr.number] = ''
-                print('{}: unprocessed'.format(pr.number),
-                      file=sys.stderr)
+                db[db_key] = ""
+                print(f"{pr_key}: unprocessed", file=sys.stderr)
 
-        if db.get(pr.number, '') != pr.head.sha:
+        if db.get(db_key, "") != pr.head.sha:
             to_process.append(pr)
 
-    to_process = sorted(to_process,
-            key=lambda x: (not any(x.name == 'priority-ci' for x in x.labels), 
x.updated_at))
+    to_process = sorted(
+        to_process,
+        key=lambda x: (
+            not any(x.name == "priority-ci" for x in x.labels),
+            x.updated_at,
+        ),
+    )
     for i, pr in enumerate(to_process):
+        pr_key = f"github/{pr.number}"
+        db_key = pr.number if pr.number in db else pr_key
         commit = r.get_commit(pr.head.sha)
         if i == 0:
-            desc = 'QA checks in progress...'
-            db[pr.number] = commit.sha
+            desc = "QA checks in progress..."
+            db[db_key] = commit.sha
         else:
-            desc = 'QA checks pending. Currently {}. in queue.'.format(i)
-        commit.create_status(
-                context='gentoo-ci',
-                state='pending',
-                description=desc)
+            desc = f"QA checks pending. Currently {i}. in queue."
+        commit.create_status(context="gentoo-ci", 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)
+        print(
+            f"{pr_key}: {db.get(db_key, '') or '(none)'} -> {pr.head.sha}", 
file=sys.stderr
+        )
 
     return to_process
 
 
 def main():
-    PULL_REQUEST_DB = os.environ['PULL_REQUEST_DB']
+    PULL_REQUEST_DB = os.environ["PULL_REQUEST_DB"]
 
     db = {}
     try:
-        with open(PULL_REQUEST_DB, 'rb') as f:
+        with open(PULL_REQUEST_DB, "rb") as f:
             db = pickle.load(f)
     except (IOError, OSError) as e:
         if e.errno != errno.ENOENT:
@@ -116,15 +120,15 @@ def main():
 
     to_process = scan_github(db)
 
-    with open(PULL_REQUEST_DB + '.tmp', 'wb') as f:
+    with open(PULL_REQUEST_DB + ".tmp", "wb") as f:
         pickle.dump(db, f)
-    os.rename(PULL_REQUEST_DB + '.tmp', PULL_REQUEST_DB)
+    os.rename(PULL_REQUEST_DB + ".tmp", PULL_REQUEST_DB)
 
     if to_process:
-        print(to_process[0].number)
+        print(f"github/{to_process[0].number}")
 
     return 0
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     sys.exit(main())

Reply via email to