From: Frank Duncan Date: Sat, 11 Dec 2021 15:25:49 +0000 (-0600) Subject: Add project refresh X-Git-Url: https://code.consxy.com/gitweb/?a=commitdiff_plain;ds=sidebyside;h=90a0214bc3b5136af1c0d88ca11e5afe3564c1fc;p=candle Add project refresh --- diff --git a/src/main/base.lisp b/src/main/base.lisp index 3fe9dbe..e47c0fb 100644 --- a/src/main/base.lisp +++ b/src/main/base.lisp @@ -3,7 +3,18 @@ (defvar *candle-dir*) (lame-db:defdbstruct project name src) + +; Status here is: +; - :queued - to be run +; - :failed - job failed +; - :succeeded - job succeeded +; - :no-candle-file - no candle file was found +; - :in-progress - job is running (lame-db:defdbstruct job status sha when-run (project :join project)) +; in-git here refers to whether the branch exists in git. As branches get deleted, +; this will get set to nil but we keep them around for historical reference +(lame-db:defdbstruct branch name in-git (project :join project) (job :join job)) + (defun project-dir (project) (format nil "~Arepos/~A/" *candle-dir* (project-name project))) diff --git a/src/main/server.lisp b/src/main/server.lisp index 8d34aa2..79246fb 100644 --- a/src/main/server.lisp +++ b/src/main/server.lisp @@ -29,13 +29,39 @@ (let ((project (make-project :name name :src src))) (ensure-directories-exist (project-dir project)) - (git project "clone" src ".")) + (git project "clone" src ".") + (refresh-project project)) t) +(defun refresh-project (project) + (multiple-value-bind (success code out err) (git project "branch" "-r" "--format" "%(refname) %(objectname)" "--list" "origin/*") + (declare (ignore code err)) + (when (not success) (error "Failed to get branches")) + (let + ((branches (find-branch-by-project project))) + (mapcar (lambda (branch) (set-branch-in-git branch nil)) branches) + (mapcar + (lambda (line) + (cl-ppcre:register-groups-bind (branch-name sha) ("refs/remotes/origin/(.*) (.*)" line) + (let* + ((job + (or + (find sha (find-job-by-project project) :test #'string= :key #'job-sha) + (make-job :status :queued :sha sha :project project))) + (branch + (or + (find branch-name branches :test #'string= :key #'branch-name) + (make-branch :name branch-name :project project)))) + (set-branch-in-git branch t) + (set-branch-job branch job)))) + (cl-ppcre:split "\\n" out))))) + (defun delete-project (name) (let ((project (find name *all-project* :test #'string= :key #'project-name))) (when (not project) (error "Project does not exists")) (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)) (nremove-project project)))