Skip to content

Commit

Permalink
[minor] Standard formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Makeshift committed Nov 21, 2022
1 parent 25474ba commit 7afef72
Show file tree
Hide file tree
Showing 3 changed files with 1,417 additions and 16 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"js-yaml": "^4.1.0"
},
"devDependencies": {
"@vercel/ncc": "^0.34.0"
"@vercel/ncc": "^0.34.0",
"standard": "^17.0.0"
}
}
32 changes: 17 additions & 15 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const core = require('@actions/core');
const yaml = require('js-yaml');
const fs = require('fs').promises;
const util = require('util');
const core = require('@actions/core')
const yaml = require('js-yaml')
const fs = require('fs').promises
const util = require('util')
const glob = util.promisify(require('glob'))
const path = require('path')
const github = require('@actions/github')

const actionName = 'Makeshift/generate-dependabot-glob-action'

const globOpts = {
root: process.cwd(),
Expand All @@ -16,22 +17,22 @@ const globOpts = {

const clone = obj => JSON.parse(JSON.stringify(obj))

async function run() {
const templateFile = core.getInput('template-file') || '.github/dependabot.template.yml';
const template = yaml.load(await fs.readFile(templateFile, 'utf8'));
async function run () {
const templateFile = core.getInput('template-file') || '.github/dependabot.template.yml'
const template = yaml.load(await fs.readFile(templateFile, 'utf8'))

const newUpdates = []

for (let entry of template.updates) {
core.info(`Processing entry ${entry.directory} for ecosystem ${entry["package-ecosystem"]}`)
for (const entry of template.updates) {
core.info(`Processing entry ${entry.directory} for ecosystem ${entry['package-ecosystem']}`)
const baseUpdate = clone(entry)
const matchingFiles = await glob(entry.directory, globOpts)
core.info(`Found ${matchingFiles.length} files matching ${entry.directory}`)
const matchingDirs = new Set(matchingFiles.map(file => path.dirname(file)))
core.info(`Found ${matchingDirs.length} directories matching ${entry.directory}`)

for (let dir of matchingDirs) {
core.info(`Creating entry for ${dir} with ecosystem ${entry["package-ecosystem"]}`)
for (const dir of matchingDirs) {
core.info(`Creating entry for ${dir} with ecosystem ${entry['package-ecosystem']}`)
const newUpdate = clone(baseUpdate)
newUpdate.directory = dir
newUpdates.push(newUpdate)
Expand All @@ -40,11 +41,12 @@ async function run() {

core.info(`Here's the final config: ${JSON.stringify(newUpdates)}`)
template.updates = newUpdates
core.info("Writing config to .github/dependabot.yml")
await fs.writeFile('.github/dependabot.yml', yaml.dump(template))
core.info('Writing config to .github/dependabot.yml')
const warning = `# This file is generated by the ${actionName} action via a GitHub Actions Workflow from the template file '${templateFile}'. Do not edit directly.`
await fs.writeFile('.github/dependabot.yml', warning + '\n' + yaml.dump(template))
}

run().catch(error => {
console.log(error)
core.setFailed(error.message)
});
})
Loading

0 comments on commit 7afef72

Please sign in to comment.