Subject: [bug#76938] [PATCH Cuirass 08/13] forgejo: Extend specification properties content.

From: Romain GARBAGE <[email-masked]>
Date: Tue, 11 Mar 2025 11:34:33 +0100

* src/cuirass/forges/forgejo.scm:
(<forgejo-owner>): New JSON mapping.
(<forgejo-repository>): Add owner and namespace fields.
(<forgejo-pull-request>): Add body field.
(forgejo-pull-request->specification): Add
PULL-REQUEST-TARGET-REPOSITORY-OWNER and PULL-REQUEST-TARGET-NAMESPACE properties.
* tests/forgejo.scm (default-pull-request-json): Add missing fields.
* tests/http.scm (forgejo-pull-request-json-open): Add missing fields.
(forgejo-pull-request-json-close): Add missing fields.
---
 src/cuirass/forges/forgejo.scm | 25 ++++++++++++++++++++-----
 tests/forgejo.scm              | 10 ++++++++++
 tests/http.scm                 | 14 ++++++++++++++
 3 files changed, 44 insertions(+), 5 deletions(-)

diff --git a/src/cuirass/forges/forgejo.scm b/src/cuirass/forges/forgejo.scm
index 9cd846f..3e7f375 100644
--- a/src/cuirass/forges/forgejo.scm
+++ b/src/cuirass/forges/forgejo.scm
@@ -64,14 +64,23 @@
 ;; generating requests during tests.
 (declare-opaque-header! "X-Forgejo-Event")
 
+(define-json-mapping <forgejo-owner>
+  make-forgejo-owner
+  forgejo-owner?
+  json->forgejo-owner
+  (login forgejo-owner-login))
+
 (define-json-mapping <forgejo-repository>
   make-forgejo-repository
   forgejo-repository?
   json->forgejo-repository
-  (name forgejo-repository-name "name"
-        string->symbol)
-  (url  forgejo-repository-url "clone_url")
-  (home-page forgejo-repository-home-page "html_url"))
+  (name      forgejo-repository-name "name"
+             string->symbol)
+  (namespace forgejo-repository-namespace "full_name")
+  (url       forgejo-repository-url "clone_url")
+  (home-page forgejo-repository-home-page "html_url")
+  (owner     forgejo-repository-owner "owner"
+             json->forgejo-owner))
 
 ;; This maps to the top level JSON object.
 (define-json-mapping <forgejo-pull-request-event>
@@ -92,7 +101,8 @@
   (base    forgejo-pull-request-base "base"
            json->forgejo-repository-reference)
   (head    forgejo-pull-request-head "head"
-           json->forgejo-repository-reference))
+           json->forgejo-repository-reference)
+  (body    forgejo-pull-request-body))
 
 ;; This mapping is used to define various JSON objects such as "base" or
 ;; "head".
@@ -161,6 +171,11 @@
           (pull-request-number . ,(forgejo-pull-request-number pull-request))
           (pull-request-target-repository-name
            . ,(forgejo-repository-name repository))
+          (pull-request-target-repository-owner
+           . ,(forgejo-owner-login
+               (forgejo-repository-owner repository)))
+          (pull-request-target-namespace
+           . ,(forgejo-repository-namespace repository))
           (pull-request-target-repository-home-page
            . ,(forgejo-repository-home-page repository))))))))
 
diff --git a/tests/forgejo.scm b/tests/forgejo.scm
index 2528f5b..0a388ba 100644
--- a/tests/forgejo.scm
+++ b/tests/forgejo.scm
@@ -48,7 +48,11 @@
         \"ref\": \"base-branch\",
         \"sha\": \"666af40e8a059fa05c7048a7ac4f2eccbbd0183b\",
         \"repo\": {
+          \"owner\": {
+            \"login\": \"project-owner\"
+          },
           \"name\": \"project-name\",
+          \"full_name\": \"base-repo/project-name\",
           \"clone_url\": \"https://forgejo.instance.test/base-repo/project-name.git\",
           \"html_url\": \"https://forgejo.instance.test/base-repo/project-name\"
         }
@@ -58,7 +62,11 @@
         \"ref\": \"test-branch\",
         \"sha\": \"582af40e8a059fa05c7048a7ac4f2eccbbd0183b\",
         \"repo\": {
+          \"owner\": {
+            \"login\": \"fork-owner\"
+          },
           \"name\": \"fork-name\",
+          \"full_name\": \"fork-owner/fork-name\",
           \"clone_url\": \"https://forgejo.instance.test/source-repo/fork-name.git\",
           \"html_url\": \"https://forgejo.instance.test/source-repo/fork-name\"
         }
@@ -87,6 +95,8 @@
                   (pull-request-url . "https://forgejo.instance.test/base-repo/pulls/1")
                   (pull-request-number . 1)
                   (pull-request-target-repository-name . project-name)
+                  (pull-request-target-repository-owner . "project-owner")
+                  (pull-request-target-namespace . "base-repo/project-name")
                   (pull-request-target-repository-home-page . "https://forgejo.instance.test/base-repo/project-name"))))))
 
 (test-equal "forgejo-request: return value"
diff --git a/tests/http.scm b/tests/http.scm
index bee02c9..74472ad 100644
--- a/tests/http.scm
+++ b/tests/http.scm
@@ -159,7 +159,11 @@
         \"ref\": \"base-branch\",
         \"sha\": \"666af40e8a059fa05c7048a7ac4f2eccbbd0183b\",
         \"repo\": {
+          \"owner\": {
+            \"login\": \"project-owner\"
+          },
           \"name\": \"project-name\",
+          \"full_name\": \"base-repo/project-name\",
           \"clone_url\": \"https://forgejo.instance.test/base-repo/project-name.git\",
           \"html_url\": \"https://forgejo.instance.test/base-repo/project-name\"
         }
@@ -169,6 +173,9 @@
         \"ref\": \"test-branch\",
         \"sha\": \"582af40e8a059fa05c7048a7ac4f2eccbbd0183b\",
         \"repo\": {
+          \"owner\": {
+            \"login\": \"fork-owner\"
+          },
           \"name\": \"fork-name\",
           \"clone_url\": \"https://forgejo.instance.test/source-repo/fork-name.git\",
           \"html_url\": \"https://forgejo.instance.test/source-repo/fork-name\"
@@ -188,7 +195,11 @@
         \"ref\": \"base-branch\",
         \"sha\": \"666af40e8a059fa05c7048a7ac4f2eccbbd0183b\",
         \"repo\": {
+          \"owner\": {
+            \"login\": \"project-owner\"
+          },
           \"name\": \"project-name\",
+          \"full_name\": \"base-repo/project-name\",
           \"clone_url\": \"https://forgejo.instance.test/base-repo/project-name.git\"
         }
       },
@@ -197,6 +208,9 @@
         \"ref\": \"test-branch\",
         \"sha\": \"582af40e8a059fa05c7048a7ac4f2eccbbd0183b\",
         \"repo\": {
+          \"owner\": {
+            \"login\": \"fork-owner\"
+          },
           \"name\": \"fork-name\",
           \"clone_url\": \"https://forgejo.instance.test/source-repo/fork-name.git\"
         }
-- 
2.48.1