Skip to content

feat: harden action for handling large diffs#210

Merged
ChristophShyper merged 8 commits into
masterfrom
feat/diff-improvement
May 17, 2026
Merged

feat: harden action for handling large diffs#210
ChristophShyper merged 8 commits into
masterfrom
feat/diff-improvement

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot commented May 15, 2026

📝 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

  • 2e08203 - ChristophShyper - 2026-05-17 19:54:45
    | fix: update action.yml to use Docker image reference directly
    |
  • e7482d9 - ChristophShyper - 2026-05-17 19:54:12
    | feat: enhance entrypoint script to improve line truncation logic
    |
  • 78a49af - ChristophShyper - 2026-05-17 19:24:02
    | feat: enhance template source selection and logging in entrypoint script
    |
  • b353b1d - ChristophShyper - 2026-05-17 18:56:34
    | feat: improve error handling and output formatting in entrypoint script
    |
  • 0ea3718 - ChristophShyper - 2026-05-17 18:22:45
    | feat: add input limits for PR body size and diff lines, implement content splitting
    |
  • bfe6826 - ChristophShyper - 2026-05-15 19:50:31
    | feat: enhance template replacement functionality with conditional file reading
    |
  • 8f22cc7 - ChristophShyper - 2026-05-15 19:28:40
    | temp hardcode Dockerfile
    |
  • 7dc4e17 - ChristophShyper - 2026-05-15 18:48:44
    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(-)

⚠️ Additional information

  • Pushed to a branch with a proper name and provided proper commit message.
  • Provided a clear and concise description of what the issue is.

Check CONTRIBUTING.md and CODE_OF_CONDUCT.md for more information

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_bytes and max_diff_lines inputs, 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.sh helper 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.

Comment thread entrypoint.sh

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}")"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

addressed

Comment thread entrypoint.sh
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}")"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

addressed

Comment thread entrypoint.sh Outdated
local input_name="$2"

if [[ ! "${value}" =~ ^[0-9]+$ ]]; then
echo -e "\n[ERROR] Input '${input_name}' must be a non-negative integer. Got: ${value}"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

addressed

Comment thread entrypoint.sh Outdated
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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

addressed

Comment thread entrypoint.sh Outdated
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)))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

addressed

Comment thread README.md Outdated

- `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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

addressed

Comment thread action.yml
Comment on lines 81 to 84
runs:
using: docker
image: docker://devopsinfra/action-pull-request:v1.0.2
image: Dockerfile
env:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

needed for testing only

Comment thread Dockerfile
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 \
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

addressed

@ChristophShyper ChristophShyper changed the title feat: enhance entrypoint script with git log and diff functionalities feat: harden action for handling large diffs May 17, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

Comment thread .dockerignore
!Dockerfile
!entrypoint.sh
!scripts/
!scripts/replace-template-diff.sh
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

addressed

Comment thread entrypoint.sh Outdated
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} ...")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

addressed

@ChristophShyper ChristophShyper merged commit 0916b92 into master May 17, 2026
3 checks passed
@ChristophShyper ChristophShyper deleted the feat/diff-improvement branch May 17, 2026 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants