Skip to content
This repository has been archived by the owner on Jan 29, 2022. It is now read-only.

Get rack/parser working #5

Merged
merged 1 commit into from
Nov 1, 2017
Merged

Conversation

dhollinger
Copy link
Member

Got the Rack::Parser code and custom parser working. Moved the branch
name parsing into its own method that is call from the call method.
Added a parse_deleted? method as well. The Sinatra params will now
contain params called branch(String) and deleted(Boolean). Code in the
payload POST route has been updated to use these params instead of
running the parsing logic itself.

I also created a new directory call "parsers" under "lib" and moved
webhook_json_parser.rb there. The class's namespace has been updated to
Sinatra::Parsers::WebhookJsonParser. All calls into that file/class have
been updated as well.

All "puts" in the code have been removed as they were there for Dev
troubleshooting purposes.

Updated .gitignore to ignore the .log files in the logs directory,
but also added a .keep file inside the logs directory so users/devs
don't have to create it themselves.

Gemfile.lock was updated after a bundle install and bin/puppet_webhook
had its permissions changed to 755.

All other work is related to the JSON parsing with Rack::Parser

).sub('refs/heads/', '') rescue nil
end

def parse_deleted?(data)
Copy link
Member Author

Choose a reason for hiding this comment

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

Ideas for how to better handle this would be awesome as this is really ugly.

data['refChanges'][0]['type'] rescue nil || # Stash/Bitbucket Server
data['after'] rescue nil # Gitlab
)
return false unless [
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this just be ![...].include?(branch_deleted) so you always return a boolean?

Copy link
Member

Choose a reason for hiding this comment

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

@ekohl Without the leading ! ?

Copy link
Member

Choose a reason for hiding this comment

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

Oh yes, the false unless was too much for me in the early morning :)

Copy link
Member

Choose a reason for hiding this comment

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

Fixed


def parse_deleted?(data)
branch_deleted = (
data['deleted'] rescue nil || # Github
Copy link
Member

Choose a reason for hiding this comment

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

Odd indenting here

Copy link
Member

Choose a reason for hiding this comment

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

Fixed


def parse_branch(data)
(
data['ref'] rescue nil || # github & gitlab
Copy link
Member

Choose a reason for hiding this comment

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

odd indenting here

Copy link
Member

Choose a reason for hiding this comment

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

Fixed

@@ -87,13 +87,7 @@ class PuppetWebhook < Sinatra::Base
data = JSON.parse(decoded, quirks_mode: true)
Copy link
Member

Choose a reason for hiding this comment

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

This might be for a future improvement but I'd expect that if there's a WebhookJsonParser that it'd do all of it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I do believe that Rack::Parser is already doing the work. We just need to update our code to add what we need to the params Rack::Parser builds

Got the Rack::Parser code and custom parser working. Moved the branch
name parsing into its own method that is call from the call method.
Added a parse_deleted? method as well. The Sinatra params will now
contain params called branch(String) and deleted(Boolean). Code in the
payload POST route has been updated to use these params instead of
running the parsing logic itself.

I also created a new directory call "parsers" under "lib" and moved
webhook_json_parser.rb there. The class's namespace has been updated to
Sinatra::Parsers::WebhookJsonParser. All calls into that file/class have
been updated as well.

All "puts" in the code have been removed as they were there for Dev
troubleshooting purposes.

Updated .gitignore to ignore the .log files in the logs directory,
but also added a .keep file inside the logs directory so users/devs
don't have to create it themselves.

Gemfile.lock was updated after a bundle install and bin/puppet_webhook
had its permissions changed to 755.

All other work is related to the JSON parsing with Rack::Parser
@alexjfisher alexjfisher merged commit c16ad2d into voxpupuli:master Nov 1, 2017
@alexjfisher
Copy link
Member

I fixed up the indentation and the parse_deleted? return before merging.
@dhollinger Let me know if you prefer I didn't abuse your branches like this! ;)

@@ -1,6 +1,5 @@
*.gem
webhook.lock
.ruby_version
*.log
logs/
logs/*.log
Copy link
Member

Choose a reason for hiding this comment

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

This should log to /var/log/puppet-webhook or the like, rather than in the gem directory.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, I just haven't gotten around to it yet.

@dhollinger dhollinger deleted the json_parsing branch November 1, 2017 16:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants