-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
75 lines (65 loc) · 1.84 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
72
73
74
75
const core = require('@actions/core')
const github = require('@actions/github')
const depcheck = require('depcheck')
const bullets = line => `* ${line}`
const options = {
ignoreBinPackage: false, // ignore the packages with bin entry
skipMissing: false, // skip calculation of missing dependencies
ignorePatterns: [
// files matching these patterns will be ignored
'sandbox',
'dist',
'bower_components',
],
ignoreMatches: [
// ignore dependencies that matches these globs
'grunt-*',
],
parsers: {
// the target parsers
'**/*.js': depcheck.parser.es6,
'**/*.jsx': depcheck.parser.jsx,
},
detectors: [
// the target detectors
depcheck.detector.requireCallExpression,
depcheck.detector.importDeclaration,
],
specials: [
// the target special parsers
depcheck.special.eslint,
depcheck.special.webpack,
],
package: {
// may specify dependencies instead of parsing package.json
dependencies: {
lodash: '^4.17.15',
},
devDependencies: {
eslint: '^6.6.0',
},
peerDependencies: {},
optionalDependencies: {},
},
}
async function main() {
const {dependencies, devDependencies} = await depcheck('.', options)
const token = core.getInput('GITHUB_TOKEN')
const {context} = github
if (!context.payload.pull_request) {
core.setFailed('No pull request found')
return
}
const prNum = context.payload.pull_request.number
const depsMissing = dependencies.map(bullets).join('\n')
const devDepsMissing = devDependencies.map(bullets).join('\n')
const body = `Dependencies: \n${depsMissing}\n\nDev Deps: \n${devDepsMissing}`
//const kit = new github.GitHub(token)
const kit = github.getOctokit(token)
await kit.issues.createComment({
...context.repo,
issue_number: prNum,
body,
})
}
main().catch(err => core.setFailed(err.message))