Skip to content

Commit

Permalink
fix(ansible-galaxy): space parsing (#20679)
Browse files Browse the repository at this point in the history
Co-authored-by: Rhys Arkins <rhys@arkins.net>
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
  • Loading branch information
3 people committed Apr 12, 2023
1 parent b1424dd commit c02cf6a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
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,3 +1,4 @@
import { codeBlock } from 'common-tags';
import { Fixtures } from '../../../../test/fixtures';
import { getSliceEndNumber } from './extract';
import { extractPackageFile } from './';
Expand Down Expand Up @@ -27,6 +28,16 @@ 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 yamlFile = codeBlock`collections:
- name: https://github.com/lowlydba/lowlydba.sqlserver.git
type: git
version: 1.1.3`;
const res = extractPackageFile(yamlFile, '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

0 comments on commit c02cf6a

Please sign in to comment.