Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hack to support local results #90

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ async function run () {
// Context
const context = github.context
// Inputs
const scopePath = core.getInput('scope', { required: true })
const databasePath = core.getInput('database', { required: true })
const reportPath = core.getInput('report', { required: true })
const scopePath = 'scope.json'
const databasePath = 'databasefile.json'
const reportPath = 'reportfile.md'
// const scopePath = core.getInput('scope', { required: true })
// const databasePath = core.getInput('database', { required: true })
// const reportPath = core.getInput('report', { required: true })
// Options
const maxRequestInParallel = parseInt(core.getInput('max-request-in-parallel') || 10)
const generateIssue = normalizeBoolean(core.getInput('generate-issue'))
Expand Down
115 changes: 77 additions & 38 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,60 +101,84 @@ const generateScope = async ({ octokit, orgs, scope, maxRequestInParallel }) =>
const generateScores = async ({ scope, database: currentDatabase, maxRequestInParallel, reportTagsEnabled, renderBadge, reportTool }) => {
// @TODO: Improve deep clone logic
const database = JSON.parse(JSON.stringify(currentDatabase))
const platform = 'github.com'
// const platform = 'github.com'

// @TODO: End the action if there are no projects in scope?
// // @TODO: End the action if there are no projects in scope?

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

// Structure Projects
const projects = []
// // Structure Projects
// const projects = []

orgs.forEach((org) => {
const repos = scope[platform][org].included
repos.forEach((repo) => projects.push({ org, repo }))
})
// orgs.forEach((org) => {
// const repos = scope[platform][org].included
// repos.forEach((repo) => projects.push({ org, repo }))
// })

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

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

const scores = []
// const scores = []

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

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

const storedScore = getScore({ database, platform, org, repo })
// const storedScore = getScore({ database, platform, org, repo })

const scoreData = { platform, org, repo, score, date, commit }
// If no stored score then record if score is different then:
if (!storedScore || storedScore.score !== score) {
saveScore({ database, platform, org, repo, score, date, commit })
}
// const scoreData = { platform, org, repo, score, date, commit }
// // If no stored score then record if score is different then:
// if (!storedScore || storedScore.score !== score) {
// saveScore({ database, platform, org, repo, score, date, commit })
// }

// // Add previous score and date if available to the report
// if (storedScore) {
// scoreData.prevScore = storedScore.score
// scoreData.prevDate = storedScore.date
// scoreData.prevCommit = storedScore.commit

// if (storedScore.score !== score) {
// scoreData.currentDiff = parseFloat((score - storedScore.score).toFixed(1))
// }
// }

// return scoreData
// }))

// scores.push(...chunkScores)
// }

let localScores = await getLocalScores(scoredata)

// Add previous score and date if available to the report
if (storedScore) {
scoreData.prevScore = storedScore.score
scoreData.prevDate = storedScore.date
scoreData.prevCommit = storedScore.commit
const scores = localScores.map(({ score, date, commit, platform, org, repo }) => {
const storedScore = getScore({ database, platform, org, repo })
const scoreData = { platform, org, repo, score, date, commit }

if (storedScore.score !== score) {
scoreData.currentDiff = parseFloat((score - storedScore.score).toFixed(1))
if (!storedScore || storedScore.score !== score) {
saveScore({ database, platform, org, repo, score, date, commit })
}
}

return scoreData
}))
// Add previous score and date if available to the report
if (storedScore) {
scoreData.prevScore = storedScore.score
scoreData.prevDate = storedScore.date
scoreData.prevCommit = storedScore.commit

scores.push(...chunkScores)
}
if (storedScore.score !== score) {
scoreData.currentDiff = parseFloat((score - storedScore.score).toFixed(1))
}
}

return scoreData
})

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

Expand All @@ -171,3 +195,18 @@ module.exports = {
generateScope,
generateScores
}

let scoredata = require('../results.json')

const getLocalScores = async ( scores ) => {
return scores.map((x) => {
const parts = x.repo.name.split('/');
score = x.score
date = x.date
commit = x.repo.commit
platform = parts[0]
org = parts[1]
repo = parts[2]
return { score, date, commit, platform, org, repo }
})
}
Loading