commit:     059203b559991bce31f8a5e8aa0a25b32537b8a4
Author:     Alfred Wingate <parona <AT> protonmail <DOT> com>
AuthorDate: Sun Oct 26 05:41:43 2025 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Wed Dec 17 16:40:01 2025 +0000
URL:        https://gitweb.gentoo.org/proj/pram.git/commit/?id=059203b5

Add support for Codebergs' api with tokens

No one has complained about rate limits yet, but its no doubt going to
be an issue in our post LLM era.

Signed-off-by: Alfred Wingate <parona <AT> protonmail.com>
Part-of: https://github.com/gentoo/pram/pull/16
Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>

 pram   | 23 +++++++++++++++--------
 pram.1 | 10 +++++++++-
 2 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/pram b/pram
index d333b6d..1bfdce0 100755
--- a/pram
+++ b/pram
@@ -27,8 +27,8 @@ print_help() {
        echo "                   a bug number or URL, can be specified multiple 
times"
        echo "  -e EDITOR, --editor EDITOR"
        echo "                   Override the editor used (default: \${EDITOR})"
-       echo "  --no-api         Don't use the GitHub REST API even if a 
personal"
-       echo "                   access token is present at ~/.github-token"
+       echo "  --no-api         Don't use the Codeberg or GitHub REST API even 
if a personal"
+       echo "                   access token is present at ~/.codeberg-token 
or ~/.github-token"
        echo "  --no-gitconfig   Do not query options via git config"
        echo "  -G, --no-gpgsign"
        echo "                   Do not automatically GPG-sign commits"
@@ -69,7 +69,8 @@ main() {
        local -x LC_COLLATE=C
 
        local am_options=()
-       local api=
+       local api_codeberg=
+       local api_github=
        local bug=()
        local closes=()
        local editor=
@@ -82,9 +83,8 @@ main() {
        local partof=def
        local link_to=
 
-       if [[ -r ~/.github-token ]]; then
-               api=1
-       fi
+       [[ -r ~/.codeberg-token ]] && api_codeberg=1
+       [[ -r ~/.github-token ]] && api_github=1
 
        while [[ ${#} -gt 0 ]]; do
                case ${1} in
@@ -139,7 +139,8 @@ main() {
                                editor=${1#*=}
                                ;;
                        --no-api)
-                               api=
+                               api_codeberg=
+                               api_github=
                                ;;
                        --no-gitconfig)
                                gitconfig=
@@ -305,7 +306,13 @@ main() {
        fi
 
        if [[ -n ${pr} ]]; then
-               if [[ -n ${api} && (
+               if [[ -n ${api_codeberg} && ${pr} == 
*://codeberg.org/*/*/pulls/* ]]; then
+                       # Modify possible patch links to be applicable to the 
Codeberg REST API
+                       # https://codeberg.org/api/swagger
+                       pr=${pr/codeberg.org/codeberg.org\/api\/v1\/repos}
+                       wget --header="Authorization: Bearer $(< 
~/.codeberg-token)" \
+                               -O "${tempdir}/all.patch" "${pr}" || die 
"Fetching patch failed"
+               elif [[ -n ${api_github} && (
                        ${pr} == *://github.com/*/commit/* ||
                        ${pr} == *://github.com/*/compare/* ||
                        ${pr} == *://github.com/*/pull/* )

diff --git a/pram.1 b/pram.1
index 0d12812..45aeb29 100644
--- a/pram.1
+++ b/pram.1
@@ -26,7 +26,8 @@ Override the editor used (default: ${EDITOR})
 Do not query options via git config.
 .TP
 \fB\-\-no\-api\fR
-Don't use the GitHub REST API even if a personal access token is present at 
\fB~/.github-token\fR.
+Don't use the Codeberg or GitHub REST API even if a personal access token
+is present at \fB~/.codeberg-token\fR or \fB~/.github-token\fR.
 .TP
 \fB\-G\fR, \fB\-\-no\-gpgsign\fR
 Do not automatically GPG-sign commits
@@ -75,6 +76,13 @@ string options:
 boolean options (\fB--type bool\fR):
 \fIpram.gpgsign\fR, \fIpram.interactive\fR, \fIpram.signoff\fR
 
+.SH CODEBERG REST API SUPPORT
+PRam will use the Codeberg REST API if a token is present at 
\fB~/.codeberg-token\fR.
+
+.UR https://docs.codeberg.org/advanced/access-token/
+See Codeberg documentation on how to create one
+.UE .
+
 .SH GITHUB REST API SUPPORT
 PRam will use the GitHub REST API if a token is present at 
\fB~/.github-token\fR.
 

Reply via email to