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 exist"))
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 job->job-information (job)
74 (list (job-sha job) (job-status job) (job-create-date job)))
76 (defun project-branch-information (name)
78 ((project (find name *all-project* :test #'string= :key #'project-name)))
79 (when (not project) (error "Project does not exist"))
84 (job->job-information (branch-job branch))))
85 (remove-if-not #'branch-in-git (find-branch-by-project project)))))
87 (defun project-job-information (name)
89 ((project (find name *all-project* :test #'string= :key #'project-name)))
90 (when (not project) (error "Project does not exist"))
91 (mapcar #'job->job-information (find-job-by-project project))))
93 (defun get-job-log (project-name sha)
95 ((project (find project-name *all-project* :test #'string= :key #'project-name))
100 (and (<= (length sha) (length job-sha)) (string= sha (subseq job-sha 0 (length sha)))))
101 (find-job-by-project project)
103 (when (not project) (error "Project does not exist"))
104 (when (not job) (error "Job does not exist"))