@@ -68,6 +68,44 @@ def projects(db_path, project, auth):
68
68
token , host = load_config (auth )
69
69
project = utils .fetch_project (project , token , host )
70
70
utils .save_project (db , project )
71
+ utils .ensure_db_shape (db )
72
+
73
+
74
+ @cli .command (name = "merge-requests" )
75
+ @click .argument (
76
+ "db_path" ,
77
+ type = click .Path (file_okay = True , dir_okay = False , allow_dash = False ),
78
+ required = True ,
79
+ )
80
+ @click .argument ("project" , required = True )
81
+ @click .option (
82
+ "-a" ,
83
+ "--auth" ,
84
+ type = click .Path (file_okay = True , dir_okay = False , allow_dash = True ),
85
+ default = "auth.json" ,
86
+ help = "Path to auth.json token file" ,
87
+ )
88
+ @click .option (
89
+ "--full" ,
90
+ is_flag = True ,
91
+ )
92
+ def merge_requests (db_path , project , auth , full ):
93
+ "Save merge requests"
94
+ db = sqlite_utils .Database (db_path )
95
+ token , host = load_config (auth )
96
+
97
+ new = 0
98
+ for merge_request in utils .fetch_merge_requests (
99
+ project ,
100
+ token ,
101
+ host ,
102
+ None if full else utils .get_latest_merge_request_time (db , project ),
103
+ ):
104
+ utils .save_merge_request (db , merge_request )
105
+ new += 1
106
+
107
+ utils .ensure_db_shape (db )
108
+ click .echo (f"Saved/updated { new } merge requests" )
71
109
72
110
73
111
@cli .command (name = "pipelines" )
@@ -84,20 +122,148 @@ def projects(db_path, project, auth):
84
122
default = "auth.json" ,
85
123
help = "Path to auth.json token file" ,
86
124
)
87
- def pipelines (db_path , project , auth ):
125
+ @click .option (
126
+ "--full" ,
127
+ is_flag = True ,
128
+ )
129
+ def pipelines (db_path , project , auth , full ):
88
130
"Save pipelines"
89
131
db = sqlite_utils .Database (db_path )
90
132
token , host = load_config (auth )
91
- latest = utils .get_latest_pipeline_time (db , project )
92
133
93
134
new = 0
94
- for pipeline in utils .fetch_pipelines (project , token , host , latest ):
95
- utils .save_pipeline (db , pipeline )
135
+ for pipeline in utils .fetch_pipelines (
136
+ project ,
137
+ token ,
138
+ host ,
139
+ None if full else utils .get_latest_pipeline_time (db , project ),
140
+ ):
141
+ utils .save_pipeline (db , pipeline , host )
96
142
new += 1
97
143
144
+ utils .ensure_db_shape (db )
98
145
click .echo (f"Saved/updated { new } pipelines" )
99
146
100
147
148
+ @cli .command (name = "environments" )
149
+ @click .argument (
150
+ "db_path" ,
151
+ type = click .Path (file_okay = True , dir_okay = False , allow_dash = False ),
152
+ required = True ,
153
+ )
154
+ @click .argument ("project" , required = True )
155
+ @click .option (
156
+ "-a" ,
157
+ "--auth" ,
158
+ type = click .Path (file_okay = True , dir_okay = False , allow_dash = True ),
159
+ default = "auth.json" ,
160
+ help = "Path to auth.json token file" ,
161
+ )
162
+ def environments (db_path , project , auth ):
163
+ db = sqlite_utils .Database (db_path )
164
+ token , host = load_config (auth )
165
+
166
+ new = 0
167
+ for environment in utils .fetch_environments (
168
+ project ,
169
+ token ,
170
+ host ,
171
+ ):
172
+ utils .save_environment (db , environment )
173
+ new += 1
174
+
175
+ utils .ensure_db_shape (db )
176
+ click .echo (f"Saved/updated { new } environments" )
177
+
178
+
179
+ @cli .command (name = "deployments" )
180
+ @click .argument (
181
+ "db_path" ,
182
+ type = click .Path (file_okay = True , dir_okay = False , allow_dash = False ),
183
+ required = True ,
184
+ )
185
+ @click .argument ("project" , required = True )
186
+ @click .argument ("environment" , required = True )
187
+ @click .option (
188
+ "-a" ,
189
+ "--auth" ,
190
+ type = click .Path (file_okay = True , dir_okay = False , allow_dash = True ),
191
+ default = "auth.json" ,
192
+ help = "Path to auth.json token file" ,
193
+ )
194
+ def deployments (db_path , project , environment , auth ):
195
+ db = sqlite_utils .Database (db_path )
196
+ token , host = load_config (auth )
197
+
198
+ if (
199
+ "deployments" in db .table_names ()
200
+ and "projects" in db .table_names ()
201
+ and "environments" in db .table_names ()
202
+ ):
203
+ r = db .query (
204
+ """
205
+ SELECT
206
+ max(d.updated_at) AS last_update
207
+ FROM
208
+ deployments d
209
+ JOIN projects p ON d.project_id = p.id
210
+ JOIN environments e ON d.environment_id = e.id
211
+ WHERE
212
+ p.full_path = ?
213
+ AND e.name = ?
214
+ """ ,
215
+ [project , environment ],
216
+ )
217
+ last_update = next (r )["last_update" ]
218
+ else :
219
+ last_update = None
220
+
221
+ new = 0
222
+ for deployment in utils .fetch_deployments (
223
+ project ,
224
+ environment ,
225
+ token ,
226
+ host ,
227
+ last_update ,
228
+ ):
229
+ if utils .save_deployment (db , deployment ) is not False :
230
+ new += 1
231
+
232
+ utils .ensure_db_shape (db )
233
+ click .echo (f"Saved/updated { new } deployments" )
234
+
235
+
236
+ @cli .command (name = "commits" )
237
+ @click .argument (
238
+ "db_path" ,
239
+ type = click .Path (file_okay = True , dir_okay = False , allow_dash = False ),
240
+ required = True ,
241
+ )
242
+ @click .argument ("project" , required = True )
243
+ @click .option (
244
+ "-a" ,
245
+ "--auth" ,
246
+ type = click .Path (file_okay = True , dir_okay = False , allow_dash = True ),
247
+ default = "auth.json" ,
248
+ help = "Path to auth.json token file" ,
249
+ )
250
+ def commits (db_path , project , auth ):
251
+ db = sqlite_utils .Database (db_path )
252
+ token , host = load_config (auth )
253
+
254
+ new = 0
255
+ for commit in utils .fetch_commits (
256
+ project ,
257
+ token ,
258
+ host ,
259
+ ):
260
+ utils .save_commit (db , commit )
261
+ new += 1
262
+
263
+ utils .ensure_db_shape (db )
264
+ click .echo (f"Saved/updated { new } commits" )
265
+
266
+
101
267
def load_config (auth ):
102
268
try :
103
269
data = json .load (open (auth ))
0 commit comments