f5995a4aedc5711435f82b17ce36582826934f16
[candle] / src / main / base.lisp
1 (in-package #:candle)
2
3 (defvar *candle-dir* nil
4  "*CANDLE-DIR*
5
6 VALUE TYPE:
7
8   A pathname or pathstring
9
10 INITIAL VALUE:
11
12   NIL
13
14 DESCRIPTION:
15
16   The main directory for all candle work to be done in.  When the server is running
17   in local mode, this is also the place that builds are built in")
18
19 (define-condition candle-error (error)
20  ((reason :initarg :reason :reader candle-error-reason))
21  (:documentation
22   "An error on the server that needs to be handled in the client.
23
24 This error is usually because some input was incorrect.  The response will
25 have a reason that is a keyword that must be handled.  The current used keywords
26 are:
27
28 - :project-does-not-exist - if the project isn't in the database
29 - :invalid-project-name - the specified name doesn't match the requirements
30 - :invlides-project-uri - the uri isn't reachable by git
31 - :project-name-taken - name is a duplicate
32 - :project-failed-to-get-branches - when refreshing fails
33 - :job-does-not-exist - the specified job can't be found"))
34
35 (setf (documentation 'candle-error-reason 'function)
36  "CANDLE-ERROR-REASON CANDLE-ERROR => REASON
37
38 ARGUMENTS AND VALUES:
39
40   CANDLE-ERROR: the error for the reason
41   REASON: a keyword representing the reason
42
43 DESCRIPTION:
44
45   Returns the reason for this candle error.  See the documentation of
46   the candle-error condition for possible values")
47
48 (defun raise-candle-error (reason) (error (make-instance 'candle-error :reason reason)))
49
50 (lame-db:defdbstruct project name src)
51
52 ; Status here is:
53 ; - :queued - to be run
54 ; - :failed - job failed
55 ; - :succeeded - job succeeded
56 ; - :no-candle-file - no candle file was found
57 ; - :in-progress - job is running
58 (lame-db:defdbstruct job status sha create-date log (project :join project))
59
60 (setf (documentation 'job-project 'function)
61  "JOB-PROJECT JOB => PROJECT
62
63 ARGUMENTS AND VALUES:
64
65   JOB: a job
66   PROJECT: the project for this job
67
68 DESCRIPTION:
69
70   Returns the project for the job in question.")
71
72 ; in-git here refers to whether the branch exists in git.  As branches get deleted,
73 ; this will get set to nil but we keep them around for historical reference
74 (lame-db:defdbstruct branch name in-git (project :join project) (job :join job))
75
76 (defun project-dir (project)
77  "PROJECT-DIR PROJECT => DIR
78
79 ARGUMENTS AND VALUES:
80
81   PROJECT: the project
82   DIR: the working directory for the project
83
84 DESCRIPTION:
85
86   Returns the checked out directory for this project, specifically for use
87   in candle.  Resides in the *CANDLE-DIR*."
88  (format nil "~Arepos/~A/" *candle-dir* (project-name project)))