-
Notifications
You must be signed in to change notification settings - Fork 1
/
utterances.74a2fd99.js
2315 lines (1876 loc) · 68.4 KB
/
utterances.74a2fd99.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
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// modules are defined as an array
// [ module function, map of requires ]
//
// map of requires is short require name -> numeric require
//
// anything defined in a previous bundle is accessed via the
// orig method which is the require for previous bundles
parcelRequire = (function (modules, cache, entry, globalName) {
// Save the require from previous bundle to this closure if any
var previousRequire = typeof parcelRequire === 'function' && parcelRequire;
var nodeRequire = typeof require === 'function' && require;
function newRequire(name, jumped) {
if (!cache[name]) {
if (!modules[name]) {
// if we cannot find the module within our internal map or
// cache jump to the current global require ie. the last bundle
// that was added to the page.
var currentRequire = typeof parcelRequire === 'function' && parcelRequire;
if (!jumped && currentRequire) {
return currentRequire(name, true);
}
// If there are other bundles on this page the require from the
// previous one is saved to 'previousRequire'. Repeat this as
// many times as there are bundles until the module is found or
// we exhaust the require chain.
if (previousRequire) {
return previousRequire(name, true);
}
// Try the node require function if it exists.
if (nodeRequire && typeof name === 'string') {
return nodeRequire(name);
}
var err = new Error('Cannot find module \'' + name + '\'');
err.code = 'MODULE_NOT_FOUND';
throw err;
}
localRequire.resolve = resolve;
localRequire.cache = {};
var module = cache[name] = new newRequire.Module(name);
modules[name][0].call(module.exports, localRequire, module, module.exports, this);
}
return cache[name].exports;
function localRequire(x){
return newRequire(localRequire.resolve(x));
}
function resolve(x){
return modules[name][1][x] || x;
}
}
function Module(moduleName) {
this.id = moduleName;
this.bundle = newRequire;
this.exports = {};
}
newRequire.isParcelRequire = true;
newRequire.Module = Module;
newRequire.modules = modules;
newRequire.cache = cache;
newRequire.parent = previousRequire;
newRequire.register = function (id, exports) {
modules[id] = [function (require, module) {
module.exports = exports;
}, {}];
};
var error;
for (var i = 0; i < entry.length; i++) {
try {
newRequire(entry[i]);
} catch (e) {
// Save first error but execute all entries
if (!error) {
error = e;
}
}
}
if (entry.length) {
// Expose entry point to Node, AMD or browser globals
// Based on https://github.com/ForbesLindesay/umd/blob/master/template.js
var mainExports = newRequire(entry[entry.length - 1]);
// CommonJS
if (typeof exports === "object" && typeof module !== "undefined") {
module.exports = mainExports;
// RequireJS
} else if (typeof define === "function" && define.amd) {
define(function () {
return mainExports;
});
// <script>
} else if (globalName) {
this[globalName] = mainExports;
}
}
// Override the current require with this new one
parcelRequire = newRequire;
if (error) {
// throw error from earlier, _after updating parcelRequire_
throw error;
}
return newRequire;
})({"deparam.ts":[function(require,module,exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.deparam = deparam;
exports.param = param;
function deparam(query) {
var match;
var plus = /\+/g;
var search = /([^&=]+)=?([^&]*)/g;
var decode = function decode(s) {
return decodeURIComponent(s.replace(plus, ' '));
};
var params = {};
while (match = search.exec(query)) {
params[decode(match[1])] = decode(match[2]);
}
return params;
}
function param(obj) {
var parts = [];
for (var name in obj) {
if (obj.hasOwnProperty(name) && obj[name]) {
parts.push(encodeURIComponent(name) + "=" + encodeURIComponent(obj[name]));
}
}
return parts.join('&');
}
},{}],"repo-regex.ts":[function(require,module,exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _default = /^([\w-_]+)\/([\w-_.]+)$/i;
exports.default = _default;
},{}],"utterances-api.ts":[function(require,module,exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.UTTERANCES_API = void 0;
var UTTERANCES_API = 'https://api.utteranc.es';
exports.UTTERANCES_API = UTTERANCES_API;
},{}],"oauth.ts":[function(require,module,exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getLoginUrl = getLoginUrl;
exports.loadToken = loadToken;
exports.token = void 0;
var _utterancesApi = require("./utterances-api");
var _deparam = require("./deparam");
var __awaiter = void 0 && (void 0).__awaiter || function (thisArg, _arguments, P, generator) {
function adopt(value) {
return value instanceof P ? value : new P(function (resolve) {
resolve(value);
});
}
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
}
function rejected(value) {
try {
step(generator["throw"](value));
} catch (e) {
reject(e);
}
}
function step(result) {
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
}
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = void 0 && (void 0).__generator || function (thisArg, body) {
var _ = {
label: 0,
sent: function sent() {
if (t[0] & 1) throw t[1];
return t[1];
},
trys: [],
ops: []
},
f,
y,
t,
g;
return g = {
next: verb(0),
"throw": verb(1),
"return": verb(2)
}, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
return this;
}), g;
function verb(n) {
return function (v) {
return step([n, v]);
};
}
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) {
try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0:
case 1:
t = op;
break;
case 4:
_.label++;
return {
value: op[1],
done: false
};
case 5:
_.label++;
y = op[1];
op = [0];
continue;
case 7:
op = _.ops.pop();
_.trys.pop();
continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
_ = 0;
continue;
}
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
_.label = op[1];
break;
}
if (op[0] === 6 && _.label < t[1]) {
_.label = t[1];
t = op;
break;
}
if (t && _.label < t[2]) {
_.label = t[2];
_.ops.push(op);
break;
}
if (t[2]) _.ops.pop();
_.trys.pop();
continue;
}
op = body.call(thisArg, _);
} catch (e) {
op = [6, e];
y = 0;
} finally {
f = t = 0;
}
}
if (op[0] & 5) throw op[1];
return {
value: op[0] ? op[1] : void 0,
done: true
};
}
};
var token = {
value: null
};
exports.token = token;
function getLoginUrl(redirect_uri) {
return _utterancesApi.UTTERANCES_API + "/authorize?" + (0, _deparam.param)({
redirect_uri: redirect_uri
});
}
function loadToken() {
return __awaiter(this, void 0, Promise, function () {
var url, response, t;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (token.value) {
return [2, token.value];
}
url = _utterancesApi.UTTERANCES_API + "/token";
return [4, fetch(url, {
method: 'POST',
mode: 'cors',
credentials: 'include'
})];
case 1:
response = _a.sent();
if (!response.ok) return [3, 3];
return [4, response.json()];
case 2:
t = _a.sent();
token.value = t;
return [2, t];
case 3:
return [2, null];
}
});
});
}
},{"./utterances-api":"utterances-api.ts","./deparam":"deparam.ts"}],"page-attributes.ts":[function(require,module,exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.pageAttributes = void 0;
var _deparam = require("./deparam");
var _repoRegex = _interopRequireDefault(require("./repo-regex"));
var _oauth = require("./oauth");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function readPageAttributes() {
var params = (0, _deparam.deparam)(location.search.substr(1));
var issueTerm = null;
var issueNumber = null;
if ('issue-term' in params) {
issueTerm = params['issue-term'];
if (issueTerm !== undefined) {
if (issueTerm === '') {
throw new Error('When issue-term is specified, it cannot be blank.');
}
if (['title', 'url', 'pathname', 'og:title'].indexOf(issueTerm) !== -1) {
if (!params[issueTerm]) {
throw new Error("Unable to find \"" + issueTerm + "\" metadata.");
}
issueTerm = params[issueTerm];
}
}
} else if ('issue-number' in params) {
issueNumber = +params['issue-number'];
if (issueNumber.toString(10) !== params['issue-number']) {
throw new Error("issue-number is invalid. \"" + params['issue-number']);
}
} else {
throw new Error('"issue-term" or "issue-number" must be specified.');
}
if (!('repo' in params)) {
throw new Error('"repo" is required.');
}
if (!('origin' in params)) {
throw new Error('"origin" is required.');
}
var matches = _repoRegex.default.exec(params.repo);
if (matches === null) {
throw new Error("Invalid repo: \"" + params.repo + "\"");
}
if (params.token) {
_oauth.token.value = params.token;
}
return {
owner: matches[1],
repo: matches[2],
issueTerm: issueTerm,
issueNumber: issueNumber,
autocreate: params.autocreate,
origin: params.origin,
url: params.url,
title: params.title,
description: params.description,
label: params.label,
theme: params.theme || 'github-light'
};
}
var pageAttributes = readPageAttributes();
exports.pageAttributes = pageAttributes;
},{"./deparam":"deparam.ts","./repo-regex":"repo-regex.ts","./oauth":"oauth.ts"}],"encoding.ts":[function(require,module,exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.decodeBase64UTF8 = decodeBase64UTF8;
function decodeBase64UTF8(encoded) {
encoded = encoded.replace(/\s/g, '');
return decodeURIComponent(escape(atob(encoded)));
}
},{}],"github.ts":[function(require,module,exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.setRepoContext = setRepoContext;
exports.readRelNext = readRelNext;
exports.loadJsonFile = loadJsonFile;
exports.loadIssueByTerm = loadIssueByTerm;
exports.loadIssueByNumber = loadIssueByNumber;
exports.loadCommentsPage = loadCommentsPage;
exports.loadUser = loadUser;
exports.createIssue = createIssue;
exports.postComment = postComment;
exports.toggleReaction = toggleReaction;
exports.renderMarkdown = renderMarkdown;
exports.reactionTypes = exports.PAGE_SIZE = void 0;
var _oauth = require("./oauth");
var _encoding = require("./encoding");
var _utterancesApi = require("./utterances-api");
var __awaiter = void 0 && (void 0).__awaiter || function (thisArg, _arguments, P, generator) {
function adopt(value) {
return value instanceof P ? value : new P(function (resolve) {
resolve(value);
});
}
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
}
function rejected(value) {
try {
step(generator["throw"](value));
} catch (e) {
reject(e);
}
}
function step(result) {
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
}
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = void 0 && (void 0).__generator || function (thisArg, body) {
var _ = {
label: 0,
sent: function sent() {
if (t[0] & 1) throw t[1];
return t[1];
},
trys: [],
ops: []
},
f,
y,
t,
g;
return g = {
next: verb(0),
"throw": verb(1),
"return": verb(2)
}, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
return this;
}), g;
function verb(n) {
return function (v) {
return step([n, v]);
};
}
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) {
try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0:
case 1:
t = op;
break;
case 4:
_.label++;
return {
value: op[1],
done: false
};
case 5:
_.label++;
y = op[1];
op = [0];
continue;
case 7:
op = _.ops.pop();
_.trys.pop();
continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
_ = 0;
continue;
}
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
_.label = op[1];
break;
}
if (op[0] === 6 && _.label < t[1]) {
_.label = t[1];
t = op;
break;
}
if (t && _.label < t[2]) {
_.label = t[2];
_.ops.push(op);
break;
}
if (t[2]) _.ops.pop();
_.trys.pop();
continue;
}
op = body.call(thisArg, _);
} catch (e) {
op = [6, e];
y = 0;
} finally {
f = t = 0;
}
}
if (op[0] & 5) throw op[1];
return {
value: op[0] ? op[1] : void 0,
done: true
};
}
};
var GITHUB_API = 'https://api.github.com/';
var GITHUB_ENCODING__HTML_JSON = 'application/vnd.github.VERSION.html+json';
var GITHUB_ENCODING__HTML = 'application/vnd.github.VERSION.html';
var GITHUB_ENCODING__REACTIONS_PREVIEW = 'application/vnd.github.squirrel-girl-preview';
var PAGE_SIZE = 25;
exports.PAGE_SIZE = PAGE_SIZE;
var reactionTypes = ['+1', '-1', 'laugh', 'hooray', 'confused', 'heart', 'rocket', 'eyes'];
exports.reactionTypes = reactionTypes;
var owner;
var repo;
var branch = 'master';
function setRepoContext(context) {
owner = context.owner;
repo = context.repo;
}
function githubRequest(relativeUrl, init) {
init = init || {};
init.mode = 'cors';
init.cache = 'no-cache';
var request = new Request(GITHUB_API + relativeUrl, init);
request.headers.set('Accept', GITHUB_ENCODING__REACTIONS_PREVIEW);
if (!/^search\//.test(relativeUrl) && _oauth.token.value !== null) {
request.headers.set('Authorization', "token " + _oauth.token.value);
}
return request;
}
var rateLimit = {
standard: {
limit: Number.MAX_VALUE,
remaining: Number.MAX_VALUE,
reset: 0
},
search: {
limit: Number.MAX_VALUE,
remaining: Number.MAX_VALUE,
reset: 0
}
};
function processRateLimit(response) {
var limit = response.headers.get('X-RateLimit-Limit');
var remaining = response.headers.get('X-RateLimit-Remaining');
var reset = response.headers.get('X-RateLimit-Reset');
var isSearch = /\/search\//.test(response.url);
var rate = isSearch ? rateLimit.search : rateLimit.standard;
rate.limit = +limit;
rate.remaining = +remaining;
rate.reset = +reset;
if (response.status === 403 && rate.remaining === 0) {
var resetDate = new Date(0);
resetDate.setUTCSeconds(rate.reset);
var mins = Math.round((resetDate.getTime() - new Date().getTime()) / 1000 / 60);
var apiType = isSearch ? 'search API' : 'non-search APIs';
console.warn("Rate limit exceeded for " + apiType + ". Resets in " + mins + " minute" + (mins === 1 ? '' : 's') + ".");
}
}
function readRelNext(response) {
var link = response.headers.get('link');
if (link === null) {
return 0;
}
var match = /\?page=([2-9][0-9]*)>; rel="next"/.exec(link);
if (match === null) {
return 0;
}
return +match[1];
}
function githubFetch(request) {
return fetch(request).then(function (response) {
if (response.status === 401) {
_oauth.token.value = null;
}
if (response.status === 403) {
response.json().then(function (data) {
if (data.message === 'Resource not accessible by integration') {
window.dispatchEvent(new CustomEvent('not-installed'));
}
});
}
processRateLimit(response);
if (request.method === 'GET' && [401, 403].indexOf(response.status) !== -1 && request.headers.has('Authorization')) {
request.headers.delete('Authorization');
return githubFetch(request);
}
return response;
});
}
function loadJsonFile(path, html) {
if (html === void 0) {
html = false;
}
var request = githubRequest("repos/" + owner + "/" + repo + "/contents/" + path + "?ref=" + branch);
if (html) {
request.headers.set('accept', GITHUB_ENCODING__HTML);
}
return githubFetch(request).then(function (response) {
if (response.status === 404) {
throw new Error("Repo \"" + owner + "/" + repo + "\" does not have a file named \"" + path + "\" in the \"" + branch + "\" branch.");
}
if (!response.ok) {
throw new Error("Error fetching " + path + ".");
}
return html ? response.text() : response.json();
}).then(function (file) {
if (html) {
return file;
}
var content = file.content;
var decoded = (0, _encoding.decodeBase64UTF8)(content);
return JSON.parse(decoded);
});
}
function loadIssueByTerm(term) {
var q = "\"" + term + "\" type:issue in:title repo:" + owner + "/" + repo;
var request = githubRequest("search/issues?q=" + encodeURIComponent(q) + "&sort=created&order=asc");
return githubFetch(request).then(function (response) {
if (!response.ok) {
throw new Error('Error fetching issue via search.');
}
return response.json();
}).then(function (results) {
if (results.total_count === 0) {
return null;
}
if (results.total_count > 1) {
console.warn("Multiple issues match \"" + q + "\".");
}
term = term.toLowerCase();
for (var _i = 0, _a = results.items; _i < _a.length; _i++) {
var result = _a[_i];
if (result.title.toLowerCase().indexOf(term) !== -1) {
return result;
}
}
console.warn("Issue search results do not contain an issue with title matching \"" + term + "\". Using first result.");
return results.items[0];
});
}
function loadIssueByNumber(issueNumber) {
var request = githubRequest("repos/" + owner + "/" + repo + "/issues/" + issueNumber);
return githubFetch(request).then(function (response) {
if (!response.ok) {
throw new Error('Error fetching issue via issue number.');
}
return response.json();
});
}
function commentsRequest(issueNumber, page) {
var url = "repos/" + owner + "/" + repo + "/issues/" + issueNumber + "/comments?page=" + page + "&per_page=" + PAGE_SIZE;
var request = githubRequest(url);
var accept = GITHUB_ENCODING__HTML_JSON + "," + GITHUB_ENCODING__REACTIONS_PREVIEW;
request.headers.set('Accept', accept);
return request;
}
function loadCommentsPage(issueNumber, page) {
var request = commentsRequest(issueNumber, page);
return githubFetch(request).then(function (response) {
if (!response.ok) {
throw new Error('Error fetching comments.');
}
return response.json();
});
}
function loadUser() {
if (_oauth.token.value === null) {
return Promise.resolve(null);
}
return githubFetch(githubRequest('user')).then(function (response) {
if (response.ok) {
return response.json();
}
return null;
});
}
function createIssue(issueTerm, documentUrl, title, description, label) {
var url = _utterancesApi.UTTERANCES_API + "/repos/" + owner + "/" + repo + "/issues" + (label ? "?label=" + encodeURIComponent(label) : '');
var request = new Request(url, {
method: 'POST',
body: JSON.stringify({
title: issueTerm,
body: "# " + title + "\n\n" + description + "\n\n[" + documentUrl + "](" + documentUrl + ")"
})
});
request.headers.set('Accept', GITHUB_ENCODING__REACTIONS_PREVIEW);
request.headers.set('Authorization', "token " + _oauth.token.value);
return fetch(request).then(function (response) {
if (!response.ok) {
throw new Error('Error creating comments container issue');
}
return response.json();
});
}
function postComment(issueNumber, markdown) {
var url = "repos/" + owner + "/" + repo + "/issues/" + issueNumber + "/comments";
var body = JSON.stringify({
body: markdown
});
var request = githubRequest(url, {
method: 'POST',
body: body
});
var accept = GITHUB_ENCODING__HTML_JSON + "," + GITHUB_ENCODING__REACTIONS_PREVIEW;
request.headers.set('Accept', accept);
return githubFetch(request).then(function (response) {
if (!response.ok) {
throw new Error('Error posting comment.');
}
return response.json();
});
}
function toggleReaction(url, content) {
return __awaiter(this, void 0, void 0, function () {
var body, postRequest, response, reaction, _a, deleteRequest;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
url = url.replace(GITHUB_API, '');
body = JSON.stringify({
content: content
});
postRequest = githubRequest(url, {
method: 'POST',
body: body
});
postRequest.headers.set('Accept', GITHUB_ENCODING__REACTIONS_PREVIEW);
return [4, githubFetch(postRequest)];
case 1:
response = _b.sent();
if (!response.ok) return [3, 3];
return [4, response.json()];
case 2:
_a = _b.sent();
return [3, 4];
case 3:
_a = null;
_b.label = 4;
case 4:
reaction = _a;
if (response.status === 201) {
return [2, {
reaction: reaction,
deleted: false
}];
}
if (response.status !== 200) {
throw new Error('expected "201 reaction created" or "200 reaction already exists"');
}
deleteRequest = githubRequest("reactions/" + reaction.id, {
method: 'DELETE'
});
deleteRequest.headers.set('Accept', GITHUB_ENCODING__REACTIONS_PREVIEW);
return [4, githubFetch(deleteRequest)];
case 5:
_b.sent();
return [2, {
reaction: reaction,
deleted: true
}];
}
});
});
}
function renderMarkdown(text) {
var body = JSON.stringify({
text: text,
mode: 'gfm',
context: owner + "/" + repo
});
return githubFetch(githubRequest('markdown', {
method: 'POST',
body: body
})).then(function (response) {
return response.text();
});
}
},{"./oauth":"oauth.ts","./encoding":"encoding.ts","./utterances-api":"utterances-api.ts"}],"time-ago.ts":[function(require,module,exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.timeAgo = timeAgo;
var thresholds = [1000, 'second', 1000 * 60, 'minute', 1000 * 60 * 60, 'hour', 1000 * 60 * 60 * 24, 'day', 1000 * 60 * 60 * 24 * 7, 'week', 1000 * 60 * 60 * 24 * 27, 'month'];
var formatOptions = {
month: 'short',
day: 'numeric',
year: 'numeric'
};
function timeAgo(current, value) {
var elapsed = current - value.getTime();
if (elapsed < 5000) {
return 'just now';
}
var i = 0;
while (i + 2 < thresholds.length && elapsed * 1.1 > thresholds[i + 2]) {
i += 2;
}
var divisor = thresholds[i];
var text = thresholds[i + 1];
var units = Math.round(elapsed / divisor);
if (units > 3 && i === thresholds.length - 2) {
return "on " + value.toLocaleDateString(undefined, formatOptions);