-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Asset and Organization resources #10
Conversation
jeffgran-dox
commented
Jun 25, 2024
- Adds some new resources that are newer in the API.
- Updates StructuredScope to have the program id so that it can construct its URLs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR and the added functionality! I have a couple comments below about the implementation, mainly to ensure that calling/ method signatures are consistent across the library.
Are you able to write and record tests for this additional functionality? If you don't have access to a test HackerOne instance, I can help record VCR tests, but would you please mind writing some tests, similar to program_spec.rb and swag_spec.rb?
@@ -4,10 +4,13 @@ | |||
require "json" | |||
require "active_support" | |||
require "active_support/core_ext/numeric/time" | |||
require "ostruct" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be needed, as Ostruct is bundled with Ruby: https://github.com/ruby/ostruct?tab=readme-ov-file#installation.
I don't see anything inherently wrong with this, so fine with the diff but it in theory it shouldn't be breaking anything currently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't need this when I was testing this locally but then when I tried to use it in another context it crashed with an "openstruct is not defined" error. I'm not sure what the cause was, maybe a different ruby version that doesn't require it by default any more or something. So I feel like it's worth leaving it in to prevent someone else from running into that, and like you say I think it should be harmless.
def program_id | ||
@program_id | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've noted a change to the method signature above to accept program
instead. Also, more idiomatically, can we just add a attr_reader :program
above? This will match the implementation in places like
attr_reader :program, :updated_at_after, :page_size |
] | ||
|
||
delegate *DELEGATES, to: :attributes | ||
|
||
def initialize(scope) | ||
def initialize(program_id, scope) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In keeping with the pattern that was set in the Swag object:
def initialize(swag, program = nil) |
Let's set this method signature to scope, program = nil
. This will also allow this change to be backwards compatible.
def initialize(program_id, scope) | |
def initialize(scope, program = nil) |
Here's another callsite that accepts program, for example:
hackerone-client/lib/hackerone/client/incremental/activities.rb
Lines 11 to 12 in cd44f29
def initialize(program, updated_at_after: nil, page_size: 25) | |
@program = program |
type: "structured-scope", | ||
attributes: attributes | ||
} | ||
make_put_request("programs/#{@program_id}/structured_scopes/#{id}", request_body: body) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make_put_request("programs/#{@program_id}/structured_scopes/#{id}", request_body: body) | |
make_put_request("programs/#{@program.id}/structured_scopes/#{id}", request_body: body) |
lib/hackerone/client/asset.rb
Outdated
|
||
delegate *DELEGATES, to: :attributes | ||
|
||
def initialize(organization_id, asset) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pattern in other objects of this library is currently object, additional_parameter
:
def initialize(organization_id, asset) | |
def initialize(asset, organization) |
@rzhade3 thanks for the review! yes, I'll address your comments and work on adding some specs. |
@rzhade3 Hi, I believe I have addressed your feedback and added some specs. However, I do not have an easy way to record new VCR fixtures so I just mocked the requests with webmock, pulling the example responses from their API docs. If you'd rather have these use VCR would you mind modifying the code and recording them for me? Thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes! I'm OK with using Webmock to stub out the request as opposed to re-recording the entire VCR request.
\cc @boveus for final review to see if there's anything more idiomatic we can do with Webmock
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a few Rubocop errors that still need to be fixed. @jeffgran-dox it doesn't appear as if I have permission to push these directly to your branch, could you please accept these suggested changes?
Co-authored-by: Rahul Zhade <[email protected]>
Co-authored-by: Rahul Zhade <[email protected]>
Co-authored-by: Rahul Zhade <[email protected]>
@jeffgran-dox Thanks again for the PR, I've released these changes as version |
@rzhade3 excellent, thank you! |