(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)))
(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)))