forked from w3f/parse-milestone-delivery-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
71 lines (62 loc) · 2.1 KB
/
index.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
'use strict'
const core = require('@actions/core')
const { promises: fs } = require('fs')
const main = async () => {
const path = core.getInput('path')
const strict = core.getInput('strict')
const content = await fs.readFile(path, 'utf8')
const regexList = [
{
name: 'application_document',
regex: /(?<=\*\*Application Document:\*\* ).*/g,
url_regex: /(https?:\/\/(www\.)?github\.com\/w3f\/(Open-)?Grants-Program\/(blob|tree)\/master\/applications\/(maintenance\/)?)([-a-zA-Z0-9():_.~! ]|%[0-9a-fA-F]{2})+.md/g,
filename_regex: /(?<=\/)([-a-zA-Z0-9():_.~! ]|%[0-9a-fA-F]{2})+.md/g
},
{
name: 'milestone_number',
regex: /(?<=\*\*(Milestone|Delivery) Number:\*\* ).*/g
},
]
let errors = []
let isMaintenance = false
regexList.map(function (reg) {
try {
switch (reg.name) {
case 'application_document':
let application_document = content.match(reg.regex)[0]
application_document = application_document.match(reg.url_regex)[0]
isMaintenance = application_document.includes('maintenance')
application_document = application_document.match(reg.filename_regex)[0]
if (application_document) {
core.setOutput(reg.name, application_document)
core.setOutput('is_maintenance', isMaintenance)
} else {
errors.push(reg.name)
}
break
case 'milestone_number':
const milestone_number = content.match(reg.regex)[0]
if (isNaN(milestone_number)) {
errors.push(reg.name)
} else {
core.setOutput(reg.name, milestone_number)
}
break
default:
const result = content.match(reg.regex)[0]
core.setOutput(reg.name, result)
}
} catch {
errors.push(reg.name)
}
})
if (errors.length > 0) {
const error_string = `Match not found for: ${errors.join(', ')}`
if (strict !== 'true') {
core.warning(error_string)
} else {
core.setFailed(error_string)
}
}
}
main().catch(err => core.setFailed(err.message))