Skip to content

Commit 28afbe9

Browse files
authored
bugfix: add emojis for all IssueEvent action types (opened, reopened, closed) (#107)
1 parent 0cb0dd9 commit 28afbe9

File tree

4 files changed

+99
-31
lines changed

4 files changed

+99
-31
lines changed

dist/index.js

Lines changed: 82 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1877,7 +1877,20 @@ const serializers = {
18771877
)}`;
18781878
},
18791879
IssuesEvent: (item) => {
1880-
const emoji = item.payload.action === "opened" ? "❗" : "🔒";
1880+
let emoji = "";
1881+
1882+
switch (item.payload.action) {
1883+
case "opened":
1884+
emoji = "❗";
1885+
break;
1886+
case "reopened":
1887+
emoji = "🔓";
1888+
break;
1889+
case "closed":
1890+
emoji = "🔒";
1891+
break;
1892+
}
1893+
18811894
return `${emoji} ${capitalize(item.payload.action)} issue ${toUrlFormat(
18821895
item
18831896
)} in ${toUrlFormat(item.repo.name)}`;
@@ -4441,11 +4454,39 @@ var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER ||
44414454
// Max safe segment length for coercion.
44424455
var MAX_SAFE_COMPONENT_LENGTH = 16
44434456

4457+
var MAX_SAFE_BUILD_LENGTH = MAX_LENGTH - 6
4458+
44444459
// The actual regexps go on exports.re
44454460
var re = exports.re = []
4461+
var safeRe = exports.safeRe = []
44464462
var src = exports.src = []
44474463
var R = 0
44484464

4465+
var LETTERDASHNUMBER = '[a-zA-Z0-9-]'
4466+
4467+
// Replace some greedy regex tokens to prevent regex dos issues. These regex are
4468+
// used internally via the safeRe object since all inputs in this library get
4469+
// normalized first to trim and collapse all extra whitespace. The original
4470+
// regexes are exported for userland consumption and lower level usage. A
4471+
// future breaking change could export the safer regex only with a note that
4472+
// all input should have extra whitespace removed.
4473+
var safeRegexReplacements = [
4474+
['\\s', 1],
4475+
['\\d', MAX_LENGTH],
4476+
[LETTERDASHNUMBER, MAX_SAFE_BUILD_LENGTH],
4477+
]
4478+
4479+
function makeSafeRe (value) {
4480+
for (var i = 0; i < safeRegexReplacements.length; i++) {
4481+
var token = safeRegexReplacements[i][0]
4482+
var max = safeRegexReplacements[i][1]
4483+
value = value
4484+
.split(token + '*').join(token + '{0,' + max + '}')
4485+
.split(token + '+').join(token + '{1,' + max + '}')
4486+
}
4487+
return value
4488+
}
4489+
44494490
// The following Regular Expressions can be used for tokenizing,
44504491
// validating, and parsing SemVer version strings.
44514492

@@ -4455,14 +4496,14 @@ var R = 0
44554496
var NUMERICIDENTIFIER = R++
44564497
src[NUMERICIDENTIFIER] = '0|[1-9]\\d*'
44574498
var NUMERICIDENTIFIERLOOSE = R++
4458-
src[NUMERICIDENTIFIERLOOSE] = '[0-9]+'
4499+
src[NUMERICIDENTIFIERLOOSE] = '\\d+'
44594500

44604501
// ## Non-numeric Identifier
44614502
// Zero or more digits, followed by a letter or hyphen, and then zero or
44624503
// more letters, digits, or hyphens.
44634504

44644505
var NONNUMERICIDENTIFIER = R++
4465-
src[NONNUMERICIDENTIFIER] = '\\d*[a-zA-Z-][a-zA-Z0-9-]*'
4506+
src[NONNUMERICIDENTIFIER] = '\\d*[a-zA-Z-]' + LETTERDASHNUMBER + '*'
44664507

44674508
// ## Main Version
44684509
// Three dot-separated numeric identifiers.
@@ -4504,7 +4545,7 @@ src[PRERELEASELOOSE] = '(?:-?(' + src[PRERELEASEIDENTIFIERLOOSE] +
45044545
// Any combination of digits, letters, or hyphens.
45054546

45064547
var BUILDIDENTIFIER = R++
4507-
src[BUILDIDENTIFIER] = '[0-9A-Za-z-]+'
4548+
src[BUILDIDENTIFIER] = LETTERDASHNUMBER + '+'
45084549

45094550
// ## Build Metadata
45104551
// Plus sign, followed by one or more period-separated build metadata
@@ -4589,6 +4630,7 @@ src[LONETILDE] = '(?:~>?)'
45894630
var TILDETRIM = R++
45904631
src[TILDETRIM] = '(\\s*)' + src[LONETILDE] + '\\s+'
45914632
re[TILDETRIM] = new RegExp(src[TILDETRIM], 'g')
4633+
safeRe[TILDETRIM] = new RegExp(makeSafeRe(src[TILDETRIM]), 'g')
45924634
var tildeTrimReplace = '$1~'
45934635

45944636
var TILDE = R++
@@ -4604,6 +4646,7 @@ src[LONECARET] = '(?:\\^)'
46044646
var CARETTRIM = R++
46054647
src[CARETTRIM] = '(\\s*)' + src[LONECARET] + '\\s+'
46064648
re[CARETTRIM] = new RegExp(src[CARETTRIM], 'g')
4649+
safeRe[CARETTRIM] = new RegExp(makeSafeRe(src[CARETTRIM]), 'g')
46074650
var caretTrimReplace = '$1^'
46084651

46094652
var CARET = R++
@@ -4625,6 +4668,7 @@ src[COMPARATORTRIM] = '(\\s*)' + src[GTLT] +
46254668

46264669
// this one has to use the /g flag
46274670
re[COMPARATORTRIM] = new RegExp(src[COMPARATORTRIM], 'g')
4671+
safeRe[COMPARATORTRIM] = new RegExp(makeSafeRe(src[COMPARATORTRIM]), 'g')
46284672
var comparatorTrimReplace = '$1$2$3'
46294673

46304674
// Something like `1.2.3 - 1.2.4`
@@ -4653,6 +4697,14 @@ for (var i = 0; i < R; i++) {
46534697
debug(i, src[i])
46544698
if (!re[i]) {
46554699
re[i] = new RegExp(src[i])
4700+
4701+
// Replace all greedy whitespace to prevent regex dos issues. These regex are
4702+
// used internally via the safeRe object since all inputs in this library get
4703+
// normalized first to trim and collapse all extra whitespace. The original
4704+
// regexes are exported for userland consumption and lower level usage. A
4705+
// future breaking change could export the safer regex only with a note that
4706+
// all input should have extra whitespace removed.
4707+
safeRe[i] = new RegExp(makeSafeRe(src[i]))
46564708
}
46574709
}
46584710

@@ -4677,7 +4729,7 @@ function parse (version, options) {
46774729
return null
46784730
}
46794731

4680-
var r = options.loose ? re[LOOSE] : re[FULL]
4732+
var r = options.loose ? safeRe[LOOSE] : safeRe[FULL]
46814733
if (!r.test(version)) {
46824734
return null
46834735
}
@@ -4732,7 +4784,7 @@ function SemVer (version, options) {
47324784
this.options = options
47334785
this.loose = !!options.loose
47344786

4735-
var m = version.trim().match(options.loose ? re[LOOSE] : re[FULL])
4787+
var m = version.trim().match(options.loose ? safeRe[LOOSE] : safeRe[FULL])
47364788

47374789
if (!m) {
47384790
throw new TypeError('Invalid Version: ' + version)
@@ -5146,6 +5198,7 @@ function Comparator (comp, options) {
51465198
return new Comparator(comp, options)
51475199
}
51485200

5201+
comp = comp.trim().split(/\s+/).join(' ')
51495202
debug('comparator', comp, options)
51505203
this.options = options
51515204
this.loose = !!options.loose
@@ -5162,7 +5215,7 @@ function Comparator (comp, options) {
51625215

51635216
var ANY = {}
51645217
Comparator.prototype.parse = function (comp) {
5165-
var r = this.options.loose ? re[COMPARATORLOOSE] : re[COMPARATOR]
5218+
var r = this.options.loose ? safeRe[COMPARATORLOOSE] : safeRe[COMPARATOR]
51665219
var m = comp.match(r)
51675220

51685221
if (!m) {
@@ -5276,17 +5329,24 @@ function Range (range, options) {
52765329
this.loose = !!options.loose
52775330
this.includePrerelease = !!options.includePrerelease
52785331

5279-
// First, split based on boolean or ||
5332+
// First reduce all whitespace as much as possible so we do not have to rely
5333+
// on potentially slow regexes like \s*. This is then stored and used for
5334+
// future error messages as well.
52805335
this.raw = range
5281-
this.set = range.split(/\s*\|\|\s*/).map(function (range) {
5336+
.trim()
5337+
.split(/\s+/)
5338+
.join(' ')
5339+
5340+
// First, split based on boolean or ||
5341+
this.set = this.raw.split('||').map(function (range) {
52825342
return this.parseRange(range.trim())
52835343
}, this).filter(function (c) {
52845344
// throw out any that are not relevant for whatever reason
52855345
return c.length
52865346
})
52875347

52885348
if (!this.set.length) {
5289-
throw new TypeError('Invalid SemVer Range: ' + range)
5349+
throw new TypeError('Invalid SemVer Range: ' + this.raw)
52905350
}
52915351

52925352
this.format()
@@ -5305,28 +5365,23 @@ Range.prototype.toString = function () {
53055365

53065366
Range.prototype.parseRange = function (range) {
53075367
var loose = this.options.loose
5308-
range = range.trim()
53095368
// `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
5310-
var hr = loose ? re[HYPHENRANGELOOSE] : re[HYPHENRANGE]
5369+
var hr = loose ? safeRe[HYPHENRANGELOOSE] : safeRe[HYPHENRANGE]
53115370
range = range.replace(hr, hyphenReplace)
53125371
debug('hyphen replace', range)
53135372
// `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
5314-
range = range.replace(re[COMPARATORTRIM], comparatorTrimReplace)
5315-
debug('comparator trim', range, re[COMPARATORTRIM])
5373+
range = range.replace(safeRe[COMPARATORTRIM], comparatorTrimReplace)
5374+
debug('comparator trim', range, safeRe[COMPARATORTRIM])
53165375

