Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. # Contributing to the Google API Go Client
  2. ## Master git repo
  3. Our master git repo is https://code.googlesource.com/google-api-go-client
  4. ## Pull Requests
  5. We do **NOT** use Github pull requests. We use Gerrit instead
  6. with the same workflow as Go. See below.
  7. ## The source tree
  8. Most of this project is auto-generated.
  9. The notable directories which are not auto-generated:
  10. ```
  11. google-api-go-generator/ -- the generator itself
  12. googleapi/ -- shared common code, used by auto-generated code
  13. examples/ -- sample code
  14. ```
  15. # Contribution Guidelines
  16. ## Introduction
  17. This document explains how to contribute changes to the google-api-go-client project.
  18. ## Testing redux
  19. You've written and tested your code, but
  20. before sending code out for review, run all the tests for the whole
  21. tree to make sure the changes don't break other packages or programs:
  22. ```
  23. $ make cached
  24. $ go test ./...
  25. ...
  26. ok google.golang.org/api/google-api-go-generator 0.226s
  27. ok google.golang.org/api/googleapi 0.015s
  28. ...
  29. ```
  30. Ideally, you will add unit tests to one of the above directories to
  31. demonstrate the changes you are making and include the tests with your
  32. code review.
  33. ## Code review
  34. Changes to google-api-go-client must be reviewed before they are submitted,
  35. no matter who makes the change.
  36. A custom git command called `git-codereview`,
  37. discussed below, helps manage the code review process through a Google-hosted
  38. [instance](https://code-review.googlesource.com/) of the code review
  39. system called [Gerrit](https://code.google.com/p/gerrit/).
  40. ### Set up authentication for code review
  41. The Git code hosting server and Gerrit code review server both use a Google
  42. Account to authenticate. You therefore need a Google Account to proceed.
  43. (If you can use the account to
  44. [sign in at google.com](https://www.google.com/accounts/Login),
  45. you can use it to sign in to the code review server.)
  46. The email address you use with the code review system
  47. needs to be added to the [`CONTRIBUTORS`](/CONTRIBUTORS) file
  48. with your first code review.
  49. You can [create a Google Account](https://www.google.com/accounts/NewAccount)
  50. associated with any address where you receive email.
  51. Visit the site [code.googlesource.com](https://code.googlesource.com)
  52. and log in using your Google Account.
  53. Click on the "Generate Password" link that appears at the top of the page.
  54. Click the radio button that says "Only `code.googlesource.com`"
  55. to use this authentication token only for the google-api-go-client project.
  56. Further down the page is a box containing commands to install
  57. the authentication cookie in file called `.gitcookies` in your home
  58. directory.
  59. Copy the text for the commands into a Unix shell window to execute it.
  60. That will install the authentication token.
  61. (If you are on a Windows computer, you should instead follow the instructions
  62. in the yellow box to run the command.)
  63. ### Register with Gerrit
  64. Now that you have a Google account and the authentication token,
  65. you need to register your account with Gerrit, the code review system.
  66. To do this, visit [golang.org/cl](https://golang.org/cl)
  67. and log in using the same Google Account you used above.
  68. That is all that is required.
  69. ### Install the git-codereview command
  70. Now install the `git-codereview` command by running,
  71. ```
  72. go get -u golang.org/x/review/git-codereview
  73. ```
  74. Make sure `git-codereview` is installed in your shell path, so that the
  75. `git` command can find it. Check that
  76. ```
  77. $ git codereview help
  78. ```
  79. prints help text, not an error.
  80. Note to Git aficionados: The `git-codereview` command is not required to
  81. upload and manage Gerrit code reviews. For those who prefer plain Git, the text
  82. below gives the Git equivalent of each git-codereview command. If you do use plain
  83. Git, note that you still need the commit hooks that the git-codereview command
  84. configures; those hooks add a Gerrit `Change-Id` line to the commit
  85. message and check that all Go source files have been formatted with gofmt. Even
  86. if you intend to use plain Git for daily work, install the hooks in a new Git
  87. checkout by running `git-codereview hooks`.
  88. ### Set up git aliases
  89. The `git-codereview` command can be run directly from the shell
  90. by typing, for instance,
  91. ```
  92. $ git codereview sync
  93. ```
  94. but it is more convenient to set up aliases for `git-codereview`'s own
  95. subcommands, so that the above becomes,
  96. ```
  97. $ git sync
  98. ```
  99. The `git-codereview` subcommands have been chosen to be distinct from
  100. Git's own, so it's safe to do so.
  101. The aliases are optional, but in the rest of this document we will assume
  102. they are installed.
  103. To install them, copy this text into your Git configuration file
  104. (usually `.gitconfig` in your home directory):
  105. ```
  106. [alias]
  107. change = codereview change
  108. gofmt = codereview gofmt
  109. mail = codereview mail
  110. pending = codereview pending
  111. submit = codereview submit
  112. sync = codereview sync
  113. ```
  114. ### Understanding the git-codereview command
  115. After installing the `git-codereview` command, you can run
  116. ```
  117. $ git codereview help
  118. ```
  119. to learn more about its commands.
  120. You can also read the [command documentation](https://godoc.org/golang.org/x/review/git-codereview).
  121. ### Switch to the master branch
  122. New changes should
  123. only be made based on the master branch.
  124. Before making a change, make sure you start on the master branch:
  125. ```
  126. $ git checkout master
  127. $ git sync
  128. ````
  129. (In Git terms, `git sync` runs
  130. `git pull -r`.)
  131. ### Make a change
  132. The entire checked-out tree is writable.
  133. Once you have edited files, you must tell Git that they have been modified.
  134. You must also tell Git about any files that are added, removed, or renamed files.
  135. These operations are done with the usual Git commands,
  136. `git add`,
  137. `git rm`,
  138. and
  139. `git mv`.
  140. If you wish to checkpoint your work, or are ready to send the code out for review, run
  141. ```
  142. $ git change <branch>
  143. ```
  144. from any directory in your google-api-go-client repository to commit the changes so far.
  145. The name `<branch>` is an arbitrary one you choose to identify the
  146. local branch containing your changes.
  147. (In Git terms, `git change <branch>`
  148. runs `git checkout -b branch`,
  149. then `git branch --set-upstream-to origin/master`,
  150. then `git commit`.)
  151. Git will open a change description file in your editor.
  152. (It uses the editor named by the `$EDITOR` environment variable,
  153. `vi` by default.)
  154. The file will look like:
  155. ```
  156. # Please enter the commit message for your changes. Lines starting
  157. # with '#' will be ignored, and an empty message aborts the commit.
  158. # On branch foo
  159. # Changes not staged for commit:
  160. # modified: editedfile.go
  161. #
  162. ```
  163. At the beginning of this file is a blank line; replace it
  164. with a thorough description of your change.
  165. The first line of the change description is conventionally a one-line
  166. summary of the change, prefixed by `google-api-go-client:`,
  167. and is used as the subject for code review mail.
  168. The rest of the
  169. description elaborates and should provide context for the
  170. change and explain what it does.
  171. If there is a helpful reference, mention it here.
  172. After editing, the template might now read:
  173. ```
  174. math: improved Sin, Cos and Tan precision for very large arguments
  175. The existing implementation has poor numerical properties for
  176. large arguments, so use the McGillicutty algorithm to improve
  177. accuracy above 1e10.
  178. The algorithm is described at http://wikipedia.org/wiki/McGillicutty_Algorithm
  179. Fixes #54
  180. # Please enter the commit message for your changes. Lines starting
  181. # with '#' will be ignored, and an empty message aborts the commit.
  182. # On branch foo
  183. # Changes not staged for commit:
  184. # modified: editedfile.go
  185. #
  186. ```
  187. The commented section of the file lists all the modified files in your client.
  188. It is best to keep unrelated changes in different change lists,
  189. so if you see a file listed that should not be included, abort
  190. the command and move that file to a different branch.
  191. The special notation "Fixes #54" associates the change with issue 54 in the
  192. [google-api-go-client issue tracker](https://github.com/google/google-api-go-client/issues/54).
  193. When this change is eventually submitted, the issue
  194. tracker will automatically mark the issue as fixed.
  195. (There are several such conventions, described in detail in the
  196. [GitHub Issue Tracker documentation](https://help.github.com/articles/closing-issues-via-commit-messages/).)
  197. Once you have finished writing the commit message,
  198. save the file and exit the editor.
  199. If you wish to do more editing, re-stage your changes using
  200. `git add`, and then run
  201. ```
  202. $ git change
  203. ```
  204. to update the change description and incorporate the staged changes. The
  205. change description contains a `Change-Id` line near the bottom,
  206. added by a Git commit hook during the initial
  207. `git change`.
  208. That line is used by Gerrit to match successive uploads of the same change.
  209. Do not edit or delete it.
  210. (In Git terms, `git change` with no branch name
  211. runs `git commit --amend`.)
  212. ### Mail the change for review
  213. Once the change is ready, mail it out for review:
  214. ```
  215. $ git mail
  216. ```
  217. You can specify a reviewer or CC interested parties
  218. using the `-r` or `-cc` options.
  219. Both accept a comma-separated list of email addresses:
  220. ```
  221. $ git mail -r joe@golang.org -cc mabel@example.com,math-nuts@swtch.com
  222. ```
  223. Unless explicitly told otherwise, such as in the discussion leading
  224. up to sending in the change list, please specify
  225. `bradfitz@golang.org`, `gmlewis@google.com`, or
  226. `mcgreevy@golang.org` as a reviewer.
  227. (In Git terms, `git mail` pushes the local committed
  228. changes to Gerrit using `git push origin HEAD:refs/for/master`.)
  229. If your change relates to an open issue, please add a comment to the issue
  230. announcing your proposed fix, including a link to your CL.
  231. The code review server assigns your change an issue number and URL,
  232. which `git mail` will print, something like:
  233. ```
  234. remote: New Changes:
  235. remote: https://code-review.googlesource.com/99999 math: improved Sin, Cos and Tan precision for very large arguments
  236. ```
  237. ### Reviewing code
  238. Running `git mail` will send an email to you and the
  239. reviewers asking them to visit the issue's URL and make comments on the change.
  240. When done, the reviewer adds comments through the Gerrit user interface
  241. and clicks "Reply" to send comments back.
  242. You will receive a mail notification when this happens.
  243. You must reply through the web interface.
  244. ### Revise and upload
  245. You must respond to review comments through the web interface.
  246. When you have revised the code and are ready for another round of review,
  247. stage those changes and use `git change` to update the
  248. commit.
  249. To send the update change list for another round of review,
  250. run `git mail` again.
  251. The reviewer can comment on the new copy, and the process repeats.
  252. The reviewer approves the change by giving it a positive score
  253. (+1 or +2) and replying `LGTM`: looks good to me.
  254. You can see a list of your pending changes by running
  255. `git pending`, and switch between change branches with
  256. `git change <branch>`.
  257. ### Synchronize your client
  258. While you were working, others might have submitted changes to the repository.
  259. To update your local branch, run
  260. ```
  261. $ git sync
  262. ```
  263. (In git terms, `git sync` runs
  264. `git pull -r`.)
  265. If files you were editing have changed, Git does its best to merge the
  266. remote changes into your local changes.
  267. It may leave some files to merge by hand.
  268. For example, suppose you have edited `sin.go` but
  269. someone else has committed an independent change.
  270. When you run `git sync`,
  271. you will get the (scary-looking) output:
  272. ```
  273. $ git sync
  274. Failed to merge in the changes.
  275. Patch failed at 0023 math: improved Sin, Cos and Tan precision for very large arguments
  276. The copy of the patch that failed is found in:
  277. /home/you/repo/.git/rebase-apply/patch
  278. When you have resolved this problem, run "git rebase --continue".
  279. If you prefer to skip this patch, run "git rebase --skip" instead.
  280. To check out the original branch and stop rebasing, run "git rebase --abort".
  281. ```
  282. If this happens, run
  283. ```
  284. $ git status
  285. ```
  286. to see which files failed to merge.
  287. The output will look something like this:
  288. ```
  289. rebase in progress; onto a24c3eb
  290. You are currently rebasing branch 'mcgillicutty' on 'a24c3eb'.
  291. (fix conflicts and then run "git rebase --continue")
  292. (use "git rebase --skip" to skip this patch)
  293. (use "git rebase --abort" to check out the original branch)
  294. Unmerged paths:
  295. (use "git reset HEAD <file>..." to unstage)
  296. (use "git add <file>..." to mark resolution)
  297. _both modified: sin.go_
  298. ```
  299. The only important part in that transcript is the italicized "both modified"
  300. line: Git failed to merge your changes with the conflicting change.
  301. When this happens, Git leaves both sets of edits in the file,
  302. with conflicts marked by `<<<<<<<` and
  303. `>>>>>>>`.
  304. It is now your job to edit the file to combine them.
  305. Continuing the example, searching for those strings in `sin.go`
  306. might turn up:
  307. ```
  308. arg = scale(arg)
  309. <<<<<<< HEAD
  310. if arg > 1e9 {
  311. =======
  312. if arg > 1e10 {
  313. >>>>>>> mcgillicutty
  314. largeReduce(arg)
  315. ```
  316. Git doesn't show it, but suppose the original text that both edits
  317. started with was 1e8; you changed it to 1e10 and the other change to 1e9,
  318. so the correct answer might now be 1e10. First, edit the section
  319. to remove the markers and leave the correct code:
  320. ```
  321. arg = scale(arg)
  322. if arg > 1e10 {
  323. largeReduce(arg)
  324. ```
  325. Then tell Git that the conflict is resolved by running
  326. ```
  327. $ git add sin.go
  328. ```
  329. If you had been editing the file, say for debugging, but do not
  330. care to preserve your changes, you can run
  331. `git reset HEAD sin.go`
  332. to abandon your changes.
  333. Then run `git rebase --continue` to
  334. restore the change commit.
  335. ### Reviewing code by others
  336. You can import a change proposed by someone else into your local Git repository.
  337. On the Gerrit review page, click the "Download ▼" link in the upper right
  338. corner, copy the "Checkout" command and run it from your local Git repo.
  339. It should look something like this:
  340. ```
  341. $ git fetch https://code.googlesource.com/review refs/changes/21/1221/1 && git checkout FETCH_HEAD
  342. ```
  343. To revert, change back to the branch you were working in.
  344. ### Submit the change after the review
  345. After the code has been `LGTM`'ed, an approver may
  346. submit it to the master branch using the Gerrit UI.
  347. There is a "Submit" button on the web page for the change
  348. that appears once the change is approved (marked +2).
  349. This checks the change into the repository.
  350. The change description will include a link to the code review,
  351. and the code review will be updated with a link to the change
  352. in the repository.
  353. Since the method used to integrate the changes is "Cherry Pick",
  354. the commit hashes in the repository will be changed by
  355. the submit operation.
  356. ### More information
  357. In addition to the information here, the Go community maintains a [CodeReview](https://golang.org/wiki/CodeReview) wiki page.
  358. Feel free to contribute to this page as you learn the review process.
  359. ## Contributors
  360. Files in the google-api-go-client repository don't list author names,
  361. both to avoid clutter and to avoid having to keep the lists up to date.
  362. Instead, please add your name to the [`CONTRIBUTORS`](/CONTRIBUTORS)
  363. file as your first code review, keeping the names in sorted order.