aboutsummaryrefslogtreecommitdiff
path: root/guix/forge
diff options
context:
space:
mode:
authorArun Isaac2022-12-20 21:15:55 +0000
committerArun Isaac2022-12-20 21:15:55 +0000
commitc51267914d1ad8979554d8e751df7fa5ff42cb3d (patch)
tree8a6cab712e6976c74cc185763d02a5b447e1ebbc /guix/forge
parent42c58a43cda934116abfc1e289294383be4be8a7 (diff)
downloadguix-forge-c51267914d1ad8979554d8e751df7fa5ff42cb3d.tar.gz
guix-forge-c51267914d1ad8979554d8e751df7fa5ff42cb3d.tar.lz
guix-forge-c51267914d1ad8979554d8e751df7fa5ff42cb3d.zip
forge: Refactor extension functions into named functions.
* guix/forge/forge.scm (forge-service-type): Refactor lambda functions into ... (forge-ci-jobs, forge-ci-job-groups, forge-ci-jobs-and-groups, forge-cron-jobs, forge-webhooks): ... new functions.
Diffstat (limited to 'guix/forge')
-rw-r--r--guix/forge/forge.scm114
1 files changed, 67 insertions, 47 deletions
diff --git a/guix/forge/forge.scm b/guix/forge/forge.scm
index f9ef272..a5445b9 100644
--- a/guix/forge/forge.scm
+++ b/guix/forge/forge.scm
@@ -252,6 +252,70 @@ clone and does not include the .git directory."
(format (current-error-port) "Built ~a successfully~%" derivation-output)
derivation-output)))))))
+(define (forge-ci-jobs config)
+ "Return list of CI jobs for forge configuraion @var{config}. Each
+value of the returned list is a @code{<forge-laminar-job>} object."
+ (append-map forge-project-ci-jobs
+ (forge-configuration-projects config)))
+
+(define (forge-ci-job-groups config)
+ "Return list of CI job groups for forge configuration
+@var{config}. Each element of the returned list is a
+@code{<forge-laminar-group>} object."
+ (filter-map (lambda (project)
+ (match (forge-project-ci-jobs project)
+ (() #f)
+ ((job) #f)
+ (jobs
+ (forge-laminar-group
+ (name (forge-project-name project))
+ (regex (string-append "^(?:"
+ (string-join (map forge-laminar-job-name jobs)
+ "|")
+ ")$"))))))
+ (forge-configuration-projects config)))
+
+(define (forge-ci-jobs-and-groups config)
+ "Return list of CI jobs and job groups for forge configuration
+@var{config}. Each element of the returned list is either a
+@code{<forge-laminar-job>} or a @code{<forge-laminar-group>} object."
+ (append (forge-ci-jobs config)
+ (forge-ci-job-groups config)))
+
+(define (forge-cron-jobs config)
+ "Return list of cron jobs for forge configuration @var{config}. Each
+element of the returned list is a G-expression corresponding to an
+mcron job specification."
+ (filter-map (lambda (project)
+ (and (eq? (forge-project-ci-jobs-trigger project)
+ 'cron)
+ (any forge-laminar-job-trigger?
+ (forge-project-ci-jobs project))
+ #~(job '(next-day)
+ #$(program-file
+ (string-append (forge-project-name project)
+ "-cron-job")
+ (ci-jobs-trigger-gexp
+ (forge-project-ci-jobs project)
+ #:reason "Cron job"))
+ #:user "laminar")))
+ (forge-configuration-projects config)))
+
+(define (forge-webhooks config)
+ "Return list of webhooks for forge configuration @var{config}. Return
+value is a list of @code{<webhook-hook>} objects."
+ (filter-map (lambda (project)
+ (and (eq? (forge-project-ci-jobs-trigger project)
+ 'webhook)
+ (any forge-laminar-job-trigger?
+ (forge-project-ci-jobs project))
+ (webhook-hook
+ (id (forge-project-name project))
+ (run (ci-jobs-trigger-gexp
+ (forge-project-ci-jobs project)
+ #:reason "Webhook")))))
+ (forge-configuration-projects config)))
+
(define forge-service-type
(service-type
(name 'forge)
@@ -259,57 +323,13 @@ clone and does not include the .git directory."
(extensions (list (service-extension activation-service-type
forge-activation)
(service-extension forge-laminar-service-type
- (lambda (config)
- (append
- ;; jobs
- (append-map forge-project-ci-jobs
- (forge-configuration-projects config))
- ;; group jobs by project
- (filter-map (lambda (project)
- (match (forge-project-ci-jobs project)
- (() #f)
- ((job) #f)
- (jobs
- (forge-laminar-group
- (name (forge-project-name project))
- (regex (string-append "^(?:"
- (string-join (map forge-laminar-job-name jobs)
- "|")
- ")$"))))))
- (forge-configuration-projects config)))))
- ;; Set up cron jobs to trigger CI jobs for remote
- ;; repositories.
+ forge-ci-jobs-and-groups)
;; TODO: Run CI job only if there are new commits
;; in the remote repository.
(service-extension mcron-service-type
- (lambda (config)
- (filter-map (lambda (project)
- (and (eq? (forge-project-ci-jobs-trigger project)
- 'cron)
- (any forge-laminar-job-trigger?
- (forge-project-ci-jobs project))
- #~(job '(next-day)
- #$(program-file
- (string-append (forge-project-name project)
- "-cron-job")
- (ci-jobs-trigger-gexp
- (forge-project-ci-jobs project)
- #:reason "Cron job"))
- #:user "laminar")))
- (forge-configuration-projects config))))
+ forge-cron-jobs)
(service-extension webhook-service-type
- (lambda (config)
- (filter-map (lambda (project)
- (and (eq? (forge-project-ci-jobs-trigger project)
- 'webhook)
- (any forge-laminar-job-trigger?
- (forge-project-ci-jobs project))
- (webhook-hook
- (id (forge-project-name project))
- (run (ci-jobs-trigger-gexp
- (forge-project-ci-jobs project)
- #:reason "Webhook")))))
- (forge-configuration-projects config))))))
+ forge-webhooks)))
(compose concatenate)
(extend (lambda (config projects)
(forge-configuration