diff --git a/src/action.js b/src/action.js index e8beceb..68fa2e4 100644 --- a/src/action.js +++ b/src/action.js @@ -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')) diff --git a/src/index.js b/src/index.js index d47858b..7c9d348 100644 --- a/src/index.js +++ b/src/index.js @@ -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') @@ -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 } + }) +}