Skip to content

Commit

Permalink
Don't throw an exception if an empty JSON payload is received (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
NikkelM authored Feb 7, 2024
1 parent cde606c commit 2904844
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
AllCops:
NewCops: enable
TargetRubyVersion: 2.5
TargetRubyVersion: 3.1

Layout/LineLength:
Max: 300
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## v1.1.3

<!--Releasenotes start-->
- The app is now hosted on [Glitch](https://glitch.com/).
- Replaced an exception with a 400 status code when the app receives a webhook event with en empty payload.
<!--Releasenotes end-->

## v1.1.2
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ source 'http://rubygems.org'
gem 'dotenv'
gem 'git'
gem 'jwt', '~> 2.1'
gem 'octokit', '~> 4.0'
gem 'octokit', '~> 5.0'
gem 'puma'
gem 'sinatra', '~> 2.0'
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ GEM
net-http (0.4.1)
uri
nio4r (2.7.0)
octokit (4.25.1)
octokit (5.6.1)
faraday (>= 1, < 3)
sawyer (~> 0.9)
public_suffix (5.0.4)
Expand Down Expand Up @@ -46,7 +46,7 @@ DEPENDENCIES
dotenv
git
jwt (~> 2.1)
octokit (~> 4.0)
octokit (~> 5.0)
puma
sinatra (~> 2.0)

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This list will update whenever new changes are pushed, so you always know exactl
The app supports a wide array of programming languages and action items.
Should you find that your language of choice or action item is not supported, feel free to open an issue.

At the moment, the app is hosted on [Glitch](https://glitch.com/), but it is also set up and configured to be built automatically using Google Cloud Build and hosted through Google Cloud Run.
Whenever a new version is released, the app is automatically built and deployed using Google Cloud Build, and subsequently hosted through Google Cloud Run.

## In-Depth

Expand All @@ -31,7 +31,7 @@ Whenever new changes are pushed to the Pull Request, the app will update the com

You can configure the check to block Pull Requests until all action items are resolved by creating a branch protection rule in your repository settings.

Tech stack: The app is built using Ruby and automatically deployed to Google Cloud Run using Google Cloud Build when a new release is created (*automated deployment has been temporarily paused while the app is hosten on Glitch*).
Tech stack: The app is built using Ruby and automatically deployed to Google Cloud Run using Google Cloud Build when a new release is created.

## Development

Expand Down
9 changes: 5 additions & 4 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
puts "Running Todo PR Checker version: #{VERSION}"

set :bind, '0.0.0.0'
set :port, '3000'
set :port, ENV['PORT'] || '3000'

GITHUB_PRIVATE_KEY = OpenSSL::PKey::RSA.new(ENV.fetch('GITHUB_PRIVATE_KEY', nil).gsub('\n', "\n"))
GITHUB_WEBHOOK_SECRET = ENV.fetch('GITHUB_WEBHOOK_SECRET', nil)
Expand Down Expand Up @@ -143,13 +143,13 @@ def get_pull_request_changes(full_repo_name, pull_number)
diff.each_line do |line|
# This is the most common case, indicating a line was added to the file
if line.start_with?('+') && !line.start_with?('+++')
changes[current_file] << { line: line_number, text: line[1..-1] }
changes[current_file] << { line: line_number, text: line[1..] }
# Lines that start with @@ contain the the starting line and its length for a new block of changes, for the old and new file respectively
elsif line.start_with?('@@')
line_number = line.split()[2].split(',')[0].to_i - 1
# Lines that start with +++ contain the new name of the file, which is the one we want to link to in the comment
elsif line.start_with?('+++')
current_file = line[6..-1].strip
current_file = line[6..].strip
changes[current_file] = []
end

Expand Down Expand Up @@ -273,7 +273,8 @@ def get_payload_request(request)
begin
@payload = JSON.parse @payload_raw
rescue JSON::ParserError => e
raise "Invalid JSON (#{e}): #{@payload_raw}"
logger.debug "Invalid JSON (#{e}): #{@payload_raw}"
halt 400
end
end

Expand Down
16 changes: 0 additions & 16 deletions glitch.json

This file was deleted.

0 comments on commit 2904844

Please sign in to comment.