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