-
-
Notifications
You must be signed in to change notification settings - Fork 123
feat: support n commit messages and previous commit message resolving #714
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -114,15 +114,86 @@ core.info(`Running in ${baseDir}`); | |||||||||||||||||||||||
| } else core.info('> Not pulling from repo.'); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| core.info('> Creating commit...'); | ||||||||||||||||||||||||
| await git | ||||||||||||||||||||||||
| .commit(getInput('message'), matchGitArgs(getInput('commit') || '')) | ||||||||||||||||||||||||
| .then(async data => { | ||||||||||||||||||||||||
| log(undefined, data); | ||||||||||||||||||||||||
| setOutput('committed', 'true'); | ||||||||||||||||||||||||
| setOutput('commit_long_sha', data.commit); | ||||||||||||||||||||||||
| setOutput('commit_sha', data.commit.substring(0, 7)); | ||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||
| .catch(err => core.setFailed(err)); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Get commit messages - support for arrays and message templates | ||||||||||||||||||||||||
| let messages = parseInputArray(getInput('message')); | ||||||||||||||||||||||||
| const messageTemplate = getInput('message_template'); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Handle message template (reuse previous commit) | ||||||||||||||||||||||||
| if (messageTemplate) { | ||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||
| const previousCommit = await git.log(['-1']); | ||||||||||||||||||||||||
| const previousMessage = previousCommit.latest?.message || ''; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| if (messageTemplate === 'reuse') { | ||||||||||||||||||||||||
| // Reuse the entire previous commit message | ||||||||||||||||||||||||
| messages = [previousMessage]; | ||||||||||||||||||||||||
| core.info(`> Reusing previous commit message: "${previousMessage}"`); | ||||||||||||||||||||||||
| } else if (messageTemplate.includes('{original}')) { | ||||||||||||||||||||||||
| // Replace {original} placeholder with previous message in the template | ||||||||||||||||||||||||
| const templatedMessage = messageTemplate.replace(/\{original\}/g, previousMessage); | ||||||||||||||||||||||||
| messages = [templatedMessage]; | ||||||||||||||||||||||||
|
Comment on lines
+132
to
+135
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, let me check the structure and find src/main.ts
git ls-files | grep -E "src/main\.(ts|js)$"Repository: EndBug/add-and-commit Length of output: 76 🏁 Script executed: # Read the relevant section of src/main.ts around lines 132-135
head -n 150 src/main.ts | tail -n 50 | cat -nRepository: EndBug/add-and-commit Length of output: 2395 🏁 Script executed: # Get more context around the template replacement to understand previousMessage source
sed -n '100,160p' src/main.ts | cat -nRepository: EndBug/add-and-commit Length of output: 3093 Escape replacement to avoid
🛠️ Proposed fix- const templatedMessage = messageTemplate.replace(/\{original\}/g, previousMessage);
+ const templatedMessage = messageTemplate.replace(
+ /\{original\}/g,
+ () => previousMessage,
+ );📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||
| core.info(`> Using message template: "${templatedMessage}"`); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } catch (err) { | ||||||||||||||||||||||||
| core.warning(`Could not retrieve previous commit message: ${err}`); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Create commits (one or multiple) | ||||||||||||||||||||||||
| let commitFailed = false; | ||||||||||||||||||||||||
| for (let i = 0; i < messages.length; i++) { | ||||||||||||||||||||||||
| const message = messages[i]; | ||||||||||||||||||||||||
| const isLastCommit = i === messages.length - 1; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| if (messages.length > 1) { | ||||||||||||||||||||||||
| core.info(`> Creating commit ${i + 1}/${messages.length}: "${message}"`); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Check for staged changes before attempting commit | ||||||||||||||||||||||||
| const stagedChanges = (await git.diffSummary(['--cached'])).files.length; | ||||||||||||||||||||||||
| const commitArgs = matchGitArgs(getInput('commit') || ''); | ||||||||||||||||||||||||
| const allowEmpty = commitArgs.includes('--allow-empty'); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| if (stagedChanges === 0 && !allowEmpty) { | ||||||||||||||||||||||||
| const errorMsg = `Cannot create commit ${i + 1}/${messages.length}: No staged changes found. Either stage files using add/remove inputs or use '--allow-empty' in the commit input to create empty commits.`; | ||||||||||||||||||||||||
| core.setFailed(errorMsg); | ||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| core.debug( | ||||||||||||||||||||||||
| `Commit ${i + 1}: ${stagedChanges} staged files, --allow-empty: ${allowEmpty}`, | ||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| await git | ||||||||||||||||||||||||
| .commit(message, commitArgs) | ||||||||||||||||||||||||
| .then(async data => { | ||||||||||||||||||||||||
| log(undefined, data); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Only set outputs for the last commit | ||||||||||||||||||||||||
| if (isLastCommit) { | ||||||||||||||||||||||||
| setOutput('committed', 'true'); | ||||||||||||||||||||||||
| setOutput('commit_long_sha', data.commit); | ||||||||||||||||||||||||
| setOutput('commit_sha', data.commit.substring(0, 7)); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||
| .catch(err => { | ||||||||||||||||||||||||
| core.setFailed(err); | ||||||||||||||||||||||||
| commitFailed = true; | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Stop processing if commit failed | ||||||||||||||||||||||||
| if (commitFailed) { | ||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Re-stage files for subsequent commits if there are more to create | ||||||||||||||||||||||||
| if (!isLastCommit) { | ||||||||||||||||||||||||
| core.info('> Re-staging files for next commit...'); | ||||||||||||||||||||||||
| if (getInput('add')) await add(ignoreErrors); | ||||||||||||||||||||||||
| if (getInput('remove')) await remove(ignoreErrors); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| if (getInput('tag')) { | ||||||||||||||||||||||||
| core.info('> Tagging commit...'); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix YAML syntax error in
message_templatedescription.The plain-scalar description contains
chore: {original}(colon + space), which breaks YAML parsing and invalidates the action metadata. Use a block scalar to keep the text intact.🛠️ Proposed fix
📝 Committable suggestion
🧰 Tools
🪛 YAMLlint (1.38.0)
[error] 40-40: syntax error: mapping values are not allowed here
(syntax)
🤖 Prompt for AI Agents