From: Frank Duncan Date: Sat, 18 Dec 2021 16:57:53 +0000 (-0600) Subject: Refactor project not exist error X-Git-Url: https://code.consxy.com/gitweb/gitweb.cgi?a=commitdiff_plain;h=1f486261df0bbc1d8c10265e4736356934aa1b57;p=candle Refactor project not exist error --- diff --git a/src/main/server.lisp b/src/main/server.lisp index f086aa2..320ffbd 100644 --- a/src/main/server.lisp +++ b/src/main/server.lisp @@ -44,6 +44,12 @@ (sb-thread:join-thread save-thread)) sb-ext:*exit-hooks*))) +(defun find-project-by-name-or-die (name) + (when name + (or + (find name *all-project* :test #'string= :key #'project-name) + (raise-candle-error :project-does-not-exist)))) + (defun add-project (name src) (when (not (cl-ppcre:scan "^[0-9A-Za-z-]*$" name)) @@ -63,7 +69,7 @@ (defun refresh-project (name) (let* - ((project (find name *all-project* :test #'string= :key #'project-name)) + ((project (find-project-by-name-or-die name)) (branches (find-branch-by-project project))) (git project "fetch" "origin" "--prune") (multiple-value-bind (success code out err) (git project "branch" "-r" "--format" "%(refname) %(objectname)" "--list" "origin/*") @@ -89,8 +95,7 @@ (defun delete-project (name) (let - ((project (find name *all-project* :test #'string= :key #'project-name))) - (when (not project) (raise-candle-error :project-does-not-exist)) + ((project (find-project-by-name-or-die name))) (sb-ext:delete-directory (project-dir project) :recursive t) (mapcar #'nremove-job (find-job-by-project project)) (mapcar #'nremove-branch (find-branch-by-project project)) @@ -101,8 +106,7 @@ (defun project-branch-information (name) (let - ((project (find name *all-project* :test #'string= :key #'project-name))) - (when (not project) (raise-candle-error :project-does-not-exist)) + ((project (find-project-by-name-or-die name))) (mapcar (lambda (branch) (list @@ -112,8 +116,7 @@ (defun project-job-information (name) (let - ((project (when name (find name *all-project* :test #'string= :key #'project-name)))) - (when (and name (not project)) (raise-candle-error :project-does-not-exist)) + ((project (find-project-by-name-or-die name))) (mapcar #'job->job-information (if project (find-job-by-project project) @@ -129,7 +132,6 @@ (and (<= (length sha) (length job-sha)) (string= sha (subseq job-sha 0 (length sha))))) (find-job-by-project project) :key #'job-sha)))) - (when (not project) (raise-candle-error :project-does-not-exist)) (when (not job) (raise-candle-error :job-does-not-exist)) job)) @@ -145,13 +147,13 @@ (lambda (project) (list (project-name project) - (project-src project))) + (project-src project) + (failures (project-name project)))) *all-project*)) (defun failures (project-name) (let - ((project (when project-name (find project-name *all-project* :test #'string= :key #'project-name)))) - (when (and project-name (not project)) (raise-candle-error :project-does-not-exist)) + ((project (find-project-by-name-or-die project-name))) (length (remove-if-not (lambda (branch) (eql :failed (job-status (branch-job branch))))