-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·107 lines (97 loc) · 3.14 KB
/
Copy pathindex.js
File metadata and controls
executable file
·107 lines (97 loc) · 3.14 KB
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
import getLocalFileDetails from './getLocalFileDetails'
import BundleWatchService from './reporting/BundleWatchService'
import GitHubService from './reporting/GitHubService'
import analyze from './analyze'
import { STATUSES } from './analyze/analyzeFiles'
import getConfig from './config/getConfig'
import createURLToResultPage from './resultsPage/createURL'
const main = async ({
files,
bundlewatchServiceHost,
ci,
defaultCompression,
normalizeFilenames,
}) => {
const currentBranchFileDetails = getLocalFileDetails({
files,
defaultCompression: defaultCompression,
normalizeFilenames,
})
const bundlewatchService = new BundleWatchService({
repoOwner: ci.repoOwner,
repoName: ci.repoName,
repoCurrentBranch: ci.repoCurrentBranch,
repoBranchBase: ci.repoBranchBase,
commitSha: ci.commitSha,
bundlewatchServiceHost,
githubAccessToken: ci.githubAccessToken,
})
const baseBranchFileDetails =
await bundlewatchService.getFileDetailsForBaseBranch()
await bundlewatchService.saveFileDetailsForCurrentBranch({
fileDetailsByPath: currentBranchFileDetails,
trackBranches: ci.trackBranches,
})
const results = analyze({
currentBranchFileDetails,
baseBranchFileDetails,
baseBranchName: ci.repoBranchBase,
})
const url = await createURLToResultPage({
results,
bundlewatchServiceHost,
repoOwner: ci.repoOwner,
repoName: ci.repoName,
repoCurrentBranch: ci.repoCurrentBranch,
repoBranchBase: ci.repoBranchBase,
commitSha: ci.commitSha,
})
return {
...results,
url,
}
}
const bundlewatchApi = async (customConfig) => {
const config = getConfig(customConfig)
const githubService = new GitHubService({
repoOwner: config.ci.repoOwner,
repoName: config.ci.repoName,
commitSha: config.ci.commitSha,
githubAccessToken: config.ci.githubAccessToken,
})
await githubService.start({ message: 'Checking bundlewatch...' })
try {
const results = await main(config)
if (results.status === STATUSES.FAIL) {
await githubService.fail({
message: results.summary,
url: results.url,
})
await Promise.all(
results.fullResults.map((result) => {
if (result.status === STATUSES.FAIL) {
return githubService.fail({
message: result.message,
filePath: result.filePath,
})
}
return Promise.resolve()
}),
)
} else {
// TODO: add warn
await githubService.pass({
message: results.summary,
url: results.url,
})
}
return results
} catch (e) {
await githubService.error({
message: `Unable to analyze, check logs. ${e ? e.message : ''}`,
})
throw e
}
}
export default bundlewatchApi
export { STATUSES }