forked from Azure/azure-sdk-for-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deployment.js
614 lines (314 loc) · 30.5 KB
/
deployment.js
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
/*** Generated by streamline 0.4.5 (callbacks) - DO NOT EDIT ***/ var __rt=require('streamline/lib/callbacks/runtime').runtime(__filename),__func=__rt.__func,__cb=__rt.__cb,__tryCatch=__rt.__tryCatch,__forIn=__rt.__forIn; var common = require("../common");
var fs = require("fs");
var path = require("path");
var url = require("url");
var crypto = require("crypto");
var pfx2pem = require("../../util/certificates/pkcs").pfx2pem;
var Channel = require("../channel");
var async = require("async");
var child_process = require("child_process");
var utils = require("../utils");
var constants = require("../constants");
var cacheUtils = require("../cacheUtils");
var GitHubApi = require("github");
exports.init = function(cli) {
var log = cli.output;
var site = cli.category("site");
var scm = site.category("deployment").description("Commands to manage your git deployments");
function getScmChannel(context) {
var parts = url.parse(context.repositoryUri);
var channel = new Channel({
host: parts.hostname,
port: (((parts.port && parseInt(parts.port, 10))) || ((/https/i.test(parts.protocol) ? 443 : 80))),
auth: context.repositoryAuth });
var proxyString = (((process.env.HTTPS_PROXY || process.env.https_proxy) || process.env.ALL_PROXY) || process.env.all_proxy);
if ((proxyString !== undefined)) {
var proxyUrl = url.parse(proxyString);
if (((proxyUrl.protocol !== "http:") && (proxyUrl.protocol !== "https:"))) {
proxyUrl = url.parse(("http://" + proxyString)); } ;
channel = channel.add({ proxy: proxyUrl }); } ;
return channel; };
scm.getScmChannel = getScmChannel;
scm.command("list [name]").whiteListPowershell().usage("[options] [name]").description("List your git deployments").option("-s, --subscription <id>", "use the subscription id").option("-m, --max <count>", "limit the maximum number of results").execute(function __1(name, options, _) { var context, repositoryUri; var __frame = { name: "__1", line: 75 }; return __func(_, this, arguments, __1, 2, __frame, function __$__1() {
context = {
subscription: cli.category("account").lookupSubscriptionId(options.subscription),
maxItems: options.max,
site: {
name: name } };
return ensureRepositoryUri(context, __cb(_, __frame, 9, 26, function ___(__0, __1) { repositoryUri = __1; return (function __$__1(__then) {
if (repositoryUri) {
return listDeployments(context, __cb(_, __frame, 11, 8, __then, true)); } else {
log.error("Repository is not setup"); __then(); } ; })(_); }, true)); }); });
scm.command("show <commitId> [name]").whiteListPowershell().usage("[options] <commitId> [name]").description("Show your git deployment").option("-s, --subscription <id>", "use the subscription id").option("-d, --details", "display log details").execute(function __2(commitId, name, options, _) { var context, repositoryUri, deployment, data, logs, i, details, j; var __frame = { name: "__2", line: 98 }; return __func(_, this, arguments, __2, 3, __frame, function __$__2() {
context = {
subscription: cli.category("account").lookupSubscriptionId(options.subscription),
shortId: commitId,
site: {
name: name } };
return cacheUtils.readCommitId(context, __cb(_, __frame, 9, 25, function ___(__0, __2) { var __1 = !(context.id = __2); return (function __$__2(__then) { if (__1) {
return _(null, log.error((("deployment with " + commitId) + " does not exist"))); } else { __then(); } ; })(function __$__2() {
return ensureRepositoryUri(context, __cb(_, __frame, 13, 26, function ___(__0, __3) { repositoryUri = __3; return (function __$__2(__then) {
if (repositoryUri) {
return scm.doDeploymentGet(context, __cb(_, __frame, 15, 25, function ___(__0, __4) { deployment = __4; return (function __$__2(__then) {
if (log.format().json) {
data = deployment; return (function __$__2(__then) {
if (options.details) {
return getLogDetails(context, __cb(_, __frame, 20, 24, function ___(__0, __5) { data.logs = __5; __then(); }, true)); } else { __then(); } ; })(function __$__2() {
log.json(data); __then(); }); } else {
site.logEachData("info", deployment); return (function __$__2(__then) {
if (options.details) {
return getLogDetails(context, __cb(_, __frame, 27, 23, function ___(__0, __6) { logs = __6;
for (i = 0; (i < logs.length); ++i) {
displayLog(logs[i]);
if (logs[i].details) {
details = logs[i].details;
for (j = 0; (j < details.length); ++j) {
displayLog(details[j]); }; } ; }; __then(); }, true)); } else {
log.help("To see more details, specify -d or --details option"); __then(); } ; })(__then); } ; })(__then); }, true)); } else {
log.error("Repository is not setup"); __then(); } ; })(_); }, true)); }); }, true)); }); });
scm.command("redeploy <commitId> [name]").whiteListPowershell().usage("[options] <commitId> [name]").description("Redeploy your git deployment").option("-s, --subscription <id>", "use the subscription id").option("-q, --quiet", "quiet mode, do not ask for redeploy confirmation").execute(function __3(commitId, name, options, _) { var context, repositoryUri; var __frame = { name: "__3", line: 150 }; return __func(_, this, arguments, __3, 3, __frame, function __$__3() {
context = {
subscription: cli.category("account").lookupSubscriptionId(options.subscription),
shortId: commitId,
site: {
name: name } };
return cacheUtils.readCommitId(context, __cb(_, __frame, 9, 25, function ___(__0, __3) { var __2 = !(context.id = __3); return (function __$__3(__then) { if (__2) {
return _(null, log.error((("deployment with " + commitId) + " does not exist"))); } else { __then(); } ; })(function __$__3() {
return ensureRepositoryUri(context, __cb(_, __frame, 13, 26, function ___(__0, __4) { repositoryUri = __4; return (function __$__3(__then) {
if (repositoryUri) { return (function __$__3(_) {
var __1 = !options.quiet; if (!__1) { return _(null, __1); } ; return site.confirm((("Reploy deployment with " + context.shortId) + " id? (y/n) "), __cb(_, __frame, 15, 31, function ___(__0, __3) { var __2 = !__3; return _(null, __2); }, true)); })(__cb(_, __frame, -149, 17, function ___(__0, __5) { return (function __$__3(__then) { if (__5) { return _(null); } else { __then(); } ; })(function __$__3() {
return scm.doDeploymentPut(context, __cb(_, __frame, 18, 8, function __$__3() {
return listDeployments(context, __cb(_, __frame, 19, 8, __then, true)); }, true)); }); }, true)); } else {
log.error("Repository is not setup"); __then(); } ; })(_); }, true)); }); }, true)); }); });
scm.command("associate [name]").whiteListPowershell().usage("[options] [name]").description("Redeploy your git deployment").option("-s, --subscription <id>", "use the subscription id").option("-u, --username <username>", "The username").option("-p, --password <password>", "The password").execute(function __4(name, options, _) { var context;
function promptForCredentials(_) { var __frame = { name: "promptForCredentials", line: 197 }; return __func(_, this, arguments, promptForCredentials, 0, __frame, function __$promptForCredentials() {
log.help("Enter your github credentials");
console.log(options); return (function __$promptForCredentials(__then) {
if (options.username) {
context.username = options.username; __then(); } else {
return prompt("Username: ", __cb(_, __frame, 8, 29, function ___(__0, __1) { context.username = __1; __then(); }, true)); } ; })(function __$promptForCredentials() { return (function __$promptForCredentials(__then) {
if (options.password) {
context.password = options.password; __then(); } else {
return prompt("Password: ", __cb(_, __frame, 14, 29, function ___(__0, __2) { context.password = __2; __then(); }, true)); } ; })(function __$promptForCredentials() {
context.github = new GitHubApi({ version: "3.0.0" });
context.github.authenticate({
type: "basic",
username: context.username,
password: context.password }); _(); }); }); }); };
function promptForRepository(_) { var repositories, parsedRepositoryUri, pathParts, owner, name, localRepositories; var __frame = { name: "promptForRepository", line: 222 }; return __func(_, this, arguments, promptForRepository, 0, __frame, function __$promptForRepository() {
return scm.doGetRepositories(context, __cb(_, __frame, 1, 27, function ___(__0, __1) { repositories = __1;
return scm.doGetRemoteUri(context, __cb(_, __frame, 3, 28, function ___(__0, __2) { context.remoteUri = __2;
if (context.remoteUri) {
parsedRepositoryUri = url.parse(context.remoteUri);
pathParts = parsedRepositoryUri.pathname.split("/");
if ((pathParts.length === 3)) {
owner = pathParts[1];
name = pathParts[2].split(".")[0];
localRepositories = repositories.filter(function(repository) {
return ((repository.name === name) && (repository.owner.login === owner)); });
if ((localRepositories && (localRepositories.length > 0))) {
context.repository = localRepositories[0]; } ; } ; } ; return (function __$promptForRepository(__then) {
if (!context.repository) {
log.help("Choose a repository");
return choose(repositories.map(function(repository) {
return repository.full_name; }), __cb(_, __frame, 22, 44, function ___(__0, __3) { context.repository = repositories[__3]; __then(); }, true)); } else { __then(); } ; })(_); }, true)); }, true)); }); };
function linkRemoteGitRepo(_) { var parsedRepositoryUri, hookUrl, hooks, existingHook; var __frame = { name: "linkRemoteGitRepo", line: 250 }; return __func(_, this, arguments, linkRemoteGitRepo, 0, __frame, function __$linkRemoteGitRepo() {
parsedRepositoryUri = url.parse(context.repositoryUri);
parsedRepositoryUri.auth = context.repositoryAuth;
parsedRepositoryUri.pathname = "/deploy";
hookUrl = url.format(parsedRepositoryUri);
context.hook = {
name: "web",
user: context.repository.owner.login,
repo: context.repository.name,
active: true,
events: ["push",],
config: {
url: hookUrl,
content_type: "json" } };
return scm.doGetHooks(context, __cb(_, __frame, 18, 20, function ___(__0, __1) { hooks = __1;
existingHook = hooks.filter(function(hook) { if (hook.config) { return ((hook.name === "web") && (url.parse(hook.config.url).hostname === parsedRepositoryUri.hostname)); } ; return false; })[0]; return (function __$linkRemoteGitRepo(__then) {
if (existingHook) { return (function __$linkRemoteGitRepo(__then) {
if ((existingHook.config.url !== context.hook.config.url)) {
existingHook.config.url = context.hook.config.url;
context.hook = existingHook;
return scm.doUpdateHook(context, __cb(_, __frame, 33, 12, __then, true)); } else {
log.info("Link already established"); __then(); } ; })(__then); } else {
return scm.doCreateHook(context, __cb(_, __frame, 38, 10, __then, true)); } ; })(_); }, true)); }); };
function addRemoteToLocalGitRepo(_) { var gitUri; var __frame = { name: "addRemoteToLocalGitRepo", line: 292 }; return __func(_, this, arguments, addRemoteToLocalGitRepo, 0, __frame, function __$addRemoteToLocalGitRepo() {
if (context.remoteUri) { return _(null); } ;
gitUri = context.repository.git_url;
log.info((("Executing `git remote add azure " + gitUri) + "`"));
return exec(("git remote add azure " + gitUri), __cb(_, __frame, 9, 8, _, true)); }); }; var __frame = { name: "__4", line: 182 }; return __func(_, this, arguments, __4, 2, __frame, function __$__4() { context = { subscription: cli.category("account").lookupSubscriptionId(options.subscription), site: { name: name } }; return ensureRepositoryUri(context, __cb(_, __frame, 9, 6, function __$__4() { return promptForCredentials(__cb(_, __frame, 10, 6, function __$__4() { return promptForRepository(__cb(_, __frame, 11, 6, function __$__4() { return linkRemoteGitRepo(__cb(_, __frame, 12, 6, function __$__4() { return addRemoteToLocalGitRepo(__cb(_, __frame, 13, 6, _, true)); }, true)); }, true)); }, true)); }, true)); }); });
scm.doCreateHook = function scm_doCreateHook__5(context, _) { var progress; var __frame = { name: "scm_doCreateHook__5", line: 305 }; return __func(_, this, arguments, scm_doCreateHook__5, 1, __frame, function __$scm_doCreateHook__5() {
progress = cli.progress("Creating new hook"); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$scm_doCreateHook__5() {
return context.github.repos.createHook(context.hook, __cb(_, __frame, 4, 6, function __$scm_doCreateHook__5() { _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$scm_doCreateHook__5() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, _); }); }); };
scm.doUpdateHook = function scm_doUpdateHook__6(context, _) { var progress; var __frame = { name: "scm_doUpdateHook__6", line: 315 }; return __func(_, this, arguments, scm_doUpdateHook__6, 1, __frame, function __$scm_doUpdateHook__6() {
progress = cli.progress("Updating hook"); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$scm_doUpdateHook__6() {
return context.github.repos.updateHook(context.hook, __cb(_, __frame, 4, 6, function __$scm_doUpdateHook__6() { _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$scm_doUpdateHook__6() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, _); }); }); };
scm.doGetHooks = function scm_doGetHooks__7(context, _) { var progress; var __frame = { name: "scm_doGetHooks__7", line: 325 }; return __func(_, this, arguments, scm_doGetHooks__7, 1, __frame, function __$scm_doGetHooks__7() {
progress = cli.progress("Retrieving website hooks"); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$scm_doGetHooks__7() {
return context.github.repos.getHooks({
user: context.repository.owner.login,
repo: context.repository.name }, __cb(_, __frame, 4, 13, _, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$scm_doGetHooks__7() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, _); }); }); };
scm.doGetRemoteUri = function scm_doGetRemoteUri__8(context, _) { var progress, originUri;
function getRemote(name, _) { var remotes, origin; var __frame = { name: "getRemote", line: 343 }; return __func(_, this, arguments, getRemote, 1, __frame, function __$getRemote() {
return exec("git remote -v", __cb(_, __frame, 1, 22, function ___(__0, __1) { remotes = __1;
origin = ((remotes.stdout + remotes.stderr)).split("\n").filter(function(item) {
return item.split(" ").some(function(it) {
return (it === name); }); });
if ((origin && (origin.length > 0))) {
return _(null, origin[0].split(" ")[1].split(" ")[0]); } ;
return _(null, null); }, true)); }); }; var __frame = { name: "scm_doGetRemoteUri__8", line: 338 }; return __func(_, this, arguments, scm_doGetRemoteUri__8, 1, __frame, function __$scm_doGetRemoteUri__8() { progress = cli.progress("Retrieving local git repositories"); originUri = null; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$scm_doGetRemoteUri__8() {
return getRemote("azure", __cb(_, __frame, 20, 18, function ___(__0, __1) { originUri = __1; return (function __$scm_doGetRemoteUri__8(__then) {
if (!originUri) {
return getRemote("origin", __cb(_, __frame, 22, 20, function ___(__0, __2) { originUri = __2; __then(); }, true)); } else { __then(); } ; })(function __$scm_doGetRemoteUri__8() { _(null, null, true); }); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$scm_doGetRemoteUri__8() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$scm_doGetRemoteUri__8() {
return _(null, originUri); }); }); }); };
scm.doGetRepositories = function scm_doGetRepositories__9(context, _) { var progress, userRepos, orgs, i, org; var __frame = { name: "scm_doGetRepositories__9", line: 369 }; return __func(_, this, arguments, scm_doGetRepositories__9, 1, __frame, function __$scm_doGetRepositories__9() {
progress = cli.progress("Retrieving repositories");
userRepos = []; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$scm_doGetRepositories__9() {
return context.github.repos.getFromUser({ user: context.username }, __cb(_, __frame, 5, 18, function ___(__0, __3) { userRepos = __3;
return context.github.user.getOrgs({ user: context.username }, __cb(_, __frame, 6, 17, function ___(__0, __4) { orgs = __4;
var __1 = __forIn(orgs); var __2 = 0; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$scm_doGetRepositories__9() { __more = false; var __8 = (__2 < __1.length); if (__8) { i = __1[__2++]; return (function __$scm_doGetRepositories__9(__then) {
if (orgs.hasOwnProperty(i)) {
org = orgs[i]; return (function __$scm_doGetRepositories__9(__then) {
if (org.login) {
return context.github.repos.getFromOrg({ org: org.login }, __cb(_, __frame, 11, 20, function ___(__0, __5) { repos = __5;
userRepos = userRepos.concat(repos); __then(); }, true)); } else { __then(); } ; })(__then); } else { __then(); } ; })(function __$scm_doGetRepositories__9() { while (__more) { __loop(); }; __more = true; }); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(function __$scm_doGetRepositories__9() { _(null, null, true); }); }, true)); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$scm_doGetRepositories__9() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$scm_doGetRepositories__9() {
return _(null, userRepos); }); }); }); };
scm.doDeploymentsGet = function scm_doDeploymentsGet__10(context, _) { var maxItems, channel, progress, deployments; var __frame = { name: "scm_doDeploymentsGet__10", line: 393 }; return __func(_, this, arguments, scm_doDeploymentsGet__10, 1, __frame, function __$scm_doDeploymentsGet__10() {
maxItems = parseInt(context.maxItems, 10);
if ((!maxItems || (maxItems <= 0))) {
maxItems = 20; } ;
channel = getScmChannel(context).path("deployments").query("$orderby", "ReceivedTime desc").query("$top", maxItems);
progress = cli.progress("Enumerating deployments"); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$scm_doDeploymentsGet__10() {
return channel.GET(__cb(_, __frame, 13, 44, function ___(__0, __1) { deployments = ensureShortCommitId(__1);
return cacheUtils.saveCommitIds(context, deployments, __cb(_, __frame, 14, 6, function __$scm_doDeploymentsGet__10() {
return _(null, deployments.map(formatDeployment)); }, true)); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$scm_doDeploymentsGet__10() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, _); }); }); };
scm.doDeploymentGet = function scm_doDeploymentGet__11(context, _) { var channel, progress; var __frame = { name: "scm_doDeploymentGet__11", line: 414 }; return __func(_, this, arguments, scm_doDeploymentGet__11, 1, __frame, function __$scm_doDeploymentGet__11() {
channel = getScmChannel(context).path("deployments").path(context.id);
progress = cli.progress("Retrieving deployment info"); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$scm_doDeploymentGet__11() {
return channel.GET(__cb(_, __frame, 6, 30, function ___(__0, __2) { var __1 = formatDeployment(__2); return _(null, __1); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$scm_doDeploymentGet__11() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, _); }); }); };
scm.doDeploymentPut = function scm_doDeploymentPut__12(context, _) { var channel, progress; var __frame = { name: "scm_doDeploymentPut__12", line: 426 }; return __func(_, this, arguments, scm_doDeploymentPut__12, 1, __frame, function __$scm_doDeploymentPut__12() {
channel = getScmChannel(context).path("deployments").path(context.id);
progress = cli.progress("Redeploying deployment"); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$scm_doDeploymentPut__12() {
return channel.PUT(null, __cb(_, __frame, 6, 13, _, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$scm_doDeploymentPut__12() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, _); }); }); };
scm.doLogGet = function scm_doLogGet__13(context, _) { var channel, progress, logs; var __frame = { name: "scm_doLogGet__13", line: 438 }; return __func(_, this, arguments, scm_doLogGet__13, 1, __frame, function __$scm_doLogGet__13() {
channel = getScmChannel(context).path("deployments").path(context.id).path("log");
progress = cli.progress("Retrieving deployment log info"); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$scm_doLogGet__13() {
return channel.GET(__cb(_, __frame, 7, 17, function ___(__0, __1) { logs = __1;
return _(null, logs.map(formatLog)); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$scm_doLogGet__13() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, _); }); }); };
function listDeployments(context, _) { var deployments, authorLength, messageLength; var __frame = { name: "listDeployments", line: 452 }; return __func(_, this, arguments, listDeployments, 1, __frame, function __$listDeployments() {
return scm.doDeploymentsGet(context, __cb(_, __frame, 1, 22, function ___(__0, __1) { deployments = __1;
authorLength = 0; messageLength = 0;
if ((deployments && deployments.length)) {
log.table(deployments, function(row, deployment) {
row.cell("Time", deployment.start_time);
row.cell("Commit id", deployment.shortId);
row.cell("Status", deployment.status);
authorLength = Math.max(deployment.author.length, authorLength);
row.cell("Author", deployment.author, null, Math.min(authorLength, 15));
messageLength = Math.max(deployment.message.length, messageLength);
row.cell("Message", deployment.message, null, Math.min(messageLength, 40)); }); }
else {
log.info("No git deployment found"); } ; _(); }, true)); }); };
function getLogDetails(context, _) { var results, logs, progress, i; var __frame = { name: "getLogDetails", line: 470 }; return __func(_, this, arguments, getLogDetails, 1, __frame, function __$getLogDetails() {
return scm.doLogGet(context, __cb(_, __frame, 2, 15, function ___(__0, __2) { logs = __2; return (function __$getLogDetails(__then) {
if ((logs && logs.length)) {
progress = cli.progress("Retrieving log details"); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$getLogDetails() {
return async.map(logs, function __1(log, _) { var details; var __frame = { name: "__1", line: 476 }; return __func(_, this, arguments, __1, 1, __frame, function __$__1() { return (function __$__1(__then) {
if (log.hasDetails) {
return getScmChannel(context).path("deployments").path(context.id).path("log").path(log.id).GET(__cb(_, __frame, 7, 26, function ___(__0, __1) { details = __1;
return _(null, details.map(formatLog)); }, true)); } else { __then(); } ; })(_); }); }, __cb(_, __frame, 6, 18, function ___(__0, __3) { results = __3; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$getLogDetails() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$getLogDetails() {
for (i = 0; (i < logs.length); ++i) {
if (results[i]) {
logs[i].details = results[i]; } ; };
return _(null, logs); }); }); } else {
log.info("deployment has no detail");
return _(null, []); } ; })(_); }, true)); }); };
function prompt(label, callback) {
cli.prompt(label, function(x) { callback(undefined, x); }); };
function promptPassword(label, callback) {
cli.password(label, function(x) { callback(undefined, x); }); };
function choose(data, callback) {
cli.choose(data, function(x) { callback(undefined, x); }); };
function displayLog(item) {
if ((item.type === "Warning")) {
log.warn(((item.short_time + " ") + item.message)); }
else if ((item.type === "Error")) {
log.error(((item.short_time + " ") + item.message)); }
else {
log.data(((item.short_time + " ") + item.message)); } ; };
function fromJsonDate(str) {
return new Date(str); };
function formatDate(dt) {
var date = dt.getDate(), month = (dt.getMonth() + 1);
date = ((((date < 10) ? "0" : "")) + date);
month = ((((month < 10) ? "0" : "")) + month);
return ((((((dt.getFullYear() + "-") + month) + "-") + date) + " ") + dt.toLocaleTimeString()); };
function dateTimeText(str) {
return formatDate(fromJsonDate(str)); };
function deploymentStatusText(status) {
switch (status) {
case 0: return "Pending"; case 1:
return "Building"; case 2:
return "Deploying"; case 3:
return "Failed"; case 4:
return "Success"; default:
return "Unknown"; }; };
function logTypeText(type) {
switch (type) {
case 0: return "Message"; case 1:
return "Warning"; case 2:
return "Error"; default:
return "Unknown"; }; };
function ensureShortCommitId(deployments) {
return deployments.map(function(deployment) {
deployment.shortId = deployment.id.substr(0, 10);
return deployment; }); };
function ensureRepositoryUri(context, _) { var siteData, repositoryUri; var __frame = { name: "ensureRepositoryUri", line: 569 }; return __func(_, this, arguments, ensureRepositoryUri, 1, __frame, function __$ensureRepositoryUri() {
return site.lookupSiteNameAndWebSpace(context, __cb(_, __frame, 1, 19, function ___(__0, __1) { siteData = __1;
repositoryUri = (siteData && site.getRepositoryUri(siteData)); return (function __$ensureRepositoryUri(__then) {
if (!repositoryUri) {
return site.doSiteGet(context, __cb(_, __frame, 4, 17, function ___(__0, __2) { siteData = __2;
repositoryUri = site.getRepositoryUri(siteData); __then(); }, true)); } else { __then(); } ; })(function __$ensureRepositoryUri() {
if (repositoryUri) {
context.repositoryAuth = site.getRepositoryAuth(siteData);
return _(null, context.repositoryUri = repositoryUri); } ; _(); }); }, true)); }); };
scm.ensureRepositoryUri = ensureRepositoryUri;
function formatDeployment(deployment) {
var timeProperties = ["end_time","last_success_end_time","received_time","start_time",];
for (var i = 0; (i < timeProperties.length); ++i) {
if (deployment[timeProperties[i]]) {
deployment[timeProperties[i]] = dateTimeText(deployment[timeProperties[i]]); } ; };
deployment.complete = (!!deployment.complete).toString();
deployment.status = (deployment.active ? "Active" : deploymentStatusText(deployment.status));
deployment.message = deployment.message.replace(/\s*(.*)\s*?/g, "$1");
delete deployment.active;
delete deployment.status_text;
delete deployment.url;
delete deployment.log_url;
return deployment; };
function formatLog(log) {
log.hasDetails = !!log.details_url;
log.log_time = (log.log_time && dateTimeText(log.log_time));
log.short_time = (log.log_time && log.log_time.replace(/.* +(.*)/g, "$1"));
log.type = logTypeText(log.type);
log.shortId = log.id.substr(0, 10);
delete log.details_url;
return log; };
function exec(cmd, cb) {
child_process.exec(cmd, function(err, stdout, stderr) {
cb(err, {
stdout: stdout,
stderr: stderr }); }); };};