Skip to content

Conversation

@vaind
Copy link
Contributor

@vaind vaind commented Sep 19, 2025

Summary

Implements GitHub Issue #45 by replacing generic markdown instructions with inline GitHub suggestions that users can apply with one click.

  • Problem: Users had to manually copy-paste changelog entries from Danger instructions
  • Solution: Generate precise inline GitHub suggestions using PR review comments API
  • Impact: Dramatically improves developer experience for changelog management

Changes Made

Core Implementation

  • findChangelogInsertionPoint(): Parses CHANGELOG.md to find exact line numbers and determines content type needed
  • generateChangelogSuggestion(): Creates properly formatted suggestion text based on what needs to be inserted
  • Enhanced reportMissingChangelog(): Uses danger.github.api.rest.pulls.createReviewComment() to create inline suggestions

Key Features ✨

  • Universal Compatibility: Works with ANY changelog state (empty, missing sections, existing structure)
  • Smart Content Generation: Creates full sections when needed or just entries when appropriate
  • Line-Accurate Targeting: Finds exact insertion points in CHANGELOG.md
  • GitHub Suggestion Syntax: Uses ```suggestion markdown blocks for one-click application
  • Robust Error Handling: Falls back to current behavior if API calls fail
  • Format Preservation: Maintains existing changelog structure

Flexible Insertion Logic

The implementation now handles three content scenarios:

  1. unreleased-and-section: No UNRELEASED section exists

    ## Unreleased
    
    ### Features
    
    - New feature ([#123](URL))
  2. section-and-entry: UNRELEASED exists but subsection doesn't

    ### Features
    
    - New feature ([#123](URL))
  3. entry-only: Both UNRELEASED and subsection exist

    - New feature ([#123](URL))

Comprehensive Testing

  • 43 comprehensive tests covering:
    • All insertion scenarios (missing sections, existing structure, edge cases)
    • Empty changelog files, mixed case headers, whitespace handling
    • Different changelog formats found across repositories
  • All existing functionality preserved (backward compatible)

Before vs After

Current Behavior (❌)

Please consider adding a changelog entry for the next release.

### Instructions and example for changelog
Please add an entry to CHANGELOG.md to the "Unreleased" section...

New Behavior (✅)

For existing structured changelog:

### Features

+- Fix memory leak in authentication ([#123](PR_URL))
- Existing feature ([#122](URL))

For completely new changelog:

+## Unreleased
+
+### Features
+
+- Initial release ([#1](PR_URL))
+
## 1.0.0

With "Apply suggestion" button for one-click changelog updates

Test Plan

  • Unit tests pass (43/43) - covers all edge cases
  • Backward compatibility maintained
  • Error handling tested (fallback to markdown instructions)
  • Empty changelog file handling
  • Missing section creation
  • Integration test with real PR (manual testing required)
  • Verify suggestions appear correctly in GitHub UI
  • Test "Apply suggestion" functionality

Implementation Notes

  • Uses GitHub's native suggestion syntax (\``suggestion`)
  • Leverages existing Danger.js GitHub API integration via Octokit
  • Maintains all current behavior as fallback for error cases
  • No breaking changes to existing functionality
  • Now works with ANY changelog state, not just pre-structured ones

Closes #45

🤖 Generated with Claude Code

Implements GitHub Issue #45 by replacing generic markdown instructions
with inline GitHub suggestions that users can apply with one click.

Changes:
- Add findChangelogInsertionPoint() to parse CHANGELOG.md structure
- Add generateChangelogSuggestion() to create formatted suggestions
- Update reportMissingChangelog() to use GitHub PR review comments API
- Maintain backward compatibility with fallback to markdown instructions
- Add comprehensive test suite (34 tests) covering edge cases

Users will now see precise inline suggestions instead of copy-paste
instructions, improving developer experience for changelog management.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions
Copy link
Contributor

github-actions bot commented Sep 19, 2025

Fails
🚫 Please consider adding a changelog entry for the next release.
Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Instructions and example for changelog

Please add an entry to CHANGELOG.md to the "Unreleased" section. Make sure the entry includes this PR's number.

Example:

## Unreleased

### Features

- Danger - Add inline changelog suggestions for GitHub PRs ([#107](https://github.com/getsentry/github-workflows/pull/107))

If none of the above apply, you can opt out of this check by adding #skip-changelog to the PR description or adding a skip-changelog label.

Generated by 🚫 dangerJS against e13e65f

Enhanced changelog insertion logic to handle all possible scenarios:

- **No UNRELEASED section**: Creates full "## Unreleased\n### Section\n- Entry"
- **UNRELEASED but no subsection**: Creates "### Section\n- Entry"
- **Both exist**: Just adds "- Entry"

Changes:
- Refactored findChangelogInsertionPoint() to return insertContent type
- Updated generateChangelogSuggestion() with switch statement for content types
- Added 8 new edge case tests (43 total tests, all passing)
- Handles empty changelogs, missing sections, mixed case headers

This makes the feature work with any changelog state, not just existing
structured changelogs.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
vaind added a commit that referenced this pull request Sep 19, 2025
Adds changelog entry for PR #107 implementing GitHub Issue #45.
This should resolve the Danger CI failure requesting a changelog entry.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@vaind vaind force-pushed the feature/inline-changelog-suggestions branch from ddb7bac to c4e607f Compare September 19, 2025 13:29
vaind and others added 2 commits September 19, 2025 15:30
GitHub PR review comments API can only target files that are part of
the PR diff. When CHANGELOG.md is not modified in the PR, we cannot
create inline suggestions and must fall back to markdown instructions.

Changes:
- Check if changelogFile is in danger.git modified/created/deleted files
- Fall back to markdown instructions when file not in diff
- Add warning log explaining why inline suggestions cannot be used

This fixes the CI error: "could not be resolved" for pull_request_review_thread.path

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@vaind
Copy link
Contributor Author

vaind commented Sep 19, 2025

Closing this PR after discovering fundamental limitations that make the inline suggestions feature impractical for real-world use.

Issues Discovered

1. GitHub API Limitation: Files Must Be in PR Diff

The GitHub PR review comments API can only create suggestions on files that are part of the PR's changed files. This means:

  • ❌ Most PRs don't modify CHANGELOG.md, so suggestions can't be created
  • ❌ The feature only works when changelog is already being modified (rare case)
  • ❌ Falls back to existing markdown instructions in majority of cases

2. Permission Issues with GitHub API

When attempting to use the GitHub API for suggestions:

  • 403: Resource not accessible by integration errors
  • ❌ Default GITHUB_TOKEN has insufficient permissions for review comments
  • ❌ Would require elevated permissions that aren't available in standard workflows

Analysis

The core idea was sound - replace copy-paste instructions with one-click suggestions. However, the GitHub API constraints make this feature work only in edge cases:

When it works: PR already modifies CHANGELOG.md + sufficient permissions
When it fails: PR doesn't modify CHANGELOG.md (99% of cases) OR permission issues

Since the vast majority of PRs don't touch the changelog file, this feature would rarely provide value over the existing markdown instructions.

Implementation Quality

The code implementation itself was solid:

  • ✅ 43 comprehensive tests covering all scenarios
  • ✅ Robust error handling and fallback logic
  • ✅ Universal changelog format support
  • ✅ Clean, well-documented code

But good implementation can't overcome fundamental API limitations.

Recommendation

Keep the existing markdown instructions approach. It works reliably across all scenarios and doesn't require special permissions or API constraints.

Thanks for the learning experience in exploring GitHub's API boundaries! 🤖

Closes #45 as not feasible due to GitHub API limitations.

@vaind vaind closed this Sep 19, 2025
@vaind vaind deleted the feature/inline-changelog-suggestions branch September 19, 2025 13:52
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.

Danger: suggest changelog change inline

2 participants