From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id sEeCF7oIW2fZJQAA62LTzQ:P1 (envelope-from ) for ; Thu, 12 Dec 2024 16:00:58 +0000 Received: from aspmx1.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id sEeCF7oIW2fZJQAA62LTzQ (envelope-from ) for ; Thu, 12 Dec 2024 17:00:58 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=tcRTxi+3; dkim=fail ("headers rsa verify failed") header.d=inria.fr header.s=dc header.b=Ohpbv40U; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=inria.fr (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" ARC-Seal: i=1; s=key1; d=yhetil.org; t=1734019258; a=rsa-sha256; cv=none; b=OR5p+LeUygn5hzmA5Qe/MdeVvorvRUDCdBA8f0m9+x5dD/efuaPWol009P0GvXvKICJGxf WaSQtXghzh9ZNldT0HnIzySex6rRt8IvENWS5/Djr/2b9beI6uwbC/2cIcpt4EPWQP04Ac nVTVc5lGk0xaoFjSjOqXd3DjkINPss7tqNeTRec//aDaSX4yp3AqjlhdeR8xn9n2ugHIw7 Mne0RWW4w3lSYB9ltgo1KI25Vf045Yzzasp+y86WQ5+0TV1aMLjUtEvFKjzhDmz8+UE6Dy MQlRizjEH9kfHfwCpXXYzjibFTrHXnX9gHmEBk3MvB2vyvcklilyPoUkgaE2iQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=tcRTxi+3; dkim=fail ("headers rsa verify failed") header.d=inria.fr header.s=dc header.b=Ohpbv40U; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=inria.fr (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1734019258; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=uuJaLNiXzxtTAja5nmSzgKWlJIWvV0W0ssew0kdhAjk=; b=eWTBLDyxTdWeQTlcd7JCi01pajyhKWh/jBkpIdOs6w+cGAxerk390nomfbx80SP8OOgUy2 bI5gHJRrqAMjUnT8bLsTT9CHLLGy2YnhCwiEMc/MU8+Zk6RBw5TvJ8yY0Q/8djwXi3aP8R EGMzw+lYopFXJC2fp7pTGmdwSErkwxf7GK6yO4vvi2hlgpRruWMz8C4Kr7Rvf1R2Ez9HoN mk9Ckz9x3i1ogmG5EKAuwO6pnFbHcb1ib6wsccocf4H+lsbF43PQ4hKgFir6nul+d6f+e6 neBaJZj0ZsStcYeB1aIw40ZGGLn2X2644blKqjccFtWkEGznS905vaYt9rX3yw== Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id CF13983E61 for ; Thu, 12 Dec 2024 17:00:57 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLlbu-00020m-Oe; Thu, 12 Dec 2024 11:00:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLlbo-0001zT-Mk for guix-patches@gnu.org; Thu, 12 Dec 2024 11:00:12 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tLlbo-0000qK-6H for guix-patches@gnu.org; Thu, 12 Dec 2024 11:00:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:Date:From:To:Subject; bh=uuJaLNiXzxtTAja5nmSzgKWlJIWvV0W0ssew0kdhAjk=; b=tcRTxi+3K9RC3WsJ89ekBAOpWdMHN+IquyalWmQT8NkD3DYvfscPIIv3F2uH6W2STu9oYxzNsVXvKtDw47eYwwLBYerjsdALpl03/pJu0WN3sdJ201qvsAC3MXrzs0+ofXDjluhYYc6kK9zMtUI4J4WrDmb7XuXazhfTfZaQWMFu1jJFEVh1wA/fLN7J24pCXgZbtTEB7LzOLmK1Gnv/iZmAvRnJj70Ax+Mug32Ia3pFJDq33jJj9isn8rtO3MG/0xYqrQFSkMkn0syrAadRaqw2RCWLFP2YLZwXrlotLKflPFS0g8UFS+eqluE4BxbZH7/FRyD5bjzj2kYJb0VpTA==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tLlbn-00014o-QU for guix-patches@gnu.org; Thu, 12 Dec 2024 11:00:11 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#74769] [PATCH Cuirass v2 5/7] forgejo: Add module for Forgejo JSON objects definition. Resent-From: Romain GARBAGE Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 12 Dec 2024 16:00:11 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74769 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 74769@debbugs.gnu.org Cc: ludovic.courtes@inria.fr, Romain GARBAGE Received: via spool by 74769-submit@debbugs.gnu.org id=B74769.17340191633604 (code B ref 74769); Thu, 12 Dec 2024 16:00:11 +0000 Received: (at 74769) by debbugs.gnu.org; 12 Dec 2024 15:59:23 +0000 Received: from localhost ([127.0.0.1]:39988 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tLlay-0000vy-IJ for submit@debbugs.gnu.org; Thu, 12 Dec 2024 10:59:23 -0500 Received: from mail3-relais-sop.national.inria.fr ([192.134.164.104]:36970) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tLlar-0000u3-BL for 74769@debbugs.gnu.org; Thu, 12 Dec 2024 10:59:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=inria.fr; s=dc; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uuJaLNiXzxtTAja5nmSzgKWlJIWvV0W0ssew0kdhAjk=; b=Ohpbv40UMtm9xcGotqIcb2fWkkIxmMvKxFtDSCHl6MkSgXdjJVvD1wYW NYpyfrFwba80UNwv4gowgYXTFMw5L+Leiu7Fu953aMvdA4Aaj/z/dN1/i HSsmlwDe8xVKrtVV1uRXHNObFA6PeRWfQ38m+u4D91p+3ywRrv9M5JWOv M=; X-IronPort-AV: E=Sophos;i="6.12,229,1728943200"; d="scan'208";a="104178645" Received: from unknown (HELO guix-A102.bordeaux.inria.fr) ([193.50.110.191]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Dec 2024 16:58:59 +0100 From: Romain GARBAGE Date: Thu, 12 Dec 2024 16:57:53 +0100 Message-ID: <20241212155845.27344-5-romain.garbage@inria.fr> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241212155845.27344-1-romain.garbage@inria.fr> References: <20241212155845.27344-1-romain.garbage@inria.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -1.19 X-Spam-Score: -1.19 X-Migadu-Queue-Id: CF13983E61 X-Migadu-Scanner: mx12.migadu.com X-TUID: icnepM7ZCya8 * Makefile.am: Add src/cuirass/forges/forgejo.scm and tests/forgejo.scm. * src/cuirass/forges/forgejo.scm: Add , , , and record types. (forgejo-pull-request->specification): New variable. * tests/forgejo.scm: Add tests. --- Makefile.am | 2 + src/cuirass/forges/forgejo.scm | 134 +++++++++++++++++++++++++++++++++ tests/forgejo.scm | 80 ++++++++++++++++++++ 3 files changed, 216 insertions(+) create mode 100644 src/cuirass/forges/forgejo.scm create mode 100644 tests/forgejo.scm diff --git a/Makefile.am b/Makefile.am index 2de3419..f38703e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -53,6 +53,7 @@ dist_pkgmodule_DATA = \ src/cuirass/base.scm \ src/cuirass/database.scm \ src/cuirass/forges.scm \ + src/cuirass/forges/forgejo.scm \ src/cuirass/forges/gitlab.scm \ src/cuirass/http.scm \ src/cuirass/logging.scm \ @@ -168,6 +169,7 @@ TESTS = \ ## tests/basic.sh # takes too long to execute tests/store.scm \ tests/database.scm \ + tests/forgejo.scm \ tests/gitlab.scm \ tests/http.scm \ tests/metrics.scm \ diff --git a/src/cuirass/forges/forgejo.scm b/src/cuirass/forges/forgejo.scm new file mode 100644 index 0000000..11133f4 --- /dev/null +++ b/src/cuirass/forges/forgejo.scm @@ -0,0 +1,134 @@ +;;; forgejo.scm -- Forgejo JSON mappings +;;; Copyright © 2024 Romain Garbage +;;; +;;; This file is part of Cuirass. +;;; +;;; Cuirass is free software: you can redistribute it and/or modify +;;; it under the terms of the GNU General Public License as published by +;;; the Free Software Foundation, either version 3 of the License, or +;;; (at your option) any later version. +;;; +;;; Cuirass is distributed in the hope that it will be useful, +;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with Cuirass. If not, see . + +(define-module (cuirass forges forgejo) + #:use-module (cuirass specification) + #:use-module (cuirass forges) + #:use-module (json) + #:use-module (web http) + #:use-module (guix channels) + #:use-module (ice-9 match) + #:export (forgejo-pull-request-event-pull-request + forgejo-pull-request-event-action + json->forgejo-pull-request-event + + forgejo-repository-name + forgejo-repository-url + + json->forgejo-pull-request + + forgejo-pull-request->specification)) + +;;; Commentary: +;;; +;;; This module implements a subset of the Forgejo Webhook API described at +;;; . +;;; +;;; Code: + +;; This declares a specific header for internal consumption, specifically when +;; generating requests during tests. +(declare-opaque-header! "X-Forgejo-Event") + +(define-json-mapping + make-forgejo-repository + forgejo-repository? + json->forgejo-repository + (name forgejo-repository-name "name" + string->symbol) + (url forgejo-repository-url "clone_url")) + +;; This maps to the top level JSON object. +(define-json-mapping + make-forgejo-pull-request-event + forgejo-pull-request-event? + json->forgejo-pull-request-event + (action forgejo-pull-request-event-action "action" + string->symbol) + (pull-request forgejo-pull-request-event-pull-request "pull_request" + json->forgejo-pull-request)) + +(define-json-mapping + make-forgejo-pull-request + forgejo-pull-request? + json->forgejo-pull-request + (number forgejo-pull-request-number "number") + (base forgejo-pull-request-base "base" + json->forgejo-repository-reference) + (head forgejo-pull-request-head "head" + json->forgejo-repository-reference)) + +;; This mapping is used to define various JSON objects such as "base" or +;; "head". +(define-json-mapping + make-forgejo-repository-reference + forgejo-repository-reference? + json->forgejo-repository-reference + (label forgejo-repository-reference-label "label") + (ref forgejo-repository-reference-ref "ref") + (sha forgejo-repository-reference-sha "sha") + (repository forgejo-repository-reference-repository "repo" + json->forgejo-repository)) + +(define* (forgejo-pull-request->specification pull-request #:optional (cuirass-options #f)) + "Returns a SPECIFICATION built out of a FORGEJO-PULL-REQUEST." + (let* ((source-repo-reference (forgejo-pull-request-head pull-request)) + (project-name (forgejo-repository-name + (forgejo-repository-reference-repository + (forgejo-pull-request-base pull-request)))) + (source-branch (forgejo-repository-reference-ref source-repo-reference)) + (source-url (forgejo-repository-url + (forgejo-repository-reference-repository source-repo-reference))) + (id (forgejo-pull-request-number pull-request)) + (name-prefix (if (and cuirass-options + (jobset-options-name-prefix cuirass-options)) + (jobset-options-name-prefix cuirass-options) + 'forgejo-pull-requests)) + (spec-name (string->symbol + (format #f "~a-~a-~a-~a" name-prefix + project-name + source-branch + id))) + (build (if (and cuirass-options + (jobset-options-build cuirass-options)) + (jobset-options-build cuirass-options) + `(channels ,project-name))) + (period (if (and cuirass-options + (jobset-options-period cuirass-options)) + (jobset-options-period cuirass-options) + %default-jobset-options-period)) + (priority (if (and cuirass-options + (jobset-options-priority cuirass-options)) + (jobset-options-priority cuirass-options) + %default-jobset-options-priority)) + (systems (if (and cuirass-options + (jobset-options-systems cuirass-options)) + (jobset-options-systems cuirass-options) + %default-jobset-options-systems))) + (specification + (name spec-name) + (build build) + (channels + (cons* (channel + (name project-name) + (url source-url) + (branch source-branch)) + %default-channels)) + (priority priority) + (period period) + (systems systems)))) diff --git a/tests/forgejo.scm b/tests/forgejo.scm new file mode 100644 index 0000000..fb3e99f --- /dev/null +++ b/tests/forgejo.scm @@ -0,0 +1,80 @@ +;;; forgejo.scm -- tests for (cuirass forgejo) module +;;; Copyright © 2024 Romain GARBAGE +;;; +;;; This file is part of Cuirass. +;;; +;;; Cuirass is free software: you can redistribute it and/or modify +;;; it under the terms of the GNU General Public License as published by +;;; the Free Software Foundation, either version 3 of the License, or +;;; (at your option) any later version. +;;; +;;; Cuirass is distributed in the hope that it will be useful, +;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with Cuirass. If not, see . + +(use-modules (cuirass forges) + (cuirass forges forgejo) + (cuirass specification) + (cuirass utils) + (tests common) + (guix channels) + (json) + (fibers) + (squee) + (web uri) + (web client) + (web response) + (rnrs bytevectors) + (srfi srfi-1) + (srfi srfi-64) + (ice-9 threads) + (ice-9 match)) + +(define default-pull-request-json + "{ + \"action\": \"opened\", + \"pull_request\": { + \"number\": 1, + \"state\": \"open\", + \"base\": { + \"label\": \"base-label\", + \"ref\": \"base-branch\", + \"sha\": \"666af40e8a059fa05c7048a7ac4f2eccbbd0183b\", + \"repo\": { + \"name\": \"project-name\", + \"clone_url\": \"https://forgejo.instance.test/base-repo/project-name.git\" + } + }, + \"head\": { + \"label\": \"test-label\", + \"ref\": \"test-branch\", + \"sha\": \"582af40e8a059fa05c7048a7ac4f2eccbbd0183b\", + \"repo\": { + \"name\": \"fork-name\", + \"clone_url\": \"https://forgejo.instance.test/source-repo/fork-name.git\" + } + } + } + }") + +(test-assert "default-json" + (specifications=? + (let ((event (json->forgejo-pull-request-event default-pull-request-json))) + (forgejo-pull-request->specification + (forgejo-pull-request-event-pull-request event))) + (specification + (name 'forgejo-pull-requests-project-name-test-branch-1) + (build '(channels . (project-name))) + (channels + (cons* (channel + (name 'project-name) + (url "https://forgejo.instance.test/source-repo/fork-name.git") + (branch "test-branch")) + %default-channels)) + (priority %default-jobset-options-priority) + (period %default-jobset-options-period) + (systems %default-jobset-options-systems)))) -- 2.46.0