Skip to content
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

Vaidate URLs #2896

Closed
wants to merge 3 commits into from
Closed

Vaidate URLs #2896

wants to merge 3 commits into from

Conversation

WillAbides
Copy link
Contributor

Resolves #1203

This addresses the issue raised in #1203 by adding a newURLString function that builds a url the same way they were previously built with fmt.Sprintf but also errors if the result is not valid.

I went this route instead of modifying addOptions because it seemed better to validate all urls instead of only the ones that use addOptions.

This turned into a pretty big diff, but that is the nature of updating boilerplate that is used in hundreds of methods.

@codecov
Copy link

codecov bot commented Aug 23, 2023

Codecov Report

Merging #2896 (2308a59) into master (38ca69f) will decrease coverage by 6.34%.
The diff coverage is 86.53%.

@@            Coverage Diff             @@
##           master    #2896      +/-   ##
==========================================
- Coverage   98.10%   91.77%   -6.34%     
==========================================
  Files         142      142              
  Lines       12340    14695    +2355     
==========================================
+ Hits        12106    13486    +1380     
- Misses        159      809     +650     
- Partials       75      400     +325     
Files Changed Coverage Δ
github/admin_stats.go 91.89% <25.00%> (-8.11%) ⬇️
github/enterprise_code_security_and_analysis.go 79.06% <25.00%> (-20.94%) ⬇️
github/orgs_rules.go 78.57% <25.00%> (-21.43%) ⬇️
github/repos_deployment_branch_policies.go 78.57% <25.00%> (-21.43%) ⬇️
github/repos_rules.go 92.96% <25.00%> (-7.04%) ⬇️
github/search.go 88.00% <25.00%> (-5.62%) ⬇️
github/users_emails.go 76.19% <29.41%> (-18.05%) ⬇️
github/apps_hooks_deliveries.go 75.51% <30.76%> (-16.80%) ⬇️
github/apps_installation.go 76.13% <31.81%> (-15.54%) ⬇️
github/projects.go 81.12% <39.24%> (-15.21%) ⬇️
... and 122 more

Copy link
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

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

Thank you, @WillAbides .
I'm going to stop review now because I'm curious if you are able to see all the Codecov warnings that I'm able to see?

If not, I can highlight them for you, as there are a lot, as also evidenced by the significant drop in code coverage stats. It also found some errors, so I'll let you clean those up before I continue reviewing.

Thanks!

Comment on lines +53 to +56
u, err := newURLString("notifications")
if err != nil {
return nil, nil, err
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't see any benefit in this case. I think we can safely revert this change.

} else {
u = "user/starred"
u, err = newURLString("user/starred")
Copy link
Collaborator

Choose a reason for hiding this comment

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

This line can stay as it was before. Any time newURLString has only a single constant arg, that change can be reverted.

@WillAbides
Copy link
Contributor Author

@gmlewis Thanks for having a look. I knew this would likely have a negative impact on code coverage, but decided to wait on the PR for codecov to show me the diff before worrying about it. As an aside now that I've looked at the coverage, 98.1% coverage on master is impressive.

For the urls that are just static strings, I decided to replace those as well so that we are using a consistent pattern across all methods. I don't feel strongly about that and am happy to revert those.

I'm having doubts about the general usefulness of this PR. It seems like if we catch this error in either newURLString or addOptions we are returning the same error that would have been returned from either client.NewRequest() or http.NewRequest(). Maybe that wasn't the case when #1203 was filed or maybe there is an exception to this that I'm not seeing.

@gmlewis
Copy link
Collaborator

gmlewis commented Aug 23, 2023

I'm having doubts about the general usefulness of this PR. It seems like if we catch this error in either newURLString or addOptions we are returning the same error that would have been returned from either client.NewRequest() or http.NewRequest(). Maybe that wasn't the case when #1203 was filed or maybe there is an exception to this that I'm not seeing.

Honestly, I am totally fine if you want to call this an interesting experiment and determine that the results are not worth it.

I remember filing #1203 after discovering that an error wasn't triggered when I messed something up which sent alarms through my mind, and was hoping that someone else would give it a good investigation and come to a conclusion, which you graciously have... and thank you!

If you wish to point to this PR in that issue and close them both as "unnecessary", I'm totally fine with that and once again really appreciate your detailed investigation!

@WillAbides
Copy link
Contributor Author

Closing this as unnecessary. I also commented on #1203, but I can't actually close it myself.

@WillAbides WillAbides closed this Aug 23, 2023
@WillAbides WillAbides deleted the validurl branch August 23, 2023 16:22
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.

addOptions fails to test URL if nil options are passed
2 participants