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

Feat: create directories #53

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -236,4 +236,5 @@ $RECYCLE.BIN/

# End of https://www.toptal.com/developers/gitignore/api/node,windows,macos,linux,visualstudiocode

.vscode/
.vscode/
reporting
19 changes: 16 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27793,7 +27793,7 @@ module.exports = {
const got = __nccwpck_require__(3061)
const core = __nccwpck_require__(2186)
const ejs = __nccwpck_require__(8431)
const { readFile } = (__nccwpck_require__(7147).promises)
const { readFile, existsSync, mkdirSync } = (__nccwpck_require__(7147).promises)
const { join } = __nccwpck_require__(1017)
const { softAssign } = __nccwpck_require__(7348)
const databaseSchema = __nccwpck_require__(5324)
Expand Down Expand Up @@ -27850,14 +27850,24 @@ const generateIssueContent = async (scores, renderBadge) => {
return ejs.render(template, { scores: scoresInScope, renderBadge })
}

const makeDirectory = ({ path }) => {
const directories = path.split('/').slice(0, -1).join('/')
core.debug(`Making directory ${directories}`)
if (!existsSync(directories)) {
core.debug('Making directory: ', path)
mkdirSync(directories, { recursive: true })
}
}

module.exports = {
validateDatabaseIntegrity: validateAgainstSchema(databaseSchema, 'database'),
validateScopeIntegrity: validateAgainstSchema(scopeSchema, 'scope'),
getProjectScore,
saveScore,
getScore,
generateReportContent,
generateIssueContent
generateIssueContent,
makeDirectory
}


Expand Down Expand Up @@ -28137,7 +28147,7 @@ const { readFile, writeFile, stat } = (__nccwpck_require__(7147).promises)
const { isDifferent } = __nccwpck_require__(9497)
const { updateOrCreateSegment } = __nccwpck_require__(7794)
const { generateScores, generateScope } = __nccwpck_require__(4351)
const { validateDatabaseIntegrity, validateScopeIntegrity } = __nccwpck_require__(1608)
const { validateDatabaseIntegrity, validateScopeIntegrity, makeDirectory } = __nccwpck_require__(1608)

async function run () {
let octokit
Expand Down Expand Up @@ -28234,6 +28244,8 @@ async function run () {

// Save changes
core.info('Saving changes to database and report')
console.log('Saving changes to database and report')
makeDirectory(reportPath)
await writeFile(databasePath, JSON.stringify(newDatabaseState, null, 2))
await writeFile(reportPath, reportTagsEnabled
? updateOrCreateSegment({
Expand All @@ -28246,6 +28258,7 @@ async function run () {

if (discoveryEnabled) {
core.info('Saving changes to scope...')
makeDirectory(scopePath)
await writeFile(scopePath, JSON.stringify(scope, null, 2))
}

Expand Down
5 changes: 4 additions & 1 deletion src/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { readFile, writeFile, stat } = require('fs').promises
const { isDifferent } = require('@ulisesgascon/is-different')
const { updateOrCreateSegment } = require('@ulisesgascon/text-tags-manager')
const { generateScores, generateScope } = require('./')
const { validateDatabaseIntegrity, validateScopeIntegrity } = require('./utils')
const { validateDatabaseIntegrity, validateScopeIntegrity, makeDirectory } = require('./utils')

async function run () {
let octokit
Expand Down Expand Up @@ -104,6 +104,8 @@ async function run () {

// Save changes
core.info('Saving changes to database and report')
console.log('Saving changes to database and report')
makeDirectory(reportPath)
await writeFile(databasePath, JSON.stringify(newDatabaseState, null, 2))
await writeFile(reportPath, reportTagsEnabled
? updateOrCreateSegment({
Expand All @@ -116,6 +118,7 @@ async function run () {

if (discoveryEnabled) {
core.info('Saving changes to scope...')
makeDirectory(scopePath)
await writeFile(scopePath, JSON.stringify(scope, null, 2))
}

Expand Down
14 changes: 12 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const got = require('got')
const core = require('@actions/core')
const ejs = require('ejs')
const { readFile } = require('fs').promises
const { readFile, existsSync, mkdirSync } = require('fs').promises
const { join } = require('path')
const { softAssign } = require('@ulisesgascon/soft-assign-deep-property')
const databaseSchema = require('../schemas/database.json')
Expand Down Expand Up @@ -58,12 +58,22 @@ const generateIssueContent = async (scores, renderBadge) => {
return ejs.render(template, { scores: scoresInScope, renderBadge })
}

const makeDirectory = ( path ) => {
const directories = path.split('/').slice(0, -1).join('/')
core.debug(`Making directory ${directories}`)
if (!existsSync(directories)) {
core.debug('Making directory: ', path)
mkdirSync(directories, { recursive: true })
}
}

module.exports = {
validateDatabaseIntegrity: validateAgainstSchema(databaseSchema, 'database'),
validateScopeIntegrity: validateAgainstSchema(scopeSchema, 'scope'),
getProjectScore,
saveScore,
getScore,
generateReportContent,
generateIssueContent
generateIssueContent,
makeDirectory
}