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

fix(ansible-galaxy): space parsing #20679

Merged
merged 11 commits into from
Apr 12, 2023
13 changes: 12 additions & 1 deletion lib/modules/manager/ansible-galaxy/extract.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { codeBlock } from 'common-tags';
import { Fixtures } from '../../../../test/fixtures';
import { getSliceEndNumber } from './extract';
import { extractPackageFile } from './';

const yamlFile1 = Fixtures.get('requirements01.yml');
const yamlFile2 = Fixtures.get('requirements02.yml');
const yamlFile3 = codeBlock`collections:
- name: https://github.com/lowlydba/lowlydba.sqlserver.git
type: git
version: 1.1.3`;
const helmRequirements = Fixtures.get('helmRequirements.yml');
const collections1 = Fixtures.get('collections1.yml');
const collections2 = Fixtures.get('collections2.yml');
Expand All @@ -27,6 +32,12 @@ describe('modules/manager/ansible-galaxy/extract', () => {
expect(res?.deps).toHaveLength(2);
});

it('extracts dependencies from requirements.yml with a space at the end of line', () => {
const res = extractPackageFile(yamlFile3, 'requirements.yml');
expect(res?.deps).toHaveLength(1);
expect(res?.deps[0].currentValue).toBe('1.1.3');
});

it('check if an empty file returns null', () => {
const res = extractPackageFile('\n', 'requirements.yml');
expect(res).toBeNull();
Expand Down Expand Up @@ -75,7 +86,7 @@ describe('modules/manager/ansible-galaxy/extract', () => {

it('choose second block', () => {
const res = getSliceEndNumber(5, 10, 5);
expect(res).toBe(9);
expect(res).toBe(10);
});
});
});
2 changes: 1 addition & 1 deletion lib/modules/manager/ansible-galaxy/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function getSliceEndNumber(
if (start < 0 || start > numberOfLines - 1) {
return -1;
}
let nearestEnd = numberOfLines - 1;
let nearestEnd = numberOfLines;
for (const blocksKey of blocks) {
if (start < blocksKey && blocksKey < nearestEnd) {
nearestEnd = blocksKey;
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/manager/ansible-galaxy/util.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { regEx } from '../../../util/regex';

export const newBlockRegEx = /^\s*-\s*((\w+):\s*(.*))$/;
export const blockLineRegEx = /^\s*((\w+):\s*(.*))$/;
export const blockLineRegEx = /^\s*((\w+):\s*(\S+))\s*$/;
export const galaxyDepRegex = /[\w-]+\.[\w-]+/;
export const dependencyRegex = /^dependencies:/;
export const galaxyRegEx = regEx(
Expand Down