From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id sE7jGJRubGZ0YAAA62LTzQ:P1 (envelope-from ) for ; Fri, 14 Jun 2024 16:23:48 +0000 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id sE7jGJRubGZ0YAAA62LTzQ (envelope-from ) for ; Fri, 14 Jun 2024 18:23:48 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=inria.fr header.s=dc header.b=IQeWCEyd; spf=pass (aspmx1.migadu.com: domain of "guix-devel-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-devel-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=inria.fr ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1718382228; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=Oao9LZSgJA2VO3TUpgM/xuRqqsuy9UVn+N0JQYoV7Tw=; b=heoXLmrm5pusbN0Wc7tXOXE4PqIgCog4cscQUNaKPgv9lapj4UYu3Toows7k4lyrHs7XZJ kJY2Bx6Pw+uf/cFsosRqFHaLCSZX1Q1bG28fLx2Izx5fGRhMp+N8IV0m70yqPqDMI2ht3z 9PXAPSfm16nK16ukW1/Jbr6mV0iUy+f0qlMbsZi46E6vz8aXe7G+XrDx+f+oahqIppDa71 qjiQFFxZfmR9zTfh3sVMLy+bNQTqLT93roZ8iA++wmp6pvwM9Oiq/KviGCmfkJT7aJMSjm VVdO+OpFY+14Eqz/CBd7d+/ixBNyGnJUa8JweX9jow074uXfV6xlwfJ2a4MXEg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=inria.fr header.s=dc header.b=IQeWCEyd; spf=pass (aspmx1.migadu.com: domain of "guix-devel-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-devel-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=inria.fr ARC-Seal: i=1; s=key1; d=yhetil.org; t=1718382228; a=rsa-sha256; cv=none; b=JciygSFW/GG71z4X+4/4bsmxDcNtyfV2SRSQ4lRhfs2lVv80WMFT76LTA5lMLbsq2yR5Md TUsFCUVsYgrfQBFaoDygc1bdFlrYhlguxnf76eiVqz7vWdxdTc/iqsIEvEGN6Mglmk5VBX p8MC9GfIldKVMsO4lJMX5njzGD9WBH7PRO5R2KhfMfF2TrOYZx57ojp1GtbF9zO0GIOPpx VlkkS+QptygKA9yoRewU1VIZBiPlsotP9UJm5Oclrxupr8ejEX89TqWgf41akCitkdyHou cyvELiCZLfHeMLxb9wghvaIcC5ASX6KMlLOQf8aCYCHyc5mbhUWYTNr6OQn7EA== 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 0A7B610A4B for ; Fri, 14 Jun 2024 18:23:48 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sI9hS-00018F-DI; Fri, 14 Jun 2024 12:22:50 -0400 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 1sHiEp-0002th-Bd for guix-devel@gnu.org; Thu, 13 Jun 2024 07:03:28 -0400 Received: from mail3-relais-sop.national.inria.fr ([192.134.164.104]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sHiEm-0007Ux-9J for guix-devel@gnu.org; Thu, 13 Jun 2024 07:03:27 -0400 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=Oao9LZSgJA2VO3TUpgM/xuRqqsuy9UVn+N0JQYoV7Tw=; b=IQeWCEydWIIyl+/7+lYwlwdQ4HuKhgdNWvQPN5BYkZUQDkkGblht39xD 7Mr2ORmRGbs/Xj4UPGpr4iRo4elrE7LHtHBVGkCQqehcTN0SxkKbDaJ2k NtQ+qbaBfsNaM7iBanJJAbScVN+NYchJY5aflTYQC+ZzGVR3y5cb8mjiL M=; X-IronPort-AV: E=Sophos;i="6.08,234,1712613600"; d="scan'208";a="89586975" 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; 13 Jun 2024 13:03:18 +0200 From: Romain GARBAGE To: guix-devel@gnu.org Cc: ludovic.courtes@inria.fr, Romain GARBAGE Subject: [PATCH Cuirass 3/4] http: Add /admin/gitlab/event. Date: Thu, 13 Jun 2024 13:03:08 +0200 Message-ID: <20240613110311.12126-3-romain.garbage@inria.fr> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240613110311.12126-1-romain.garbage@inria.fr> References: <20240613110311.12126-1-romain.garbage@inria.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=192.134.164.104; envelope-from=romain.garbage@inria.fr; helo=mail3-relais-sop.national.inria.fr X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Fri, 14 Jun 2024 12:22:48 -0400 X-BeenThere: guix-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+larch=yhetil.org@gnu.org Sender: guix-devel-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -9.86 X-Spam-Score: -9.86 X-Migadu-Queue-Id: 0A7B610A4B X-Migadu-Scanner: mx13.migadu.com X-TUID: fR8dPyC57FCQ * src/cuirass/http.scm (url-handler): Add "/admin/gitlab/event". --- src/cuirass/http.scm | 88 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 78 insertions(+), 10 deletions(-) diff --git a/src/cuirass/http.scm b/src/cuirass/http.scm index 0a2a30f..d47333c 100644 --- a/src/cuirass/http.scm +++ b/src/cuirass/http.scm @@ -5,6 +5,7 @@ ;;; Copyright © 2018 Clément Lassieur ;;; Copyright © 2018 Tatiana Sholokhova ;;; Copyright © 2019, 2020 Ricardo Wurmus +;;; Copyright © 2024 Romain Garbage ;;; ;;; This file is part of Cuirass. ;;; @@ -26,6 +27,7 @@ #:use-module (cuirass config) #:use-module (cuirass database) #:use-module ((cuirass base) #:select (evaluation-log-file)) + #:use-module (cuirass gitlab) #:use-module (cuirass metrics) #:use-module (cuirass utils) #:use-module (cuirass logging) @@ -705,6 +707,72 @@ bogus reply is received, return DEFAULT." (('GET "robots.txt") (respond-text %robots-txt)) + ;; Define an API for Gitlab events. + (('POST "admin" "gitlab" "event") + (let* ((params (utf8->string body)) + (event (json->gitlab-event params)) + (content-type (assoc-ref (request-headers request) 'content-type)) + (json? (equal? (car content-type) + 'application/json))) + (if json? + (match (gitlab-event-type event) + ('merge-request + (let* ((merge-request (gitlab-event-value event)) + (spec (gitlab-merge-request->specification merge-request))) + (match (gitlab-merge-request-action merge-request) + ;; New merge request. + ((or "open" "reopen") + (if (not (db-get-specification (specification-name spec))) + (begin + (db-add-or-update-specification spec) + + (unless (call-bridge `(register-jobset ,(specification-name spec)) + bridge) + (log-warning + "cannot notify bridge of the addition of jobset '~a'" + (specification-name spec))) + (respond + (build-response #:code 200 + #:headers + `((location . ,(string->uri-reference "/")))) + #:body "")) + (begin + (log-warning "jobset '~a' already exists" (specification-name spec)) + (respond-json-with-error 400 "Jobset already exists.")))) + ;; Accepted or rejected merge requests receive the same treatment. + ((or "close" "merge") + (let ((spec-name (symbol->string (specification-name spec)))) + (if (db-get-specification spec-name) + (begin + (db-remove-specification spec-name) + (log-info "Removed jobset '~a'" spec-name) + (respond + (build-response #:code 200 + #:headers + `((location . ,(string->uri-reference "/")))) + #:body "")) + (begin + (log-warning "cannot find jobset '~a'" spec-name) + (respond-json-with-error 404 "Jobset not found."))))) + ;; A lot of things can trigger an "update" action. For now they are all + ;; treated the same way: the jobset is reevaluated. + ;; XXX: Copied and adapted from "/jobset//hook/evaluate. + ("update" + (let ((spec-name (symbol->string (specification-name spec)))) + (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."))) + (respond-json-with-error 404 "Jobset not found.")))) + (action (log-warning + "Handling of action '~a' not implemented" + action))))) + (event-type (respond-json-with-error 400 (format #f "Event type \"~a\" not supported." event-type)))) + (respond-json-with-error 400 "This API only supports JSON.")))) + (('POST "admin" "specification" "add") (let* ((spec (body->specification body)) (name (specification-name spec))) @@ -1026,7 +1094,7 @@ bogus reply is received, return DEFAULT." (respond-json-with-error 500 "Parameter not defined!")))) (('GET "api" "evaluations") (let* ((params (request-parameters request)) - (spec (assq-ref params 'spec)) ;optional + (spec (assq-ref params 'spec)) ;optional ;; 'nr parameter is mandatory to limit query size. (nr (assq-ref params 'nr))) (if nr @@ -1233,13 +1301,13 @@ bogus reply is received, return DEFAULT." (build-search-results-table query (with-time-logging - "job search request" - (db-get-builds-by-search - `((query . ,query) - (nr . ,%page-size) - (order . finish-time+build-id) - (border-low-id . ,border-low-id) - (border-high-id . ,border-high-id)))) + "job search request" + (db-get-builds-by-search + `((query . ,query) + (nr . ,%page-size) + (order . finish-time+build-id) + (border-low-id . ,border-low-id) + (border-high-id . ,border-high-id)))) builds-id-min builds-id-max) '() @@ -1367,8 +1435,8 @@ bogus reply is received, return DEFAULT." (if file (if (file-exists? file) (respond-file file #:ttl %static-file-ttl) - (fail 500)) ;something's wrong: it vanished - (fail 404)))) ;no such build product + (fail 500)) ;something's wrong: it vanished + (fail 404)))) ;no such build product (('GET "machine" name) (respond-html -- 2.45.1