diff --git a/action.yml b/action.yml index 972047d..9673a9d 100644 --- a/action.yml +++ b/action.yml @@ -11,14 +11,19 @@ inputs: default: ${{ github.token }} commit-msg-template: description: | - The commit message template to use. Variable: `flake_input`. + The commit message template to use. You can use these variables in your template: + + * `{{ flake_dot_lock }}` is the path to the `flake.lock` file being updated + * `{{ flake_dot_lock_dir }}` is the `flake.lock` file's directory + + If you set both this and `commit-msg`, the `commit-msg` setting is used. required: false default: | - flake.lock: Updated {{ flake_input }} + flake.lock: Updated in {{ flake_dot_lock_dir }} commit-msg: - description: "The message provided with the commit" + description: | + The message provided with the commit. required: false - default: "flake.lock: Update" base: description: "Sets the pull request base branch. Defaults to the branch checked out in the workflow." required: false @@ -41,6 +46,12 @@ inputs: description: "The title of the PR to be created" required: false default: "flake.lock: Update" + pr-body-template: + description: | + TODO + required: false + default: | + Just testing. pr-body: description: "The body of the PR to be created" required: false diff --git a/src/index.ts b/src/index.ts index fbb0fa1..18eb7fa 100644 --- a/src/index.ts +++ b/src/index.ts @@ -64,7 +64,11 @@ class UpdateFlakeLockAction extends DetSysAction { const commitMessage = this.commitMessage !== "" ? this.commitMessage - : renderCommitMessage(this.commitMessageTemplate, flakeDotLock); + : renderCommitMessage( + this.commitMessageTemplate, + flakeDir, + flakeDotLock, + ); // Nix command of this form: // nix ${maybe nix options} flake ${"update" or "lock"} ${maybe --update-input flags} --commit-lock-file --commit-lockfile-summary ${commit message} diff --git a/src/template.test.ts b/src/template.test.ts index e586d64..eb546ad 100644 --- a/src/template.test.ts +++ b/src/template.test.ts @@ -1,31 +1,58 @@ -import { renderCommitMessage } from "./template.js"; -import { describe, expect, test } from "vitest"; +import { renderCommitMessage, renderPullRequestBody } from "./template.js"; +import { template } from "handlebars"; +import { Test, describe, expect, test } from "vitest"; describe("templating", () => { test("commit message", () => { type TestCase = { template: string; + flakeDotLockDir: string; flakeDotLock: string; expected: string; }; const testCases: TestCase[] = [ { - template: "Updating lockfile at {{ flake_dot_lock }}", + template: "Updating flake.lock in dir {{ flake_dot_lock_dir }}", + flakeDotLockDir: ".", flakeDotLock: "./flake.lock", - expected: "Updating lockfile at ./flake.lock", + expected: "Updating flake.lock in dir .", }, { template: "Here I go doing some updating of my pristine flake.lock at {{ flake_dot_lock }}", + flakeDotLockDir: "subflake", flakeDotLock: "subflake/flake.lock", expected: "Here I go doing some updating of my pristine flake.lock at subflake/flake.lock", }, + { + template: "This variable doesn't exist: {{ foo }}", + flakeDotLockDir: ".", + flakeDotLock: "./flake.lock", + expected: "This variable doesn't exist: ", + }, ]; - testCases.forEach(({ template, flakeDotLock, expected }) => { - expect(renderCommitMessage(template, flakeDotLock)).toEqual(expected); + testCases.forEach( + ({ template, flakeDotLockDir, flakeDotLock, expected }) => { + expect( + renderCommitMessage(template, flakeDotLockDir, flakeDotLock), + ).toEqual(expected); + }, + ); + }); + + test("pull request body", () => { + type TestCase = { + template: string; + expected: string; + }; + + const testCases: TestCase[] = []; + + testCases.forEach(({ template, expected }) => { + expect(renderPullRequestBody(template)).toEqual(expected); }); }); }); diff --git a/src/template.ts b/src/template.ts index a50c68c..b79b477 100644 --- a/src/template.ts +++ b/src/template.ts @@ -1,10 +1,19 @@ import Handlebars from "handlebars"; +export function renderPullRequestBody(template: string): string { + const tpl = Handlebars.compile(template); + return tpl({}); +} + export function renderCommitMessage( template: string, + flakeDotLockDir: string, flakeDotLock: string, ): string { - return render(template, { flake_dot_lock: flakeDotLock }); + return render(template, { + flake_dot_lock_dir: flakeDotLockDir, + flake_dot_lock: flakeDotLock, + }); } function render(template: string, inputs: Record): string {