-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Implemented HooksService (w/tests) #23
Conversation
Added support for manipulating webhooks for repositories
Stian, thanks for the pull request. A couple of notes:
|
Submitted CLA: "Thank you. Your CLA submission will be processed shortly."
Ah, of course, my bad. I'll refactor and push the changes. |
Oops. Looks like you preempted me on these changes. No worries though, I'll go ahead and comment on differences we have. |
Name string `json:"name"` | ||
Events []string `json:"events,omitempty"` | ||
Active bool `json:"active"` | ||
Config map[string]string `json:"config,omitempty"` |
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 be map[string]interface{}. Values can also be bools, ints, etc.
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.
Looking at https://api.github.com/hooks I do see some boolean values (as well as "password" types, WTF?). I don't actually see any ints, but you're right, this should probably be map[string]interface{}
One idea I toyed around with is the idea of separating the Hook struct into parts: Hook and an anonymous struct HookOptions. The motivation behind this was to separate the fields that the user can edit vs the fields that get returned back to the user. For example, the user can't edit the repo ID or Github URL, and that's not entirely clear from a simple hook struct. Making an anonymous substruct does have the benefit of being able to reference all fields as if they were directly part of the hook struct. You can find an example of this on my fork. Let me know what you think about this. |
Hook api calls belong to the repository service
Couldn't the same thing be achieved by documenting the struct fields, either individually or breaking them into groups? That's actually what I did for I haven't done a good job elsewhere in the API of identifying which fields are mutable 😦. That's actually one of the reasons I made sure to include links back to the GitHub API docs... for those things that aren't clear in the library, you can always refer to the GitHub docs. Of course, ideally you shouldn't have to... it should be clear in the Go source. But I think I'd rather try to accomplish that with docs rather than nested structs if we can. It keeps the overall surface area of the library a little more manageable (and it's already getting pretty big as it is 😕) |
Events []string `json:"events,omitempty"` | ||
Active bool `json:"active"` | ||
Config map[string]interface{} `json:"config,omitempty"` | ||
Id int `json:"id,omitempty"` |
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.
Small nit here: general convention is to make acronyms all upper or lower case, never mixed. For example, "URL" or "url" is good, but not "Url". This rule also applies to ID.
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.
Fixed, thank you :)
I suppose that works. I can see where it makes more sense with other structs to keep everything together as one (like keeping Name as part of Repository). |
UpdatedAt *time.Time `json:"updated_at,omitempty"` | ||
Name string `json:"name"` | ||
Events []string `json:"events,omitempty"` | ||
Active bool `json:"active"` |
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 noticed while testing this that the json serializer skip bool fields that are false if omitempty is enabled.
This meant that it was not possible to deactivate a webhook as "active":false was dropped from the json, only possible to activate one ("active":true worked). I removed omitempty from the bool field here because of this.
This has the side effect that all Hooks are per default Active = false. The default from github would normally be active: true.
Any idea how to fix this if needed? (it isn't possible to set default values for a struct in Go afaik)
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.
yep, this problem is pretty well documented in #19. The solution will be to change all of these fields to be pointers, I just haven't sat down to do that yet. I'll probably do it sometime this 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.
so for now, leave the omitempty
in there.
yep, should definitely do that. Since |
As a general discussion: Are we going to continue to keep everything under one large repos.go file are are we ever going to split up each API into its own file (hooks.go, statuses.go, forks.go, etc.)? |
merged as d79a5b0 |
thus far, I've kept everything in a single file per service... I haven't felt a strong need to separate them out just yet. I did leave |
(just closing the PR since the code is now merged in... happy to continue discussing code organization) |
I was thinking about adopting some sort of naming scheme that would easily allow us to separate and distinguish source files and the APIs they provide. Instead of looking through repos.go (which after adding all 12 APIs, might be very lengthy) for the ListHook function, why not separate the hook API into something like repos_hooks.go. This lets us sort APIs into separate files while still keeping everything in a single package and making a clear relation to the service they are a part of. It also is a close mapping to the overall layout of the Github API (i.e. http://developer.github.com/v3/repos/ -> repos.go and http://developer.github.com/v3/repos/hooks/ -> repos_hooks.go). I think this is something we should definitely consider for a large services such as RepositoryService, and apply to smaller services as a matter of consistency. |
yeah, I like that naming pattern. let's go for it 🤘 |
Added support for manipulating hooks via the hooks api