Change work dir to include project name, keep around
[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 (defvar *environment* :local
20  "*ENVIRONMENT*
21
22 VALUE TYPE:
23
24   A keyword
25
26 INITIAL VALUE:
27
28   :LOCAL
29
30 DESCRIPTION:
31
32   The environment that candle is currently running.  Useful to do switching in tests
33   or in the .candle file to do extra boot up processing.")
34
35 (define-condition candle-error (error)
36  ((reason :initarg :reason :reader candle-error-reason))
37  (:documentation
38   "An error on the server that needs to be handled in the client.
39
40 This error is usually because some input was incorrect.  The response will
41 have a reason that is a keyword that must be handled.  The current used keywords
42 are:
43
44 - :project-does-not-exist - if the project isn't in the database
45 - :invalid-project-name - the specified name doesn't match the requirements
46 - :invlides-project-uri - the uri isn't reachable by git
47 - :project-name-taken - name is a duplicate
48 - :project-failed-to-get-branches - when refreshing fails
49 - :job-does-not-exist - the specified job can't be found"))
50
51 (setf (documentation 'candle-error-reason 'function)
52  "CANDLE-ERROR-REASON CANDLE-ERROR => REASON
53
54 ARGUMENTS AND VALUES:
55
56   CANDLE-ERROR: the error for the reason
57   REASON: a keyword representing the reason
58
59 DESCRIPTION:
60
61   Returns the reason for this candle error.  See the documentation of
62   the candle-error condition for possible values")
63
64 (defun raise-candle-error (reason) (error (make-instance 'candle-error :reason reason)))
65
66 (lame-db:defdbstruct project name src)
67
68 ; Status here is:
69 ; - :queued - to be run
70 ; - :failed - job failed
71 ; - :succeeded - job succeeded
72 ; - :no-candle-file - no candle file was found
73 ; - :in-progress - job is running
74 (lame-db:defdbstruct job status sha create-date log (project :join project))
75
76 (setf (documentation 'job-project 'function)
77  "JOB-PROJECT JOB => PROJECT
78
79 ARGUMENTS AND VALUES:
80
81   JOB: a job
82   PROJECT: the project for this job
83
84 DESCRIPTION:
85
86   Returns the project for the job in question.")
87
88 ; in-git here refers to whether the branch exists in git.  As branches get deleted,
89 ; this will get set to nil but we keep them around for historical reference
90 (lame-db:defdbstruct branch name in-git (project :join project) (job :join job))
91
92 (setf (documentation 'project-name 'function)
93  "PROJECT-NAME PROJECT => NAME
94
95 ARGUMENTS AND VALUES:
96
97   PROJECT: the project
98   NAME: a string, the name of the job
99
100 DESCRIPTION:
101
102   Returns the name of the project in question.")
103
104 (defun project-dir (project)
105  "PROJECT-DIR PROJECT => DIR
106
107 ARGUMENTS AND VALUES:
108
109   PROJECT: the project
110   DIR: the working directory for the project
111
112 DESCRIPTION:
113
114   Returns the checked out directory for this project, specifically for use
115   in candle.  Resides in the *CANDLE-DIR*."
116  (format nil "~Arepos/~A/" *candle-dir* (project-name project)))