This repository has been archived by the owner on Nov 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
workbench.lisp
286 lines (222 loc) · 8.38 KB
/
workbench.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
(in-package #:cache-cache)
;; For interactive debugging
(setf h:*catch-errors-p* nil)
(setf h:*catch-errors-p* t)
(in-package #:cache-cache.gitlab.source)
(import 'cache-cache::source-by-id)
(initialize-projects (source-by-id 1))
(initialize-issues (source-by-id 1))
(cache-filename (source-by-id 1) :issue)
;; => "1-issue"
(cache-pathname (source-by-id 1) :issue)
;; => #P"/home/fstamour/.cache/cache-cache/1-issue.sbin"
(write-cache-file (source-by-id 1) :project)
(write-cache-file (source-by-id 1) :issue)
(read-cache-file (source-by-id 1) :project)
(time
(read-cache-file (source-by-id 1) :issue))
;; 0.623 seconds of real time
;; 0.622624 seconds of total run time (0.614839 user, 0.007785 system)
;; [ Real times consist of 0.044 seconds GC time, and 0.579 seconds non-GC time. ]
;; [ Run times consist of 0.041 seconds GC time, and 0.582 seconds non-GC time. ]
;; 100.00% CPU
;; 2,190,069,700 processor cycles
;; 257,261,856 bytes consed
(in-package #:cache-cache.gitlab.search)
(import 'cache-cache::source-by-id)
(find-issues "clean" (source-by-id 1))
;;;;;;;;;;; Stuff below this is probably out of date
(in-package #:cache-cache)
(initialize-projects)
(initialize-issues)
;;; Group labels to terraform...
;; Get all the root groups' labels
(defvar *group-labels*
(http-request-get-all
(format nil
"~a/groups/~a/labels?per_page=1000"
*base-uri*
*root-group-id*)))
;; Deduplicate the colors
(defvar *color* (make-hash-table :test 'equal))
;; Create a terraform file with one "local" per color
(alexandria:with-output-to-file (stream "./label-colors.tf"
:if-exists :supersede)
(format stream "locals {~%")
(loop :for color :in
(sort (copy-seq
(a:hash-table-keys
(by *group-labels* :key (lambda (label)
(gethash "color" label)))))
#'string<)
:for i :from 0
:do
(setf (gethash color *color*) i)
(format stream " color~d = ~s~%" i color))
(format stream "}"))
(defun sanitize-string (string)
(str:replace-using
`("\\" "\\\\"
,(string #\newline) "\\n"
"\"" "\\\"")
(str:trim string)))
;; Generate a terraform file that contains all the group labels
(alexandria:with-output-to-file (stream "./labels.tf"
:if-exists :supersede)
(loop
;; set importp to t to also generate the import blocks (useful the
;; first time)
:with importp = nil
:for labels-by-name = (by *group-labels* :key 'item-name)
:for name :across (sort
(map 'vector (lambda (label) (gethash "name" label))
*group-labels*)
#'string<)
:for label = (gethash name labels-by-name)
:for id = (item-id label)
:for resource-name = (format nil "label~a" id)
:do
(format stream "~{~?~}"
`(,@ (when importp "
import {
id = \"~a:~a\"
to = gitlab_group_label.~a
}
"
,(list *root-group-id* id resource-name))
"
resource \"gitlab_group_label\" ~s {
group = ~s
name = ~s
description = \"~a\"
color = local.color~d
}
"
,(list
resource-name *root-group-id*
(gethash "name" label)
;; TODO use sanitize-string
(str:replace-using
`("\\" "\\\\"
,(string #\newline) "\\n"
"\"" "\\\"")
(gethash "description" label))
;; (gethash "color" label)
(gethash (gethash "color" label) *color*)
)))))
;; IMO, it took too much time to plan with so many labels, so I move
;; these resources out into another (new) terraform state).
;;
;; Use this to remove them from the state (this takes forever, it might
;; have been faster (but less safe) to pull the state, edit and push).
;; 1. terraform state list | grep gitlab_group_label | xargs -n 1 echo tf state rm > remove-labels-from-state.sh
;; 2. < review remove-labels-from-state.sh >
;; 3. sh remove-labels-from-state.sh
;;; Getting a project's environements' ids (also to import into terraform)
(let ((project-id *the-project-id*))
(defparameter *environments*
(http-request-get-all
(format nil
"~a/projects/~a/environments"
*base-uri*
project-id))
))
;; Show the environments as json, but keeping only the "id" and "name"
;; attributes.
#++
(jzon:stringify
*environments*
:pretty t
:replacer (lambda (k v)
(if (and k (stringp k))
(and (member k '("id" "name" "external_url") :test #'string=) t)
t)))
;; Make an import terraform block for the environments
(loop :for env :across *environments*
:do
(format t "~%import {
id = ~s
to = gitlab_project_environment.apigateway[~s]
}"
(item-id env)
(item-name env)))
;;; Getting all epics
;; TODO updated_after
(defparameter *epics*
(http-request-get-all
(format nil
"~a/groups/~a/epics?per_page=1000"
*base-uri*
*root-group-id*)))
(length *epics*)
(hash-table-count *epics*)
(aref *epics* 0)
;;; Trying to fetch my activities...
;; It seems to always return the last 7 days instead of respecting the
;; :after and :before...
(progn
(format t "~%~%==================~%~%")
(loop :for event :across (http-request-get-all
(puri:render-uri
(make-uri "/api/v4/events"
(format-query
:after "2023-07-04"
:before "2023-07-07"
:scope :all))
nil))
:do (format t "~%~%~a~%"
(alexandria:hash-table-alist event))))
;;; Trying to use serapeum to generate the documentation
;; (asdf:load-system 'serapeum/docs)
;; I had some issues with guix... lol
(load
(merge-pathnames
"docs.lisp"
(asdf:system-source-directory 'serapeum)))
(let ((root (asdf:system-source-directory 'cache-cache))
(home (user-homedir-pathname)))
(if (uiop:absolute-pathname-p (enough-namestring root home))
(error "The system's location ~s is not in the user's home directory (~s), did you load the system from guix or nix?"
root home)
(serapeum.docs:update-function-reference
;; (namestring (uiop:merge-pathnames* root "REFERENCE.md"))
"REFERENCE.md"
:cache-cache)))
;; It failed miserably because swank wasn't able to locate the source
;; of a few symbols. I tried to modify serapeum/docs' code, but too
;; many things assume that source information is available.
;;; "hot-loading" of common lisp systems installed in a guix profile
;;;
;;; I added a guix package definition for my project breeze and
;;; installed it in a profile. I wanted to load it without restarting
;;; the lisp image. I managed to do it by adding the path to the
;;; profile to the enviroment variable XDG_CONFIG_DIRS and calling
;;; (asdf:clear-source-registry). This works because guix's sbcl is
;;; compiled with a patched asdf that looks into all directories in
;;; XDG_CONFIG_DIRS for its configurations.
(defvar *xdg-config-dirs*
(uiop:getenv "XDG_CONFIG_DIRS")
"The original value of the environment variable XDG_CONFIG_DIRS")
;; Update the environment variable
(setf (uiop:getenv
"XDG_CONFIG_DIRS")
(format nil "~a:~a"
*xdg-config-dirs*
(merge-pathnames
"dev/guix-configurations/lisp-profile/etc"
(user-homedir-pathname))))
;; Check the value
(uiop:getenv "XDG_CONFIG_DIRS")
;; Restore the original value
(setf (uiop:getenv "XDG_CONFIG_DIRS") *xdg-config-dirs*)
;; Try to find the system
(asdf:locate-system 'breeze)
;; Try to reload the asdf's configurations
(asdf:clear-source-registry)
;; Try to load the system
(asdf:load-system :breeze :force :all)
;; TODO check if we're on guix, of if guix is available at least
;; TODO ensure that path to profile is in XDG_CONFIG_DIRS
;; TODO locate-system
;; TODO guix install in profile, then clear-source-registry, locate again
(asdf:load-system :flute)