feat: harden action for handling large diffs#210
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR extends the action’s entrypoint to generate and inject git log/summary/diff content into PR templates, adds configurable limits for PR body size and diff section length, and introduces helper scripts plus unit tests to support template replacement and content splitting.
Changes:
- Add
max_body_bytesandmax_diff_linesinputs, including overflow splitting into “managed” PR comments when the PR body exceeds the configured byte limit. - Replace sed-based template marker replacement with a dedicated
replace-template-diff.shhelper script and add a Python helper to split UTF-8 text by byte limits. - Add unit tests covering branch validation, input validation, template replacement, and content splitting behavior.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
.dockerignore |
Ensures the new scripts/ directory is included in the Docker build context. |
Dockerfile |
Copies helper scripts into the image and marks them executable. |
README.md |
Documents new inputs and required workflow permissions for managed comments. |
action.yml |
Adds new inputs and switches the Docker action to build from the repo Dockerfile. |
entrypoint.sh |
Implements git log/summary/diff helpers, template marker replacement, diff line capping, body-size splitting, and managed comment reconciliation. |
scripts/replace-template-diff.sh |
New helper to replace template markers using external files (summary/commits/files). |
scripts/split_content_bytes.py |
New helper to split UTF-8 content into byte-bounded main body + overflow chunks. |
tests/unit/test_branch_validation.sh |
New unit test validating branch reference handling. |
tests/unit/test_input_limits_validation.sh |
New unit test validating numeric input enforcement. |
tests/unit/test_replace_template_diff.sh |
New unit test validating template marker replacement behavior. |
tests/unit/test_split_content_bytes.py |
New unit test validating byte-bounded splitting and recombination. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| printf '%s' "${TEMPLATE}" > "/tmp/template-final.md" | ||
| apply_body_limits "/tmp/template-final.md" "${MAX_BODY_BYTES}" "${MAX_COMMENT_BODY_BYTES}" | ||
| TEMPLATE="$(cat "${OVERFLOW_MAIN_FILE}")" |
Comment on lines
+203
to
+210
| local with_note_file="/tmp/template-with-note.md" | ||
| { | ||
| cat "${template_file}" | ||
| printf '\n\n---\n' | ||
| printf '_Note: Additional diff output is included in managed comments because body size exceeded max_body_bytes=%s._\n' "${max_body_bytes}" | ||
| } > "${with_note_file}" | ||
|
|
||
| CHUNK_COUNT="$(split_template_by_bytes "${with_note_file}" "${OVERFLOW_MAIN_FILE}" "${OVERFLOW_CHUNK_PREFIX}" "${max_body_bytes}" "${max_comment_bytes}")" |
| local input_name="$2" | ||
|
|
||
| if [[ ! "${value}" =~ ^[0-9]+$ ]]; then | ||
| echo -e "\n[ERROR] Input '${input_name}' must be a non-negative integer. Got: ${value}" |
Comment on lines
+94
to
+101
| local total_lines | ||
| total_lines="$(wc -l < "${file_path}" | tr -d '[:space:]')" | ||
|
|
||
| if (( total_lines > max_lines )); then | ||
| python3 - "$file_path" "$max_lines" "$section_name" <<'PY' | ||
| import pathlib | ||
| import sys | ||
|
|
Comment on lines
+144
to
+148
| --arg actor "${GITHUB_ACTOR}" \ | ||
| --arg start "${MANAGED_COMMENT_START}" \ | ||
| --arg end "${MANAGED_COMMENT_END}" \ | ||
| 'if type == "array" then .[] else . end | ||
| | select(.user.login == $actor and (.body // "" | contains($start)) and (.body // "" | contains($end))) |
|
|
||
| - `contents: read` is required to read repository state. | ||
| - `pull-requests: write` is required to create and update pull requests. | ||
| - `issues: write` is required for larger PRs that will spill over 65000 bytes (default `max_body_bytes`) and create new PR issue comments. In other cases can be omitted. |
Comment on lines
81
to
84
| runs: | ||
| using: docker | ||
| image: docker://devopsinfra/action-pull-request:v1.0.2 | ||
| image: Dockerfile | ||
| env: |
Member
There was a problem hiding this comment.
needed for testing only
Comment on lines
11
to
16
| SHELL ["/bin/bash", "-euxo", "pipefail", "-c"] | ||
| # hadolint ignore=DL3008 | ||
| RUN chmod +x /entrypoint.sh ;\ | ||
| RUN chmod +x /entrypoint.sh /scripts/replace-template-diff.sh /scripts/split_content_bytes.py ;\ | ||
| apt-get update -y ;\ | ||
| apt-get install --no-install-recommends -y \ | ||
| curl \ |
| !Dockerfile | ||
| !entrypoint.sh | ||
| !scripts/ | ||
| !scripts/replace-template-diff.sh |
Comment on lines
+105
to
+107
| trimmed = lines[:limit] | ||
| removed = len(lines) - len(trimmed) | ||
| trimmed.append(f"... truncated {removed} lines from {section} because max_diff_lines={limit} ...") |
ChristophShyper
approved these changes
May 17, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
📝 Brief description
feat: enhance entrypoint script with git log and diff functionalities
temp hardcode Dockerfile
feat: enhance template replacement functionality with conditional file reading
feat: add input limits for PR body size and diff lines, implement content splitting
feat: improve error handling and output formatting in entrypoint script
feat: enhance template source selection and logging in entrypoint script
feat: enhance entrypoint script to improve line truncation logic
fix: update action.yml to use Docker image reference directly
💻 Commits
| fix: update action.yml to use Docker image reference directly
|
| feat: enhance entrypoint script to improve line truncation logic
|
| feat: enhance template source selection and logging in entrypoint script
|
| feat: improve error handling and output formatting in entrypoint script
|
| feat: add input limits for PR body size and diff lines, implement content splitting
|
| feat: enhance template replacement functionality with conditional file reading
|
| temp hardcode Dockerfile
|
feat: enhance entrypoint script with git log and diff functionalities
📁 Modified files
.dockerignore | 3 +
Dockerfile | 6 +-
README.md | 43 +++
action.yml | 8 +
entrypoint.sh | 358 +++++++++++++++++++--
scripts/replace-template-diff.sh (new +x) | 111 +++++++
scripts/split_content_bytes.py (new +x) | 87 +++++
tests/unit/test_branch_validation.sh (new +x) | 95 ++++++
.../unit/test_input_limits_validation.sh (new +x) | 59 ++++
tests/unit/test_replace_template_diff.sh (new +x) | 152 +++++++++
tests/unit/test_split_content_bytes.py (new +x) | 70 ++++
.../test_template_source_selection.sh (new +x) | 168 ++++++++++
12 files changed, 1127 insertions(+), 33 deletions(-)
Check CONTRIBUTING.md and CODE_OF_CONDUCT.md for more information