Skip to content
Merged
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dependabot-for-git",
"version": "0.0.3",
"version": "0.0.4",
"private": false,
"type": "module",
"description": "Runs dependabot/cli update jobs against Bitbucket Cloud or GitLab repos and turns the results into real pull/merge requests.",
Expand Down
13 changes: 4 additions & 9 deletions src/create-prs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,7 @@ import {
defaultBody,
truncateBody,
} from './lib/format.mjs';

// js-yaml is CommonJS-only; loading it via createRequire avoids ESM/CJS
// default-export interop issues that can crop up depending on the local
// npm/node_modules setup ("does not provide an export named 'default'").
const require = createRequire(import.meta.url);
const yaml = require('js-yaml');
import { load } from 'js-yaml';

export async function createPullRequests(argv = [], { env = process.env, provider } = {}) {
const dryRun = env.DRY_RUN === 'true';
Expand All @@ -55,7 +50,7 @@ export async function createPullRequests(argv = [], { env = process.env, provide
if (skipTransitiveOnly && !touchesManifestFile(files)) {
console.log(
`Skipping transitive-only update for ${dependencies.map((d) => d.name).join(', ')} ` +
`(only touches ${files.map((f) => f.name).join(', ')}, not the manifest)`
`(only touches ${files.map((f) => f.name).join(', ')}, not the manifest)`
);
return;
}
Expand Down Expand Up @@ -85,7 +80,7 @@ export async function createPullRequests(argv = [], { env = process.env, provide
if (skipTransitiveOnly && !touchesManifestFile(files)) {
console.log(
`Skipping transitive-only update for ${dependencies.map((d) => d.name).join(', ')} ` +
`(only touches ${files.map((f) => f.name).join(', ')}, not the manifest)`
`(only touches ${files.map((f) => f.name).join(', ')}, not the manifest)`
);
return;
}
Expand Down Expand Up @@ -127,7 +122,7 @@ export async function createPullRequests(argv = [], { env = process.env, provide
console.log(`No output file at ${outputPath} (likely no updates found), skipping`);
return;
}
const parsed = yaml.load(readFileSync(outputPath, 'utf8'));
const parsed = load(readFileSync(outputPath, 'utf8'));
const calls = parsed?.output ?? parsed ?? [];

for (const entry of calls) {
Expand Down
9 changes: 2 additions & 7 deletions src/run-updates.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@ import { execFileSync } from 'node:child_process';
import { resolve } from 'node:path';
import { createRequire } from 'node:module';
import { createProvider } from './providers/index.mjs';

// js-yaml is CommonJS-only; loading it via createRequire avoids ESM/CJS
// default-export interop issues that can crop up depending on the local
// npm/node_modules setup ("does not provide an export named 'default'").
const require = createRequire(import.meta.url);
const yaml = require('js-yaml');
import { dump } from 'js-yaml';

export async function runUpdates({ env = process.env, provider, execFileSyncImpl = execFileSync } = {}) {
provider = provider ?? createProvider({ env });
Expand Down Expand Up @@ -76,7 +71,7 @@ export async function runUpdates({ env = process.env, provider, execFileSyncImpl

const jobPath = resolve(workDir, `job-${index}.yaml`);
const outputPath = resolve(workDir, `output-${index}.yaml`);
writeFileSync(jobPath, yaml.dump(job));
writeFileSync(jobPath, dump(job));

const args = ['update', '-f', jobPath, '-o', outputPath];
if (DEPENDABOT_UPDATER_IMAGE) args.push('--updater-image', DEPENDABOT_UPDATER_IMAGE);
Expand Down
5 changes: 2 additions & 3 deletions test/create-prs.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import { join } from 'node:path';
import { createRequire } from 'node:module';
import { createPullRequests } from '../src/create-prs.mjs';

const require = createRequire(import.meta.url);
const yaml = require('js-yaml');
import { dump } from 'js-yaml';

function makeFakeProvider(overrides = {}) {
return {
Expand Down Expand Up @@ -38,7 +37,7 @@ async function withScratchDir(fn) {

function writeOutputFile(dir, filename, outputEntries) {
const path = join(dir, filename);
writeFileSync(path, yaml.dump({ output: outputEntries }));
writeFileSync(path, dump({ output: outputEntries }));
return path;
}

Expand Down
9 changes: 4 additions & 5 deletions test/run-updates.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import { join } from 'node:path';
import { createRequire } from 'node:module';
import { runUpdates } from '../src/run-updates.mjs';

const require = createRequire(import.meta.url);
const yaml = require('js-yaml');
import { load } from 'js-yaml';

function makeFakeProvider(overrides = {}) {
return {
Expand Down Expand Up @@ -47,7 +46,7 @@ describe('run-updates orchestration', () => {

const jobPath = join(dir, '.dependabot-run', 'job-0.yaml');
expect(existsSync(jobPath)).to.equal(true);
const job = yaml.load(readFileSync(jobPath, 'utf8'));
const job = load(readFileSync(jobPath, 'utf8'));

expect(job.job['package-manager']).to.equal('npm_and_yarn');
expect(job.job.source).to.deep.equal({ provider: 'fake', repo: 'group/project', directory: '/', commit: 'abc123' });
Expand All @@ -63,7 +62,7 @@ describe('run-updates orchestration', () => {

await runUpdates({ env: { NPM_TOKEN: 'npm-secret' }, provider, execFileSyncImpl });

const job = yaml.load(readFileSync(join(dir, '.dependabot-run', 'job-0.yaml'), 'utf8'));
const job = load(readFileSync(join(dir, '.dependabot-run', 'job-0.yaml'), 'utf8'));
expect(job.credentials).to.deep.include({
type: 'npm_registry',
registry: 'registry.npmjs.org',
Expand All @@ -80,7 +79,7 @@ describe('run-updates orchestration', () => {

await runUpdates({ env: {}, provider, execFileSyncImpl });

const job = yaml.load(readFileSync(join(dir, '.dependabot-run', 'job-0.yaml'), 'utf8'));
const job = load(readFileSync(join(dir, '.dependabot-run', 'job-0.yaml'), 'utf8'));
expect(job.credentials).to.have.length(1);
});
});
Expand Down