From patchwork Fri Mar 7 11:00:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Romain GARBAGE X-Patchwork-Id: 39754 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 5784427BBEA; Fri, 7 Mar 2025 11:01:25 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-8.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2,RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL, RCVD_IN_VALIDITY_SAFE,SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id BD40327BBE2 for ; Fri, 7 Mar 2025 11:01:24 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tqVS3-0002Ze-Ky; Fri, 07 Mar 2025 06:01:11 -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 1tqVRv-0002AZ-To for guix-patches@gnu.org; Fri, 07 Mar 2025 06:01:04 -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 1tqVRv-0007dM-IY for guix-patches@gnu.org; Fri, 07 Mar 2025 06:01:03 -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=4byisWVRXiihEfcSC6Ae9/T/l6/J2H/qYQw4hGdv/xs=; b=Uo8tYlE2smj1hrbbcKFmclRI+60wnzPImUw9yH5dgenBdGphNz8HwlZhqGcAH02Z0l4j/V0+4RJtqil7HESTRYKExO9GwXNN6VXHDkL4wcWZxe37oxVtkenlCIp/yWk/se1pbLDdU+rJdKKQi7npI4pY9ltZmYuRTrcXbzHxQdl6wzTqzJZ11u+T1avi3lgtoqaS93rMowJACzrSt0zy9dek6XypL1QYHjnr5EYitHbZh6K8atip75WSB+ftJw1kXDveGuxQkN2Q/oa89dFEmDyN9O703YA839cWTWCiTM5z8ujrUOkknKA9GxJg6/dJsPSXuOMx99okpnFn0y75pg==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tqVRv-0000ok-AK for guix-patches@gnu.org; Fri, 07 Mar 2025 06:01:03 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#76809] [PATCH Cuirass 3/3] http: Update Forgejo jobset when PR is updated. Resent-From: Romain GARBAGE Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 07 Mar 2025 11:01:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 76809 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 76809@debbugs.gnu.org Cc: ludovic.courtes@inria.fr, Romain GARBAGE Received: via spool by 76809-submit@debbugs.gnu.org id=B76809.17413452453091 (code B ref 76809); Fri, 07 Mar 2025 11:01:03 +0000 Received: (at 76809) by debbugs.gnu.org; 7 Mar 2025 11:00:45 +0000 Received: from localhost ([127.0.0.1]:47151 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tqVRc-0000ni-Tf for submit@debbugs.gnu.org; Fri, 07 Mar 2025 06:00:45 -0500 Received: from mail2-relais-roc.national.inria.fr ([192.134.164.83]:48252) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1tqVRa-0000mz-El for 76809@debbugs.gnu.org; Fri, 07 Mar 2025 06:00:43 -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=4byisWVRXiihEfcSC6Ae9/T/l6/J2H/qYQw4hGdv/xs=; b=GKr2aXzKuHmhJt6IrcoSuERKKUKEDvqPJC+UinvjUKsEaWavy0nQx129 QT+EUn3MzWM3WL58Otu7azmQPbxPxdL0jEDerkPZVogngsYoSEs5c6meT IE89MLbJBZhgP/j23SN3z1MrRry3aQHONFNtDtWloLPokHq67bRihr0sK c=; Authentication-Results: mail2-relais-roc.national.inria.fr; dkim=none (message not signed) header.i=none; spf=SoftFail smtp.mailfrom=romain.garbage@inria.fr; dmarc=fail (p=none dis=none) d=inria.fr X-IronPort-AV: E=Sophos;i="6.14,229,1736809200"; d="scan'208";a="211751975" Received: from unknown (HELO guix-A102.bordeaux.inria.fr) ([193.50.110.221]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Mar 2025 12:00:34 +0100 From: Romain GARBAGE Date: Fri, 7 Mar 2025 12:00:25 +0100 Message-ID: <20250307110025.12928-3-romain.garbage@inria.fr> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250307110025.12928-1-romain.garbage@inria.fr> References: <20250307110025.12928-1-romain.garbage@inria.fr> MIME-Version: 1.0 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+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * src/cuirass/http.scm (url-handler): Update Forgejo jobset when PR is updated. * tests/http.scm (forgejo-pull-request-json-update): New variable. ("/admin/forgejo/event updates a spec"): New test. --- src/cuirass/http.scm | 14 ++++++++------ tests/http.scm | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/src/cuirass/http.scm b/src/cuirass/http.scm index cfb72e4..a826ef1 100644 --- a/src/cuirass/http.scm +++ b/src/cuirass/http.scm @@ -840,12 +840,14 @@ return DEFAULT." ;; Pull request is updated. ('synchronized (if (db-get-specification spec-name) - (if (call-bridge `(trigger-jobset ,(specification-name spec)) - bridge) - (respond-json (scm->json-string `((jobset . ,spec-name)))) - (begin - (log-warning "evaluation hook disabled") - (respond-json-with-error 400 "Evaluation hook disabled."))) + (begin + (db-add-or-update-specification spec) + (if (call-bridge `(trigger-jobset ,spec-name) + bridge) + (respond-json (scm->json-string `((jobset . ,spec-name)))) + (begin + (log-warning "evaluation hook disabled for spec ~a" spec-name) + (respond-json-with-error 400 "Evaluation hook disabled.")))) (respond-json-with-error 404 "Jobset not found.")))))) (_ (respond-json-with-error 400 (format #f "Event type \"~a\" not supported." event-type)))) (respond-json-with-error 400 "This API only supports JSON.")))) diff --git a/tests/http.scm b/tests/http.scm index a57a4ab..ead4bf3 100644 --- a/tests/http.scm +++ b/tests/http.scm @@ -177,6 +177,36 @@ } }") +(define forgejo-pull-request-json-update + "{ + \"action\": \"synchronized\", + \"pull_request\": { + \"number\": 1, + \"state\": \"open\", + \"url\": \"https://forgejo.instance.test/base-repo/pulls/1\", + \"base\": { + \"label\": \"base-label\", + \"ref\": \"base-branch\", + \"sha\": \"666af40e8a059fa05c7048a7ac4f2eccbbd0183b\", + \"repo\": { + \"name\": \"project-name\", + \"clone_url\": \"https://forgejo.instance.test/base-repo/project-name.git\", + \"html_url\": \"https://forgejo.instance.test/base-repo/project-name\" + } + }, + \"head\": { + \"label\": \"test-label\", + \"ref\": \"test-branch\", + \"sha\": \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\", + \"repo\": { + \"name\": \"fork-name\", + \"clone_url\": \"https://forgejo.instance.test/source-repo/fork-name.git\", + \"html_url\": \"https://forgejo.instance.test/source-repo/fork-name\" + } + } + } + }") + (define forgejo-pull-request-json-close "{ \"action\": \"closed\", @@ -572,6 +602,19 @@ forgejo-pull-request-json-open '((x-forgejo-event . "pull_request"))))) + (test-assert "/admin/forgejo/event updates a spec" + (let* ((spec (forgejo-pull-request->specification + (forgejo-pull-request-event-pull-request + (json->forgejo-pull-request-event forgejo-pull-request-json-update)))) + (spec-name (specification-name forgejo-pull-request-specification))) + (specifications=? + (pk 'expected spec) + (begin + (http-post-json (test-cuirass-uri "/admin/forgejo/event") + forgejo-pull-request-json-update + '((x-forgejo-event . "pull_request"))) + (pk 'actual (db-get-specification spec-name)))))) + (test-assert "/admin/forgejo/event removes a spec from a closed pull request" (begin (http-post-json (test-cuirass-uri "/admin/forgejo/event")