Skip to content

Commit

Permalink
fix: handle parsing of invalid YAML in .travis.yml (#4191)
Browse files Browse the repository at this point in the history
  • Loading branch information
nihalwasheretoo authored and rarkins committed Jul 27, 2019
1 parent 9e5ea71 commit a6b48f6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/manager/travis/extract.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import is from '@sindresorhus/is';
import yaml from 'js-yaml';
import { PackageFile, PackageDependency } from '../common';
import { logger } from '../../logger';

export function extractPackageFile(content: string): PackageFile {
const doc = yaml.safeLoad(content);
let doc;
try {
doc = yaml.safeLoad(content);
} catch (err) {
logger.warn({ err, content }, 'Failed to parse .travis.yml file.');
return null;
}
let deps: PackageDependency[] = [];
if (doc && is.array(doc.node_js)) {
deps = [
Expand Down
2 changes: 2 additions & 0 deletions test/manager/travis/_fixtures/invalid.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
after_deploy:
- "curl -H 'Content-Type: application/json' --data '{\'build\': true}' -X POST $DOCKER_HUB_URL;"
11 changes: 11 additions & 0 deletions test/manager/travis/extract.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { readFileSync } from 'fs';
import { resolve } from 'path';
import { extractPackageFile } from '../../../lib/manager/travis/extract';

const invalidYAML = readFileSync(
resolve('test/manager/travis/_fixtures/invalid.yml'),
'utf8'
);

describe('lib/manager/travis/extract', () => {
describe('extractPackageFile()', () => {
it('returns empty if fails to parse', () => {
Expand All @@ -11,5 +18,9 @@ describe('lib/manager/travis/extract', () => {
expect(res).toMatchSnapshot();
expect(res.deps).toHaveLength(1);
});
it('should handle invalid YAML', () => {
const res = extractPackageFile(invalidYAML);
expect(res).toBeNull();
});
});
});

0 comments on commit a6b48f6

Please sign in to comment.