...
1# How to contribute #
2
3We'd love to accept your patches and contributions to this project. There are
4a just a few small guidelines you need to follow.
5
6
7## Contributor License Agreement ##
8
9Contributions to any Google project must be accompanied by a Contributor
10License Agreement. This is not a copyright **assignment**, it simply gives
11Google permission to use and redistribute your contributions as part of the
12project. Head over to <https://cla.developers.google.com/> to see your current
13agreements on file or to sign a new one.
14
15You generally only need to submit a CLA once, so if you've already submitted one
16(even if it was for a different project), you probably don't need to do it
17again.
18
19
20## Reporting issues ##
21
22Bugs, feature requests, and development-related questions should be directed to
23our [GitHub issue tracker](https://github.com/google/go-github/issues). If
24reporting a bug, please try and provide as much context as possible such as
25your operating system, Go version, and anything else that might be relevant to
26the bug. For feature requests, please explain what you're trying to do, and
27how the requested feature would help you do that.
28
29Security related bugs can either be reported in the issue tracker, or if they
30are more sensitive, emailed to <opensource@google.com>.
31
32## Submitting a patch ##
33
34 1. It's generally best to start by opening a new issue describing the bug or
35 feature you're intending to fix. Even if you think it's relatively minor,
36 it's helpful to know what people are working on. Mention in the initial
37 issue that you are planning to work on that bug or feature so that it can
38 be assigned to you.
39
40 1. Follow the normal process of [forking][] the project, and setup a new
41 branch to work in. It's important that each group of changes be done in
42 separate branches in order to ensure that a pull request only includes the
43 commits related to that bug or feature.
44
45 1. Go makes it very simple to ensure properly formatted code, so always run
46 `go fmt` on your code before committing it. You should also run
47 [golint][] over your code. As noted in the [golint readme][], it's not
48 strictly necessary that your code be completely "lint-free", but this will
49 help you find common style issues.
50
51 1. Any significant changes should almost always be accompanied by tests. The
52 project already has good test coverage, so look at some of the existing
53 tests if you're unsure how to go about it. [gocov][] and [gocov-html][]
54 are invaluable tools for seeing which parts of your code aren't being
55 exercised by your tests.
56
57 1. Please run:
58 * `go generate github.com/google/go-github/...`
59 * `go test github.com/google/go-github/...`
60 * `go vet github.com/google/go-github/...`
61
62 1. Do your best to have [well-formed commit messages][] for each change.
63 This provides consistency throughout the project, and ensures that commit
64 messages are able to be formatted properly by various git tools.
65
66 1. Finally, push the commits to your fork and submit a [pull request][].
67 **NOTE:** Please do not use force-push on PRs in this repo, as it makes
68 it more difficult for reviewers to see what has changed since the last
69 code review.
70
71[forking]: https://help.github.com/articles/fork-a-repo
72[golint]: https://github.com/golang/lint
73[golint readme]: https://github.com/golang/lint/blob/master/README.md
74[gocov]: https://github.com/axw/gocov
75[gocov-html]: https://github.com/matm/gocov-html
76[well-formed commit messages]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
77[squash]: http://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits
78[pull request]: https://help.github.com/articles/creating-a-pull-request
79
80
81## Other notes on code organization ##
82
83Currently, everything is defined in the main `github` package, with API methods
84broken into separate service objects. These services map directly to how
85the [GitHub API documentation][] is organized, so use that as your guide for
86where to put new methods.
87
88Code is organized in files also based pretty closely on the GitHub API
89documentation, following the format `{service}_{api}.go`. For example, methods
90defined at <https://docs.github.com/en/rest/webhooks/repos> live in
91[repos_hooks.go][].
92
93[GitHub API documentation]: https://docs.github.com/en/rest
94[repos_hooks.go]: https://github.com/google/go-github/blob/master/github/repos_hooks.go
95
96
97## Maintainer's Guide ##
98
99(These notes are mostly only for people merging in pull requests.)
100
101**Verify CLAs.** CLAs must be on file for the pull request submitter and commit
102author(s). Google's CLA verification system should handle this automatically
103and will set commit statuses as appropriate. If there's ever any question about
104a pull request, ask [willnorris](https://github.com/willnorris).
105
106**Always try to maintain a clean, linear git history.** With very few
107exceptions, running `git log` should not show a bunch of branching and merging.
108
109Never use the GitHub "merge" button, since it always creates a merge commit.
110Instead, check out the pull request locally ([these git aliases
111help][git-aliases]), then cherry-pick or rebase them onto master. If there are
112small cleanup commits, especially as a result of addressing code review
113comments, these should almost always be squashed down to a single commit. Don't
114bother squashing commits that really deserve to be separate though. If needed,
115feel free to amend additional small changes to the code or commit message that
116aren't worth going through code review for.
117
118If you made any changes like squashing commits, rebasing onto master, etc, then
119GitHub won't recognize that this is the same commit in order to mark the pull
120request as "merged". So instead, amend the commit message to include a line
121"Fixes #0", referencing the pull request number. This would be in addition to
122any other "Fixes" lines for closing related issues. If you forget to do this,
123you can also leave a comment on the pull request [like this][rebase-comment].
124If you made any other changes, it's worth noting that as well, [like
125this][modified-comment].
126
127[git-aliases]: https://github.com/willnorris/dotfiles/blob/d640d010c23b1116bdb3d4dc12088ed26120d87d/git/.gitconfig#L13-L15
128[rebase-comment]: https://github.com/google/go-github/pull/277#issuecomment-183035491
129[modified-comment]: https://github.com/google/go-github/pull/280#issuecomment-184859046
130
131**When creating a release, don't forget to update the `Version` constant in `github.go`.** This is used to send the version in the `User-Agent` header to identify clients to the GitHub API.
View as plain text