3 (defun server (port &optional (background t))
4 (when (not *candle-dir*) (error "Need a candle dir"))
6 ((data-dir (format nil "~Adata" *candle-dir*)))
7 (ensure-directories-exist *candle-dir*)
8 (ensure-directories-exist data-dir)
9 (lame-db:load-known-dbs data-dir)
10 (sb-thread:make-thread
15 (lame-db:save-known-dbs data-dir))))
17 (communication:start-listener port background)))
19 (defun add-project (name src)
21 (not (cl-ppcre:scan "^[0-9A-Za-z-]*$" name))
22 (error "Name contains invalid characters"))
24 (not (git nil "ls-remote" src))
25 (error "Project uri is not a valid git repository"))
27 (find name *all-project* :test #'string= :key #'project-name)
28 (error "Project name already taken"))
30 ((project (make-project :name name :src src)))
31 (ensure-directories-exist (project-dir project))
32 (git project "clone" src ".")
33 (refresh-project project))
36 (defun refresh-project (project)
37 (multiple-value-bind (success code out err) (git project "branch" "-r" "--format" "%(refname) %(objectname)" "--list" "origin/*")
38 (declare (ignore code err))
39 (when (not success) (error "Failed to get branches"))
41 ((branches (find-branch-by-project project)))
42 (mapcar (lambda (branch) (set-branch-in-git branch nil)) branches)
45 (cl-ppcre:register-groups-bind (branch-name sha) ("refs/remotes/origin/(.*) (.*)" line)
49 (find sha (find-job-by-project project) :test #'string= :key #'job-sha)
50 (make-job :status :queued :sha sha :project project :create-date (get-universal-time))))
53 (find branch-name branches :test #'string= :key #'branch-name)
54 (make-branch :name branch-name :project project))))
55 (set-branch-in-git branch t)
56 (set-branch-job branch job))))
57 (cl-ppcre:split "\\n" out)))))
59 (defun delete-project (name)
61 ((project (find name *all-project* :test #'string= :key #'project-name)))
63 (error "Project does not exists"))
64 (sb-ext:delete-directory (project-dir project) :recursive t)
65 (mapcar #'nremove-job (find-job-by-project project))
66 (mapcar #'nremove-branch (find-branch-by-project project))
67 (nremove-project project)))