mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-10-13 08:02:47 +00:00
fix: a programmatic on/mute line joins the existing ones in the header
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
f80d2594b1
commit
eec000b430
@@ -17,6 +17,13 @@ describe('pipeline annotation edits', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('adds `on` next to the existing `on` lines', () => {
|
||||
const sql = '-- pipeline\n-- on schedule\n-- materialize ducklake://main/x\nSELECT 1;'
|
||||
expect(listenToAsset(sql, table, false)).toBe(
|
||||
'-- pipeline\n-- on schedule\n-- on datatable://main/orders\n-- materialize ducklake://main/x\nSELECT 1;'
|
||||
)
|
||||
})
|
||||
|
||||
it('removes an `on` line however it is spelled, options included', () => {
|
||||
const py = '# pipeline\n# on datatable://main/orders debounce=60s\nprint(1)'
|
||||
expect(stopListeningToAsset(py, table, true)).toBe('# pipeline\nprint(1)')
|
||||
|
||||
@@ -66,13 +66,16 @@ function hasDirective(content: string, match: LineMatch): boolean {
|
||||
return header(content.split('\n')).some((l) => matches(l, match))
|
||||
}
|
||||
|
||||
/** Adds `<prefix> <directive>` at the end of the header, in its comment style. */
|
||||
/** Adds `<prefix> <directive>` in the header's comment style: after the last line
|
||||
* of the same directive (`on`, `mute`), so they stay grouped, else at its end. */
|
||||
function addDirective(content: string, directive: string): string {
|
||||
const lines = content.split('\n')
|
||||
const h = header(lines)
|
||||
const last = h[h.length - 1]
|
||||
const line = `${last?.prefix ?? '//'} ${directive}`
|
||||
lines.splice(last ? last.index + 1 : 0, 0, line)
|
||||
const keyword = directive.split(/\s/)[0]
|
||||
const sameKind = h.filter((l) => l.inner.split(/\s/)[0] === keyword)
|
||||
const after = sameKind[sameKind.length - 1] ?? h[h.length - 1]
|
||||
const line = `${after?.prefix ?? '//'} ${directive}`
|
||||
lines.splice(after ? after.index + 1 : 0, 0, line)
|
||||
return lines.join('\n')
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user