Skip to content

Commit 51b8e77

Browse files
committed
Hack to support local results.
Signed-off-by: Jeff Mendoza <[email protected]>
1 parent a3a9c4c commit 51b8e77

File tree

2 files changed

+83
-41
lines changed

2 files changed

+83
-41
lines changed

src/action.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@ async function run () {
1414
// Context
1515
const context = github.context
1616
// Inputs
17-
const scopePath = core.getInput('scope', { required: true })
18-
const databasePath = core.getInput('database', { required: true })
19-
const reportPath = core.getInput('report', { required: true })
17+
const scopePath = 'scope.json'
18+
const databasePath = 'databasefile.json'
19+
const reportPath = 'reportfile.md'
20+
// const scopePath = core.getInput('scope', { required: true })
21+
// const databasePath = core.getInput('database', { required: true })
22+
// const reportPath = core.getInput('report', { required: true })
2023
// Options
2124
const maxRequestInParallel = parseInt(core.getInput('max-request-in-parallel') || 10)
2225
const generateIssue = normalizeBoolean(core.getInput('generate-issue'))

src/index.js

+77-38
Original file line numberDiff line numberDiff line change
@@ -101,60 +101,84 @@ const generateScope = async ({ octokit, orgs, scope, maxRequestInParallel }) =>
101101
const generateScores = async ({ scope, database: currentDatabase, maxRequestInParallel, reportTagsEnabled, renderBadge, reportTool }) => {
102102
// @TODO: Improve deep clone logic
103103
const database = JSON.parse(JSON.stringify(currentDatabase))
104-
const platform = 'github.com'
104+
// const platform = 'github.com'
105105

106-
// @TODO: End the action if there are no projects in scope?
106+
// // @TODO: End the action if there are no projects in scope?
107107

108-
const orgs = Object.keys(scope[platform])
109-
core.debug(`Total Orgs/Users in scope: ${orgs.length}`)
108+
// const orgs = Object.keys(scope[platform])
109+
// core.debug(`Total Orgs/Users in scope: ${orgs.length}`)
110110

111-
// Structure Projects
112-
const projects = []
111+
// // Structure Projects
112+
// const projects = []
113113

114-
orgs.forEach((org) => {
115-
const repos = scope[platform][org].included
116-
repos.forEach((repo) => projects.push({ org, repo }))
117-
})
114+
// orgs.forEach((org) => {
115+
// const repos = scope[platform][org].included
116+
// repos.forEach((repo) => projects.push({ org, repo }))
117+
// })
118118

119-
core.debug(`Total Projects in scope: ${projects.length}`)
119+
// core.debug(`Total Projects in scope: ${projects.length}`)
120120

121-
const chunks = chunkArray(projects, maxRequestInParallel)
122-
core.debug(`Total chunks: ${chunks.length}`)
121+
// const chunks = chunkArray(projects, maxRequestInParallel)
122+
// core.debug(`Total chunks: ${chunks.length}`)
123123

124-
const scores = []
124+
// const scores = []
125125

126-
for (let index = 0; index < chunks.length; index++) {
127-
const chunk = chunks[index]
128-
core.debug(`Processing chunk ${index + 1}/${chunks.length}`)
126+
// for (let index = 0; index < chunks.length; index++) {
127+
// const chunk = chunks[index]
128+
// core.debug(`Processing chunk ${index + 1}/${chunks.length}`)
129129

130-
const chunkScores = await Promise.all(chunk.map(async ({ org, repo }) => {
131-
const { score, date, commit } = await getProjectScore({ platform, org, repo })
132-
core.debug(`Got project score for ${platform}/${org}/${repo}: ${score} (${date})`)
130+
// const chunkScores = await Promise.all(chunk.map(async ({ org, repo }) => {
131+
// const { score, date, commit } = await getProjectScore({ platform, org, repo })
132+
// core.debug(`Got project score for ${platform}/${org}/${repo}: ${score} (${date})`)
133133

134-
const storedScore = getScore({ database, platform, org, repo })
134+
// const storedScore = getScore({ database, platform, org, repo })
135135

136-
const scoreData = { platform, org, repo, score, date, commit }
137-
// If no stored score then record if score is different then:
138-
if (!storedScore || storedScore.score !== score) {
139-
saveScore({ database, platform, org, repo, score, date, commit })
140-
}
136+
// const scoreData = { platform, org, repo, score, date, commit }
137+
// // If no stored score then record if score is different then:
138+
// if (!storedScore || storedScore.score !== score) {
139+
// saveScore({ database, platform, org, repo, score, date, commit })
140+
// }
141+
142+
// // Add previous score and date if available to the report
143+
// if (storedScore) {
144+
// scoreData.prevScore = storedScore.score
145+
// scoreData.prevDate = storedScore.date
146+
// scoreData.prevCommit = storedScore.commit
147+
148+
// if (storedScore.score !== score) {
149+
// scoreData.currentDiff = parseFloat((score - storedScore.score).toFixed(1))
150+
// }
151+
// }
152+
153+
// return scoreData
154+
// }))
155+
156+
// scores.push(...chunkScores)
157+
// }
158+
159+
let localScores = await getLocalScores(scoredata)
141160

142-
// Add previous score and date if available to the report
143-
if (storedScore) {
144-
scoreData.prevScore = storedScore.score
145-
scoreData.prevDate = storedScore.date
146-
scoreData.prevCommit = storedScore.commit
161+
const scores = localScores.map(({ score, date, commit, platform, org, repo }) => {
162+
const storedScore = getScore({ database, platform, org, repo })
163+
const scoreData = { platform, org, repo, score, date, commit }
147164

148-
if (storedScore.score !== score) {
149-
scoreData.currentDiff = parseFloat((score - storedScore.score).toFixed(1))
165+
if (!storedScore || storedScore.score !== score) {
166+
saveScore({ database, platform, org, repo, score, date, commit })
150167
}
151-
}
152168

153-
return scoreData
154-
}))
169+
// Add previous score and date if available to the report
170+
if (storedScore) {
171+
scoreData.prevScore = storedScore.score
172+
scoreData.prevDate = storedScore.date
173+
scoreData.prevCommit = storedScore.commit
155174

156-
scores.push(...chunkScores)
157-
}
175+
if (storedScore.score !== score) {
176+
scoreData.currentDiff = parseFloat((score - storedScore.score).toFixed(1))
177+
}
178+
}
179+
180+
return scoreData
181+
})
158182

159183
core.debug('All the scores are already collected')
160184

@@ -171,3 +195,18 @@ module.exports = {
171195
generateScope,
172196
generateScores
173197
}
198+
199+
let scoredata = require('../results.json')
200+
201+
const getLocalScores = async ( scores ) => {
202+
return scores.map((x) => {
203+
const parts = x.repo.name.split('/');
204+
score = x.score
205+
date = x.date
206+
commit = x.repo.commit
207+
platform = parts[0]
208+
org = parts[1]
209+
repo = parts[2]
210+
return { score, date, commit, platform, org, repo }
211+
})
212+
}

0 commit comments

Comments
 (0)