diff --git a/lib/modules/manager/bazel-module/parser/common.ts b/lib/modules/manager/bazel-module/parser/common.ts new file mode 100644 index 00000000000000..5fe3ad77180d45 --- /dev/null +++ b/lib/modules/manager/bazel-module/parser/common.ts @@ -0,0 +1,29 @@ +import { query as q } from 'good-enough-parser'; +import { regEx } from '../../../../util/regex'; +import type { Ctx } from '../context'; +import * as starlark from '../starlark'; + +const booleanValuesRegex = regEx(`^${starlark.booleanStringValues.join('|')}$`); + +/** + * Matches key-value pairs: + * - `name = "foobar"` + * - `name = True` + * - `name = ["string"]` + **/ +export const kvParams = q + .sym((ctx, token) => ctx.startAttribute(token.value)) + .op('=') + .alt( + q.str((ctx, token) => ctx.addString(token.value)), + q.sym(booleanValuesRegex, (ctx, token) => ctx.addBoolean(token.value)), + q.tree({ + type: 'wrapped-tree', + maxDepth: 1, + startsWith: '[', + endsWith: ']', + postHandler: (ctx) => ctx.endArray(), + preHandler: (ctx) => ctx.startArray(), + search: q.many(q.str((ctx, token) => ctx.addString(token.value))), + }), + ); diff --git a/lib/modules/manager/bazel-module/parser/index.spec.ts b/lib/modules/manager/bazel-module/parser/index.spec.ts index f0137c9f13a09c..aa2311d2c9ee93 100644 --- a/lib/modules/manager/bazel-module/parser/index.spec.ts +++ b/lib/modules/manager/bazel-module/parser/index.spec.ts @@ -66,6 +66,10 @@ describe('modules/manager/bazel-module/parser/index', () => { { rule: fragments.string('git_override'), module_name: fragments.string('rules_foo'), + patches: fragments.array( + [fragments.string('//:rules_foo.patch')], + true, + ), commit: fragments.string( '6a2c2e22849b3e6b33d5ea9aa72222d4803a986a', ), @@ -102,6 +106,10 @@ describe('modules/manager/bazel-module/parser/index', () => { { rule: fragments.string('archive_override'), module_name: fragments.string('rules_foo'), + urls: fragments.array( + [fragments.string('https://example.com/archive.tar.gz')], + true, + ), }, true, ), diff --git a/lib/modules/manager/bazel-module/parser/maven.ts b/lib/modules/manager/bazel-module/parser/maven.ts index 9248297c9a4613..56376b8a13c3bd 100644 --- a/lib/modules/manager/bazel-module/parser/maven.ts +++ b/lib/modules/manager/bazel-module/parser/maven.ts @@ -10,6 +10,7 @@ import { StringArrayFragmentSchema, StringFragmentSchema, } from '../fragments'; +import { kvParams } from './common'; const artifactMethod = 'artifact'; const installMethod = 'install'; @@ -115,22 +116,6 @@ export function fillRegistryUrls( return result; } -const kvParams = q - .sym((ctx, token) => ctx.startAttribute(token.value)) - .op('=') - .alt( - q.str((ctx, token) => ctx.addString(token.value)), - q.tree({ - type: 'wrapped-tree', - maxDepth: 1, - startsWith: '[', - endsWith: ']', - postHandler: (ctx) => ctx.endArray(), - preHandler: (ctx) => ctx.startArray(), - search: q.many(q.str((ctx, token) => ctx.addString(token.value))), - }), - ); - export const mavenRules = q .sym(mavenVariableRegex, (ctx, token) => { return ctx.startRule(token.value); diff --git a/lib/modules/manager/bazel-module/parser/module.ts b/lib/modules/manager/bazel-module/parser/module.ts index ace1d413d7ab8f..80371274c029e3 100644 --- a/lib/modules/manager/bazel-module/parser/module.ts +++ b/lib/modules/manager/bazel-module/parser/module.ts @@ -1,9 +1,8 @@ import { query as q } from 'good-enough-parser'; import { regEx } from '../../../../util/regex'; import type { Ctx } from '../context'; -import * as starlark from '../starlark'; +import { kvParams } from './common'; -const booleanValuesRegex = regEx(`^${starlark.booleanStringValues.join('|')}$`); const supportedRules = [ 'archive_override', 'bazel_dep', @@ -13,19 +12,6 @@ const supportedRules = [ ]; const supportedRulesRegex = regEx(`^${supportedRules.join('|')}$`); -/** - * Matches key-value pairs: - * - `name = "foobar"` - * - `name = True` - **/ -const kvParams = q - .sym((ctx, token) => ctx.startAttribute(token.value)) - .op('=') - .alt( - q.str((ctx, token) => ctx.addString(token.value)), - q.sym(booleanValuesRegex, (ctx, token) => ctx.addBoolean(token.value)), - ); - export const moduleRules = q .sym(supportedRulesRegex, (ctx, token) => ctx.startRule(token.value)) .join(