-
Notifications
You must be signed in to change notification settings - Fork 407
Add repo traffic support #972
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
Conversation
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 looks like a great start! Thank you for your submission!
You'll want to add yourself to the Authors file as well.
""" | ||
params = {} | ||
if per in ("day", "week"): | ||
params.update(per=per) |
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.
What happens if a user requests a per
that is not one of day or week? There should probably be some checking around this and a raise if invalid options are passed.
Looking at the API itself, it does require a per
argument, so it should be enough to validate that what the function was sent was one of day
or week
, and then just pass whatever it is into the params.
Maybe here, just have an else
block that raises an error about invalid arguments.
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.
Sounds reasonable. Will do.
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.
Although, to be consistent with this behavior, you'll want to update create_blob()
, create_status()
, create_tag()
and archive()
in the Repository
class as well. All these functions accept parameters with a string value from some allowed set, and don't fail if the value is outside of that set (just silently ignore the parameter).
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.
That'd be a nice follow up PR.
Or maybe we can just follow the example. Presumably the API itself will return the error back to the user, and github3.py will surface it accordingly. Worth giving it a test! If the error comes back through nicely then less code is better code :D
""" | ||
params = {} | ||
if per in ("day", "week"): | ||
params.update(per=per) |
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.
Same thing here about validating a proper argument was sent.
@@ -600,6 +602,8 @@ def clones(self, per='day'): | |||
params = {} | |||
if per in ("day", "week"): | |||
params.update(per=per) | |||
else: | |||
raise ValueError("per must be 'day' or 'week'") |
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 looks like the right error to raise. But when adding a Raise we should update the function doc string. I was just looking at this example and saw the docs were updated there.
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.
Of course, thanks for catching that.
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.
Great! I think all that's missing here is the tests, and adding yourself to the authors file! 🎉
Thanks, @omgjlk, I'll add those soon(ish). |
Co-Authored-By: Jesse Keating <omgjlk@github.com>
561103b
to
8567956
Compare
Finally got to those tests. Thanks for your patience, @omgjlk. |
Hey, @omgjlk, would you like me to add anything else to this PR? Or do you think it's ready to be merged? Thanks. |
@omgjlk, is there a reason why this PR has not yet been merged? |
Sorry, I've just been distracted. |
Hrm, the appveyor checks are failing, but for unrelated reasons. |
Addresses #971.
Before I add tests, please have a look at my stab for the repo traffic interface. Would you like something changed?