-
Notifications
You must be signed in to change notification settings - Fork 14
docs: document the variable-substitution templating language #11913
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
Merged
mergify
merged 1 commit into
main
from
devs/kozlek/docs/variable-substitution/document-var-substitution-templating-language--530a11f4
Jun 24, 2026
+277
−41
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import configSchema from '../../util/sanitizedConfigSchema'; | ||
| import { extractTemplateVariables } from '../../util/templateVariables'; | ||
|
|
||
| import { ConfigSchema, Def } from './ConfigOptions'; | ||
| import { renderMarkdown } from './utils'; | ||
|
|
||
| interface TemplateVariablesTableProps extends Def { | ||
| field: string; | ||
| } | ||
|
|
||
| export default function TemplateVariablesTable({ def, field }: TemplateVariablesTableProps) { | ||
| const schema = configSchema as unknown as ConfigSchema; | ||
| const definition = schema.$defs[def]?.properties?.[field]; | ||
| const variables = extractTemplateVariables(definition); | ||
|
|
||
| // Astro's React SSR rejects a component that conditionally returns null/undefined, | ||
| // so render an empty fragment (not null) when the field has no published variables | ||
| // — the graceful state before the engine schema with x-mergify-template-variables | ||
| // is synced into the docs. | ||
| if (variables.length === 0) { | ||
| return <></>; | ||
| } | ||
|
|
||
| return ( | ||
| <div className="table-wrap"> | ||
| <table> | ||
| <thead> | ||
| <tr> | ||
| <th>Variable</th> | ||
| <th>Description</th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| {variables.map((variable) => ( | ||
| <tr key={variable.name}> | ||
| <td> | ||
| <code>{`{{ ${variable.name} }}`}</code> | ||
| </td> | ||
| <td dangerouslySetInnerHTML={{ __html: renderMarkdown(variable.description) }} /> | ||
| </tr> | ||
| ))} | ||
| </tbody> | ||
| </table> | ||
| </div> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| import { extractTemplateVariables } from './templateVariables'; | ||
|
|
||
| describe('extractTemplateVariables', () => { | ||
| it('reads variables from a top-level simple-template field', () => { | ||
| const definition = { | ||
| type: 'string', | ||
| format: 'simple-template', | ||
| 'x-mergify-template-variables': [{ name: 'author', description: 'PR author login' }], | ||
| }; | ||
| expect(extractTemplateVariables(definition)).toEqual([ | ||
| { name: 'author', description: 'PR author login' }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('finds variables inside an anyOf branch (optional field like comment.message)', () => { | ||
| const definition = { | ||
| anyOf: [ | ||
| { | ||
| type: 'string', | ||
| format: 'simple-template', | ||
| 'x-mergify-template-variables': [{ name: 'number', description: 'PR number' }], | ||
| }, | ||
| { type: 'null' }, | ||
| ], | ||
| }; | ||
| expect(extractTemplateVariables(definition)).toEqual([ | ||
| { name: 'number', description: 'PR number' }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('finds variables under additionalProperties → anyOf (dict field like github_actions inputs)', () => { | ||
| const definition = { | ||
| type: 'object', | ||
| additionalProperties: { | ||
| anyOf: [ | ||
| { type: 'integer' }, | ||
| { type: 'boolean' }, | ||
| { | ||
| type: 'string', | ||
| format: 'simple-template', | ||
| 'x-mergify-template-variables': [{ name: 'base', description: 'base branch' }], | ||
| }, | ||
| ], | ||
| }, | ||
| }; | ||
| expect(extractTemplateVariables(definition)).toEqual([ | ||
| { name: 'base', description: 'base branch' }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('returns [] when no template variables are present', () => { | ||
| expect(extractTemplateVariables({ type: 'string' })).toEqual([]); | ||
| expect(extractTemplateVariables(null)).toEqual([]); | ||
| expect(extractTemplateVariables(undefined)).toEqual([]); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.