Skip to content

manual song post creation - #435

Open
jtzero wants to merge 1 commit into
mainfrom
manual-post-creation
Open

manual song post creation#435
jtzero wants to merge 1 commit into
mainfrom
manual-post-creation

Conversation

@jtzero

@jtzero jtzero commented Aug 9, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • Added a command-line tool for generating songbook posts from supplied metadata, images, and content.
    • Added validation and clear error reporting for missing or invalid inputs.
    • Added support for formatted metadata, image placement, optional fields, and normalized Markdown filenames.
    • Added a manually triggered workflow that generates posts, runs tests, and opens a pull request automatically.
  • Tests

    • Added comprehensive coverage for post generation, validation, image placement, and file creation.

@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@jtzero, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 42 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 09235873-f291-46d2-8375-a3f6a9cd8e63

📥 Commits

Reviewing files that changed from the base of the PR and between bc44c67 and c78a5f6.

📒 Files selected for processing (1)
  • .github/workflows/create-songbook-post.yml
📝 Walkthrough

Walkthrough

Adds a validated songbook post generator, a CLI entry point, and a manually triggered GitHub Actions workflow. The workflow generates and formats posts, runs tests, creates a pull request, and enables automatic rebase merging.

Changes

Songbook post generation

Layer / File(s) Summary
Post generation and validation
src/lib/createSongbookPost.ts, src/lib/createSongbookPost.test.ts
Defines typed inputs and outputs, parses image placement, validates metadata, serializes Markdown, creates post files, and tests these behaviors.
CLI entry point
package.json, bin/create-songbook-post.ts
Adds the create-songbook-post npm script. The CLI reads inputs, validates required values, creates the post, and reports failures.
Manual workflow automation
.github/workflows/create-songbook-post.yml
Adds manual inputs, dependency setup, post generation, formatting, tests, pull-request creation, and conditional auto-merge.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant GitHubActions
  participant createSongbookPostScript
  participant createSongbookPostFile
  participant PullRequest
  GitHubActions->>createSongbookPostScript: Pass post inputs
  createSongbookPostScript->>createSongbookPostFile: Create validated post
  GitHubActions->>GitHubActions: Format content and run tests
  GitHubActions->>PullRequest: Create pull request and enable auto-merge
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: adding manual tooling and workflow for song post creation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch manual-post-creation

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.