53175376
// `~ 1.2.3` => `~1.2.3`
5318-
range = range.replace(re[TILDETRIM], tildeTrimReplace)
5377+
range = range.replace(safeRe[TILDETRIM], tildeTrimReplace)
53195378

53205379
// `^ 1.2.3` => `^1.2.3`
5321-
range = range.replace(re[CARETTRIM], caretTrimReplace)
5322-
5323-
// normalize spaces
5324-
range = range.split(/\s+/).join(' ')
5380+
range = range.replace(safeRe[CARETTRIM], caretTrimReplace)
53255381

53265382
// At this point, the range is completely trimmed and
53275383
// ready to be split into comparators.
5328-
5329-
var compRe = loose ? re[COMPARATORLOOSE] : re[COMPARATOR]
5384+
var compRe = loose ? safeRe[COMPARATORLOOSE] : safeRe[COMPARATOR]
53305385
var set = range.split(' ').map(function (comp) {
53315386
return parseComparator(comp, this.options)
53325387
}, this).join(' ').split(/\s+/)
@@ -5402,7 +5457,7 @@ function replaceTildes (comp, options) {
54025457
}
54035458

54045459
function replaceTilde (comp, options) {
5405-
var r = options.loose ? re[TILDELOOSE] : re[TILDE]
5460+
var r = options.loose ? safeRe[TILDELOOSE] : safeRe[TILDE]
54065461
return comp.replace(r, function (_, M, m, p, pr) {
54075462
debug('tilde', comp, _, M, m, p, pr)
54085463
var ret
@@ -5443,7 +5498,7 @@ function replaceCarets (comp, options) {
54435498

54445499
function replaceCaret (comp, options) {
54455500
debug('caret', comp, options)
5446-
var r = options.loose ? re[CARETLOOSE] : re[CARET]
5501+
var r = options.loose ? safeRe[CARETLOOSE] : safeRe[CARET]
54475502
return comp.replace(r, function (_, M, m, p, pr) {
54485503
debug('caret', comp, _, M, m, p, pr)
54495504
var ret
@@ -5502,7 +5557,7 @@ function replaceXRanges (comp, options) {
55025557

55035558
function replaceXRange (comp, options) {
55045559
comp = comp.trim()
5505-
var r = options.loose ? re[XRANGELOOSE] : re[XRANGE]
5560+
var r = options.loose ? safeRe[XRANGELOOSE] : safeRe[XRANGE]
55065561
return comp.replace(r, function (ret, gtlt, M, m, p, pr) {
55075562
debug('xRange', comp, ret, gtlt, M, m, p, pr)
55085563
var xM = isX(M)
@@ -5572,10 +5627,10 @@ function replaceXRange (comp, options) {
55725627
function replaceStars (comp, options) {
55735628
debug('replaceStars', comp, options)
55745629
// Looseness is ignored here. star is always as loose as it gets!
5575-
return comp.trim().replace(re[STAR], '')
5630+
return comp.trim().replace(safeRe[STAR], '')
55765631
}
55775632

5578-
// This function is passed to string.replace(re[HYPHENRANGE])
5633+
// This function is passed to string.replace(safeRe[HYPHENRANGE])
55795634
// M, m, patch, prerelease, build
55805635
// 1.2 - 3.4.5 => >=1.2.0 <=3.4.5
55815636
// 1.2.3 - 3.4 => >=1.2.0 <3.5.0 Any 3.4.x will do
@@ -5886,7 +5941,7 @@ function coerce (version) {
58865941
return null
58875942
}
58885943

5889-
var match = version.match(re[COERCE])
5944+
var match = version.match(safeRe[COERCE])
58905945

58915946
if (match == null) {
58925947
return null

index.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,20 @@ const serializers = {
9494
)}`;
9595
},
9696
IssuesEvent: (item) => {
97-
const emoji = item.payload.action === "opened" ? "❗" : "🔒";
97+
let emoji = "";
98+
99+
switch (item.payload.action) {
100+
case "opened":
101+
emoji = "❗";
102+
break;
103+
case "reopened":
104+
emoji = "🔓";
105+
break;
106+
case "closed":
107+
emoji = "🔒";
108+
break;
109+
}
110+
98111
return `${emoji} ${capitalize(item.payload.action)} issue ${toUrlFormat(
99112
item
100113
)} in ${toUrlFormat(item.repo.name)}`;

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "github-activity-readme",
3-
"version": "0.4.1",
3+
"version": "0.4.2",
44
"description": "Updates README with the recent GitHub activity of a user",
55
"main": "index.js",
66
"keywords": [],

0 commit comments

Comments
 (0)