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 (format t "Starting processor in ~(~A~) mode~%" *job-system*)
18 (start-processor-thread)
19 (communication:start-listener port background)))
21 (defun add-project (name src)
23 (not (cl-ppcre:scan "^[0-9A-Za-z-]*$" name))
24 (error "Name contains invalid characters"))
26 (not (git nil "ls-remote" src))
27 (error "Project uri is not a valid git repository"))
29 (find name *all-project* :test #'string= :key #'project-name)
30 (error "Project name already taken"))
32 ((project (make-project :name name :src src)))
33 (ensure-directories-exist (project-dir project))
34 (git project "clone" src ".")
35 (refresh-project name))
38 (defun refresh-project (name)
40 ((project (find name *all-project* :test #'string= :key #'project-name))
41 (branches (find-branch-by-project project)))
42 (git project "fetch" "origin" "--prune")
43 (multiple-value-bind (success code out err) (git project "branch" "-r" "--format" "%(refname) %(objectname)" "--list" "origin/*")
44 (declare (ignore code err))
45 (when (not success) (error "Failed to get branches"))
46 (mapcar (lambda (branch) (set-branch-in-git branch nil)) branches)
49 (cl-ppcre:register-groups-bind (branch-name sha) ("refs/remotes/origin/(.*) (.*)" line)
53 (find sha (find-job-by-project project) :test #'string= :key #'job-sha)
54 (make-job :status :queued :sha sha :project project :create-date (get-universal-time))))
57 (find branch-name branches :test #'string= :key #'branch-name)
58 (make-branch :name branch-name :project project))))
59 (set-branch-in-git branch t)
60 (set-branch-job branch job))))
61 (cl-ppcre:split "\\n" out))))
62 (awaken-processor-thread))
64 (defun delete-project (name)
66 ((project (find name *all-project* :test #'string= :key #'project-name)))
67 (when (not project) (error "Project does not exists"))
68 (sb-ext:delete-directory (project-dir project) :recursive t)
69 (mapcar #'nremove-job (find-job-by-project project))
70 (mapcar #'nremove-branch (find-branch-by-project project))
71 (nremove-project project)))
73 (defun project-branch-information (name)
75 ((project (find name *all-project* :test #'string= :key #'project-name)))
76 (when (not project) (error "Project does not exists"))
81 (job-status (branch-job branch))
82 (job-create-date (branch-job branch))
83 (job-sha (branch-job branch))))
84 (remove-if-not #'branch-in-git (find-branch-by-project project)))))
86 (defun project-job-information (name)
88 ((project (find name *all-project* :test #'string= :key #'project-name)))
89 (when (not project) (error "Project does not exists"))
95 (job-create-date job)))
96 (find-job-by-project project))))