export function formatFrontmatterValue(value: unknown): string {
if (typeof value === "string") {
return `"${value.replace(/"/g, '\\"')}"`;

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/create-songbook-post.yml:
- Around line 55-59: Remove the workflow_dispatch branch input and update the
job to always check out main. Replace DATA_PIPELINE_PR_AUTOMATION_KEY with the
scoped GITHUB_TOKEN for checkout, and set persist-credentials: false so
credentials are not retained; handle any non-main refs only in a separate job
without write permissions or secrets.

In `@src/lib/createSongbookPost.ts`:
- Around line 66-71: Update date handling in createSongbookPost so any non-empty
input.date must match the YYYY-MM-DD format and parse successfully; throw a
validation error when it does not instead of omitting it. Store and serialize
only the validated date value in validationObj and the frontmatter-writing logic
around lines 101-103, and add a regression test covering an invalid date.
- Around line 157-172: Validate cleanFilename in createSongbookPost before
constructing filePath, rejecting path separators and traversal segments so
filename cannot escape targetDir; alternatively resolve the candidate path and
verify it remains within targetDir before calling fs.writeFileSync. Preserve
normal .md/.mdx stripping and post creation for safe slugs.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 96c28cd0-ecb9-4beb-bac8-b1aef22349ae

📥 Commits

Reviewing files that changed from the base of the PR and between e082f33 and bc44c67.

📒 Files selected for processing (5)
  • .github/workflows/create-songbook-post.yml
  • bin/create-songbook-post.ts
  • package.json
  • src/lib/createSongbookPost.test.ts
  • src/lib/createSongbookPost.ts

Comment on lines +55 to +59
branch:
description: "The branch to run on"
required: true
default: "main"
type: string

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -eo pipefail

echo "== file exists =="
git ls-files | grep -FxF ".github/workflows/create-songbook-post.yml" || true

echo "== diff stat =="
git diff --stat # from HEAD if possible

echo "== workflow relevant sections =="
if [ -f .github/workflows/create-songbook-post.yml ]; then
  nl -ba .github/workflows/create-songbook-post.yml | sed -n '1,130p'
fi

echo "== find create-pull-request and automation key usages =="
rg -n "create-pull-request|DATA_PIPELINE_PR_AUTOMATION_KEY|pull_request_token|persist-credentials|actions/checkout|branch:" .github/workflows . -g '!node_modules' -g '!dist' -g '!build' | head -200

Repository: jtzero/cle-gunners

Length of output: 307


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== workflow relevant sections =="
awk '{printf "%6d  %s\n", NR, $0}' .github/workflows/create-songbook-post.yml | sed -n '1,140p'

echo "== focused search =="
grep -RInE 'create-pull-request|DATA_PIPELINE_PR_AUTOMATION_KEY|pull_request_token|persist-credentials|actions/checkout|inputs\.branch|refs/heads|github.ref' .github/workflows . -g '!node_modules' -g '!dist' -g '!build' | head -200

echo "== package scripts =="
if [ -f package.json ]; then
  python3 - <<'PY'
import json
with open("package.json") as f:
    data=json.load(f)
print({k:data.get(k) for k in ("scripts","dependencies","devDependencies")})
PY
fi

Repository: jtzero/cle-gunners

Length of output: 5423


🌐 Web query:

GitHub Actions workflow_dispatch user permissions write access required

💡 Result:

To manually trigger a GitHub Actions workflow using the workflow_dispatch event, write access to the repository is required [1][2][3]. Key details regarding permissions and requirements: 1. Repository Access: Users or service accounts (via tokens) must have write access to the repository to trigger a workflow manually via the GitHub UI, GitHub CLI, or REST API [1][4][3]. 2. Workflow Location: The workflow file must exist on the repository's default branch for the workflow_dispatch trigger to be active and recognized by GitHub [1][5][3]. 3. Authentication Scopes: When using API tokens (Personal Access Tokens or OAuth tokens), the required permissions typically involve repository write access (often represented by the repo scope for classic tokens) or specific fine-grained permissions such as actions:write [6][4][7]. 4. UI Visibility: If a user does not have write access, they will not see the Run workflow button in the GitHub Actions tab, even if the workflow is properly configured [1][2]. In summary, write access is a fundamental requirement for manually invoking workflows configured with workflow_dispatch, as it ensures only authorized users can initiate these actions [1][2][3].

Citations:


🌐 Web query:

npm install runs lifecycle scripts install lifecycle documentation

💡 Result:

In npm, lifecycle scripts are automated hooks defined in the scripts property of a package.json file that execute at specific stages of package installation and management [1][2][3]. As of July 2026, with the release of npm v12, significant security changes have been implemented regarding these scripts [4]. Lifecycle Scripts and npm install When running npm install, the following lifecycle scripts are standard: - preinstall: Executes before the package is installed [3][4]. - install: Executes after the package is installed [3][4]. - postinstall: Executes after the package is installed [3][4]. Important Security Change (npm v12+) Prior to npm v12, these scripts executed automatically by default, posing significant supply chain security risks [5][6][4]. Starting with npm v12 (released July 2026), all dependency install scripts are disabled by default [4]. Furthermore, this protection now extends to the implicit node-gyp rebuild process (triggered by binding.gyp files), which previously acted as a "Phantom Gyp" bypass for security controls [4]. Packages that require these scripts must now be explicitly allowlisted in the project's npm configuration [7][4]. Execution Order During an npm install command, the lifecycle scripts for the project and its dependencies typically follow this general sequence [3]: 1. preinstall 2. install 3. postinstall 4. prepublish 5. preprepare 6. prepare 7. postprepare Note that recent updates have refined the execution of root-level preinstall scripts to ensure they run before dependency resolution (reify) begins, addressing long-standing issues where root scripts could not effectively gate the installation process [8]. Management and Environment Variables - Environment Variable: The npm_lifecycle_event environment variable is set during execution, allowing a single script to detect which lifecycle stage is currently active [1][9][2]. - Best Practices: Users should avoid relying on automatic script execution for critical build steps and should instead use explicit, controlled build processes [5][10]. Reviewing the hasInstallScript flag in package-lock.json is recommended for identifying dependencies that utilize these hooks [4].

Citations:


Do not run dispatcher-selected refs with the automation key.

workflow_dispatch requires write access, and this job checks out $inputs.branch with DATA_PIPELINE_PR_AUTOMATION_KEY before npm install. Even if root install scripts are disabled, selected repository code can still execute with that credential and expose it. Remove the branch input, checkout main, use the scoped GITHUB_TOKEN, and set persist-credentials: false. If non-main refs are required, run them in a separate job without write permissions or secrets.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/create-songbook-post.yml around lines 55 - 59, Remove the
workflow_dispatch branch input and update the job to always check out main.
Replace DATA_PIPELINE_PR_AUTOMATION_KEY with the scoped GITHUB_TOKEN for
checkout, and set persist-credentials: false so credentials are not retained;
handle any non-main refs only in a separate job without write permissions or
secrets.

Source: Linters/SAST tools

Comment on lines +66 to +71
if (input.date && input.date.trim() !== "") {
const parsedDate = new Date(input.date.trim());
if (!isNaN(parsedDate.getTime())) {
validationObj.date = parsedDate;
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Reject invalid dates before serializing frontmatter.

An invalid non-empty date is omitted from validationObj, so postSchema.safeParse can succeed. Lines 101-103 then write that same invalid value into the file. The generated post can fail content parsing after this function reports success.

Require a valid YYYY-MM-DD value and throw when parsing fails. Serialize only the validated value. Add a regression test for an invalid date.

Also applies to: 101-103

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/lib/createSongbookPost.ts` around lines 66 - 71, Update date handling in
createSongbookPost so any non-empty input.date must match the YYYY-MM-DD format
and parse successfully; throw a validation error when it does not instead of
omitting it. Store and serialize only the validated date value in validationObj
and the frontmatter-writing logic around lines 101-103, and add a regression
test covering an invalid date.

Comment on lines +157 to +172
let cleanFilename = input.filename.trim();
if (cleanFilename.endsWith(".md")) {
cleanFilename = cleanFilename.slice(0, -3);
}
if (cleanFilename.endsWith(".mdx")) {
cleanFilename = cleanFilename.slice(0, -4);
}

const markdown = generateSongbookPostMarkdown(input);
const targetDir = path.join(baseDir, "src", "content", "posts");
if (!fs.existsSync(targetDir)) {
fs.mkdirSync(targetDir, { recursive: true });
}

const filePath = path.join(targetDir, `${cleanFilename}.md`);
fs.writeFileSync(filePath, markdown, "utf-8");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

Restrict filename to a safe post slug.

cleanFilename accepts .. path segments. path.join normalizes those segments, so a caller can write outside src/content/posts. Reject path separators and traversal segments, or resolve the path and verify that it remains under targetDir.

Proposed fix
-  let cleanFilename = input.filename.trim();
-  if (cleanFilename.endsWith(".md")) {
-    cleanFilename = cleanFilename.slice(0, -3);
-  }
-  if (cleanFilename.endsWith(".mdx")) {
-    cleanFilename = cleanFilename.slice(0, -4);
+  const cleanFilename = input.filename
+    .trim()
+    .replace(/\.(?:md|mdx)$/i, "");
+  if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(cleanFilename)) {
+    throw new Error("filename must be a lowercase kebab-case post slug");
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let cleanFilename = input.filename.trim();
if (cleanFilename.endsWith(".md")) {
cleanFilename = cleanFilename.slice(0, -3);
}
if (cleanFilename.endsWith(".mdx")) {
cleanFilename = cleanFilename.slice(0, -4);
}
const markdown = generateSongbookPostMarkdown(input);
const targetDir = path.join(baseDir, "src", "content", "posts");
if (!fs.existsSync(targetDir)) {
fs.mkdirSync(targetDir, { recursive: true });
}
const filePath = path.join(targetDir, `${cleanFilename}.md`);
fs.writeFileSync(filePath, markdown, "utf-8");
const cleanFilename = input.filename
.trim()
.replace(/\.(?:md|mdx)$/i, "");
if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(cleanFilename)) {
throw new Error("filename must be a lowercase kebab-case post slug");
}
const markdown = generateSongbookPostMarkdown(input);
const targetDir = path.join(baseDir, "src", "content", "posts");
if (!fs.existsSync(targetDir)) {
fs.mkdirSync(targetDir, { recursive: true });
}
const filePath = path.join(targetDir, `${cleanFilename}.md`);
fs.writeFileSync(filePath, markdown, "utf-8");
🧰 Tools
🪛 ast-grep (0.45.0)

[warning] 171-171: Filesystem path is not a string literal; a request-/variable-derived path can enable path traversal. Validate and normalize the path before use.
Context: fs.writeFileSync(filePath, markdown, "utf-8")
Note: [CWE-22] Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').

(detect-non-literal-fs-filename-typescript)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/lib/createSongbookPost.ts` around lines 157 - 172, Validate cleanFilename
in createSongbookPost before constructing filePath, rejecting path separators
and traversal segments so filename cannot escape targetDir; alternatively
resolve the candidate path and verify it remains within targetDir before calling
fs.writeFileSync. Preserve normal .md/.mdx stripping and post creation for safe
slugs.

Source: Linters/SAST tools

@jtzero
jtzero force-pushed the manual-post-creation branch from bc44c67 to c78a5f6 Compare August 9, 2026 00:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants