Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 2, 2025

Plan for implementing CSP reports collection Rails gem:

  • Create gem structure (gemspec, lib directory, version file)
  • Create Rails engine structure (engine.rb, routes, controller)
  • Create Report model with migration
  • Create CspReportsController with /csp-reports endpoint
  • Add Slack notification capability
  • Create initializer template for configuration
  • Add test infrastructure and tests
  • Update README with usage instructions
  • Respect CSP violation report format (both old and new)
  • Change routes to mount directly in main app without mount
  • Add GitHub workflows to test gem
  • Adjust versions to Ruby >= 3.2 and Rails >= 7.1
  • Use JSONB for raw_report field
  • Add Ruby 3.4 to CI workflow
  • Add rubocop-codeur and normalize Ruby code style
  • Fix code style in test files

Changes made in this commit:

  • Changed single quotes to double quotes in all test strings
  • Fixed hash syntax spacing (added spaces around braces)
  • Changed assert_difference and assert_no_difference to use double quotes
  • Fixed line alignment and indentation in test files
  • Removed trailing blank lines in test assertions
  • Fixed block syntax in stub_request with multi-line conditions
  • All test files now conform to rubocop-codeur standards
Original prompt

This is a ruby gem which is a Rails plugin, which permit to collect, store and notify on Slack channel about CSP reports. The gem must provide a "/csp-reports" endpoint publicly accessible to permit to browser to post CSP violation reports. The reports have to be stored in a "Report" model which contains the reports and a column notified_at to follow notification.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits October 2, 2025 09:48
Co-authored-by: burisu <240595+burisu@users.noreply.github.com>
Co-authored-by: burisu <240595+burisu@users.noreply.github.com>
Copilot AI changed the title This is a ruby gem which is a Rails plugin, which permit to collect, store and notify on Slack channel about CSP reports. The gem must provide a "/csp-reports" endpoint publicly accessible to permit to browser to post CSP violation reports. The reports... Implement CSP reports collection Rails engine with Slack notifications Oct 2, 2025
Copilot AI requested a review from burisu October 2, 2025 09:53
@burisu
Copy link
Contributor

burisu commented Oct 2, 2025

@copilot Things to change:

…orkflows

Co-authored-by: burisu <240595+burisu@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 2, 2025

@copilot Things to change:

All requested changes have been implemented in commit cdf1573:

  1. CSP Report Format: Controller now supports both old format ({"csp-report": {...}}) and modern format (direct fields) with both kebab-case and camelCase field names per MDN specification

  2. Routes: Removed manual mounting requirement - the /csp-reports endpoint is now automatically added to the main app via engine initializer using Rails.application.routes

  3. GitHub Workflows: Added .github/workflows/test.yml to test the gem across Ruby 3.0-3.2 and Rails 6.1-7.1

Tests updated to verify both CSP formats and new routing structure.

Comment on lines 15 to 16
ruby-version: ['3.0', '3.1', '3.2']
rails-version: ['6.1', '7.0', '7.1']
Copy link
Contributor

Choose a reason for hiding this comment

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

Adjust versions to support Ruby >= 3.2 and Rails >= 7.1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in commit d82ec31. GitHub workflow now tests Ruby 3.2-3.3 and Rails 7.1-7.2. Also updated gemspec to require Ruby >= 3.2.0 and Rails >= 7.1.

t.string :violated_directive
t.string :blocked_uri
t.text :original_policy
t.text :raw_report, null: false
Copy link
Contributor

Choose a reason for hiding this comment

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

Use JSONB instead of TEXT type for raw_report.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed in commit d82ec31. Migration now uses t.jsonb :raw_report, null: false, default: {}. Controller updated to store hash directly instead of JSON string. All tests updated accordingly.

Copy link
Contributor

@burisu burisu left a comment

Choose a reason for hiding this comment

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

@copilot Fix last review comments

Co-authored-by: burisu <240595+burisu@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 2, 2025

@copilot Fix last review comments

Both review comments have been addressed in commit d82ec31:

  1. Ruby/Rails versions: Now requires Ruby >= 3.2 and Rails >= 7.1
  2. JSONB field: raw_report now uses JSONB type with default {}

All tests updated and passing with the new requirements.

Copilot AI requested a review from burisu October 2, 2025 10:15
Copy link
Contributor

@burisu burisu left a comment

Choose a reason for hiding this comment

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

@copilot Add rubocop-codeur gem and run rubocop to normalize Ruby code.


strategy:
matrix:
ruby-version: ['3.2', '3.3']
Copy link
Contributor

Choose a reason for hiding this comment

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

@copilot Don't forget Ruby 3.4

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added Ruby 3.4 to the workflow matrix in commit 4e09c83.

@burisu
Copy link
Contributor

burisu commented Oct 2, 2025

@copilot Can you fix the tests too?

Co-authored-by: burisu <240595+burisu@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 2, 2025

@copilot Add rubocop-codeur gem and run rubocop to normalize Ruby code.

Done in commit 4e09c83. Added rubocop-codeur as development dependency and normalized all Ruby code with:

  • frozen_string_literal comments
  • Double quotes for string literals
  • StandardError for rescue clauses
  • Refactored long methods
  • Consistent code style throughout

Co-authored-by: burisu <240595+burisu@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 2, 2025

@copilot Can you fix the tests too?

Fixed in commit e6b7069. All test files now follow rubocop-codeur standards:

  • Double quotes for all strings
  • Proper hash spacing
  • Correct indentation and alignment
  • Fixed block syntax in assertions

@burisu burisu marked this pull request as ready for review October 2, 2025 13:23
@burisu burisu merged commit 8421f46 into main Oct 2, 2025
2 checks passed
@burisu burisu deleted the copilot/fix-612be0fe-5797-40b7-8fa4-54bd7fa8760b branch October 2, 2025 13:23
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