This repository was archived by the owner on Jan 23, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmetadataExtractor.js
210 lines (192 loc) · 6.17 KB
/
metadataExtractor.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
/**
* Metadata extractor
*/
const _ = require('lodash')
/**
* Get metadata entry by key
* @param {Array} metadata the metadata array
* @param {String} key the metadata key
*/
const getMeta = (metadata = [], key) => _.find(metadata, meta => meta.name === key)
/**
* Extract billing project
* @param {Object} challenge the challenge object
* @param {Any} defaultValue the default value
*/
function extractBillingProject (challenge, defaultValue) {
return _.get(challenge, 'billingAccountId', _.get(challenge, 'billing.billingAccountId', _.toString(defaultValue)))
}
/**
* Extract markup
* @param {Object} challenge the challenge object
* @param {Any} defaultValue the default value
*/
function extractMarkup (challenge, defaultValue) {
return _.toString(_.get(challenge, 'billing.markup', defaultValue))
}
/**
* Extract submission limit
* @param {Object} challenge the challenge object
* @param {Any} defaultValue the default value
*/
function extractSubmissionLimit (challenge, defaultValue) {
const entry = getMeta(challenge.metadata, 'submissionLimit')
if (!entry) return _.toString(defaultValue)
try {
const parsedEntryValue = JSON.parse(entry.value)
if (parsedEntryValue.limit) {
entry.value = parsedEntryValue.count
} else {
entry.value = null
}
} catch (e) {
entry.value = null
}
return _.toString(entry.value || defaultValue)
}
/**
* Extract spec review cost
* @param {Object} challenge the challenge object
* @param {Any} defaultValue the default value
*/
function extractSpecReviewCost (challenge, defaultValue) {
return _.get(_.find(_.get(challenge, 'prizeSets', []), p => p.type === 'specReviewer') || {}, 'prizes[0].value', _.toString(defaultValue))
}
/**
* Extract DR points
* @param {Object} challenge the challenge object
* @param {Any} defaultValue the default value
*/
function extractDrPoints (challenge, defaultValue) {
const entry = getMeta(challenge.metadata, 'drPoints')
if (!entry) return _.toString(defaultValue)
return _.toString(entry.value || defaultValue)
}
/**
* Extract Approval required
* @param {Object} challenge the challenge object
* @param {Any} defaultValue the default value
*/
function extractApprovalRequired (challenge, defaultValue) {
const entry = getMeta(challenge.metadata, 'approvalRequired')
if (!entry) return _.toString(defaultValue)
return _.toString(entry.value)
}
/**
* Extract Post-mortem required
* @param {Object} challenge the challenge object
* @param {Any} defaultValue the default value
*/
function extractPostMortemRequired (challenge, defaultValue) {
const entry = getMeta(challenge.metadata, 'postMortemRequired')
if (!entry) return _.toString(defaultValue)
return _.toString(entry.value)
}
/**
* Extract track late deliverables required
* @param {Object} challenge the challenge object
* @param {Any} defaultValue the default value
*/
function extractTrackLateDeliverablesRequired (challenge, defaultValue) {
const entry = getMeta(challenge.metadata, 'trackLateDeliverables')
if (!entry) return _.toString(defaultValue)
return _.toString(entry.value)
}
/**
* Extract allow stock art required
* @param {Object} challenge the challenge object
* @param {Any} defaultValue the default value
*/
function extractAllowStockArtRequired (challenge, defaultValue) {
const entry = getMeta(challenge.metadata, 'allowStockArt')
if (!entry) return _.toString(defaultValue)
return _.toString(entry.value)
}
/**
* Extract submission viewable
* @param {Object} challenge the challenge object
* @param {Any} defaultValue the default value
*/
function extractSubmissionViewable (challenge, defaultValue) {
const entry = getMeta(challenge.metadata, 'submissionViewable')
if (!entry) return _.toString(defaultValue)
return _.toString(entry.value)
}
/**
* Extract review feedback
* @param {Object} challenge the challenge object
* @param {Any} defaultValue the default value
*/
function extractReviewFeedback (challenge, defaultValue) {
const entry = getMeta(challenge.metadata, 'reviewFeedback')
if (!entry) return _.toString(defaultValue)
return _.toString(entry.value)
}
/**
* Extract environment
* @param {Object} challenge the challenge object
* @param {Any} defaultValue the default value
*/
function extractEnvironment (challenge, defaultValue) {
const entry = getMeta(challenge.metadata, 'environment')
if (!entry) return _.toString(defaultValue)
return _.toString(entry.value)
}
/**
* Extract code repo
* @param {Object} challenge the challenge object
* @param {Any} defaultValue the default value
*/
function extractCodeRepo (challenge, defaultValue) {
const entry = getMeta(challenge.metadata, 'codeRepo')
if (!entry) return _.toString(defaultValue)
return _.toString(entry.value)
}
/**
* Extract estimate effort hours
* @param {Object} challenge the challenge object
* @param {Any} defaultValue the default value
*/
function extractEstimateEffortHours (challenge, defaultValue) {
const entry = getMeta(challenge.metadata, 'effortHoursEstimate')
if (!entry) return _.toString(defaultValue)
return _.toNumber(entry.value)
}
/**
* Extract estimate effort days offshore
* @param {Object} challenge the challenge object
* @param {Any} defaultValue the default value
*/
function extractEstimateEffortOffshore (challenge, defaultValue) {
const entry = getMeta(challenge.metadata, 'offshoreEfforts')
if (!entry) return _.toString(defaultValue)
return _.toNumber(entry.value)
}
/**
* Extract estimate effort days Onsite
* @param {Object} challenge the challenge object
* @param {Any} defaultValue the default value
*/
function extractEstimateEffortOnsite (challenge, defaultValue) {
const entry = getMeta(challenge.metadata, 'onsiteEfforts')
if (!entry) return _.toString(defaultValue)
return _.toNumber(entry.value)
}
module.exports = {
extractMarkup,
extractBillingProject,
extractSubmissionLimit,
extractSpecReviewCost,
extractDrPoints,
extractApprovalRequired,
extractPostMortemRequired,
extractTrackLateDeliverablesRequired,
extractAllowStockArtRequired,
extractSubmissionViewable,
extractReviewFeedback,
extractEnvironment,
extractCodeRepo,
extractEstimateEffortHours,
extractEstimateEffortOffshore,
extractEstimateEffortOnsite
}