1
1
const nlp = require ( 'compromise' )
2
2
3
+ // Types that are valid (multi words must all be lower case)
3
4
const validContributionTypes = [
4
5
'blog' ,
5
6
'bug' ,
6
7
'code' ,
7
8
'design' ,
8
9
'doc' ,
9
- 'eventOrganizing ' ,
10
+ 'eventorganizing ' ,
10
11
'example' ,
11
12
'financial' ,
12
- 'fundingFinding ' ,
13
+ 'fundingfinding ' ,
13
14
'ideas' ,
14
15
'infra' ,
15
16
'maintenance' ,
@@ -23,17 +24,59 @@ const validContributionTypes = [
23
24
'tool' ,
24
25
'translation' ,
25
26
'tutorial' ,
26
- 'userTesting ' ,
27
+ 'usertesting ' ,
27
28
'video' ,
28
29
]
29
30
31
+ // Types that are valid multi words, that we need to re map back to there camelCase parts
32
+ const validMultiContributionTypesMapping = {
33
+ eventorganizing : 'eventOrganizing' ,
34
+ fundingfinding : 'fundingFinding' ,
35
+ usertesting : 'userTesting' ,
36
+ }
37
+
38
+ // Additional terms to match to types (plurals, aliases etc)
30
39
const contributionTypeMappings = {
31
- 'event organizing' : 'eventOrganizing' ,
32
- 'funding finding' : 'fundingFinding' ,
33
- 'user testing' : 'userTesting' ,
40
+ blogs : 'blog' ,
41
+ blogging : 'blog' ,
42
+ bugs : 'bug' ,
43
+ codes : 'code' ,
44
+ coding : 'code' ,
45
+ designing : 'design' ,
46
+ desigs : 'design' ,
47
+ doc : 'doc' ,
48
+ docs : 'doc' ,
49
+ documenting : 'doc' ,
34
50
documentation : 'doc' ,
51
+ examples : 'example' ,
52
+ finance : 'financial' ,
53
+ financials : 'financial' ,
54
+ funds : 'fundingfinding' ,
55
+ idea : 'ideas' ,
56
+ infras : 'infra' ,
35
57
infrastructure : 'infra' ,
36
58
maintaining : 'maintenance' ,
59
+ platforms : 'platform' ,
60
+ plugins : 'plugin' ,
61
+ questions : 'question' ,
62
+ reviews : 'review' ,
63
+ securing : 'security' ,
64
+ talks : 'talk' ,
65
+ tests : 'test' ,
66
+ testing : 'test' ,
67
+ tools : 'tool' ,
68
+ tooling : 'tool' ,
69
+ translations : 'translation' ,
70
+ tutorials : 'tutorial' ,
71
+ videoes : 'video' ,
72
+ }
73
+
74
+ // Additional terms to match to types (plurals, aliases etc) that are multi word
75
+ const contributionTypeMultiWordMapping = {
76
+ 'event organizing' : 'eventOrganizing' ,
77
+ 'fund finding' : 'fundingFinding' ,
78
+ 'funding finding' : 'fundingFinding' ,
79
+ 'user testing' : 'userTesting' ,
37
80
}
38
81
39
82
const Contributions = { }
@@ -51,15 +94,12 @@ const plugin = {
51
94
...Contributions ,
52
95
add : 'Action' ,
53
96
} ,
54
- patterns : {
55
- // 'add #person for #Contribution': 'AddContributor',
56
- // "i can't (log|sign|get) in to my? #Software": 'LoginIssue'
57
- } ,
58
97
}
98
+
59
99
nlp . plugin ( plugin )
60
100
61
- function parseAddComment ( doc , action ) {
62
- const whoMatched = doc
101
+ function parseAddComment ( message , action ) {
102
+ const whoMatched = nlp ( message )
63
103
. match ( `${ action } [.]` )
64
104
. normalize ( {
65
105
whitespace : true , // remove hyphens, newlines, and force one space between words
@@ -79,20 +119,32 @@ function parseAddComment(doc, action) {
79
119
80
120
const who = whoMatched . startsWith ( '@' ) ? whoMatched . substr ( 1 ) : whoMatched
81
121
82
- // TODO: handle plurals (e.g. some said docs)
83
- let contributions = doc
122
+ // Contributions
123
+ const doc = nlp ( message ) . toLowerCase ( )
124
+ // This is to support multi word 'matches' (altho the compromise docs say it supports this *confused*)
125
+ Object . entries ( contributionTypeMultiWordMapping ) . forEach (
126
+ ( [ multiWordType , singleWordType ] ) => {
127
+ doc . replace ( multiWordType , singleWordType )
128
+ } ,
129
+ )
130
+ const contributions = doc
84
131
. match ( '#Contribution' )
85
132
. data ( )
86
133
. map ( data => {
87
134
// This removes whitespace, commas etc
88
135
return data . normal
89
136
} )
90
-
91
- contributions = contributions . map ( type => {
92
- if ( contributionTypeMappings [ type ] )
93
- return contributionTypeMappings [ type ]
94
- return type
95
- } )
137
+ . map ( type => {
138
+ if ( contributionTypeMappings [ type ] )
139
+ return contributionTypeMappings [ type ]
140
+ return type
141
+ } )
142
+ . map ( type => {
143
+ // Convert usertesting to userTesting for the node api
144
+ if ( validMultiContributionTypesMapping [ type ] )
145
+ return validMultiContributionTypesMapping [ type ]
146
+ return type
147
+ } )
96
148
97
149
return {
98
150
action : 'add' ,
@@ -105,12 +157,13 @@ function parseComment(message) {
105
157
const doc = nlp ( message )
106
158
107
159
const action = doc
160
+ . toLowerCase ( )
108
161
. match ( '#Action' )
109
162
. normalize ( )
110
163
. out ( 'string' )
111
164
112
165
if ( action === 'add' ) {
113
- return parseAddComment ( doc , action )
166
+ return parseAddComment ( message , action )
114
167
}
115
168
116
169
return {
0 commit comments