cuelang.org/go@v0.10.1/CONTRIBUTING.md (about) 1 # Contribution Guide 2 3 There are many ways to contribute to CUE without writing code! 4 5 * Ask or answer questions via GitHub discussions, Slack, and Discord 6 * Raise issues such as bug reports or feature requests on GitHub 7 * Contributing thoughts and use cases to proposals. CUE can be and is 8 being used in many varied different ways. Sharing experience reports helps 9 to shape proposals and designs. 10 * Create content: share blog posts, tutorials, videos, meetup talks, etc 11 * Add your project to [Unity](https://cuelabs.dev/unity/) to help us test changes to CUE 12 13 ## Before contributing code 14 15 As with many open source projects, CUE uses the GitHub [issue 16 tracker](https://github.com/cue-lang/cue/issues) to not only track bugs, but 17 also coordinate work on new features, bugs, designs and proposals. Given the 18 inherently distributed nature of open-source this coordination is important 19 because it very often serves as the main form of communication between 20 contributors. 21 22 You can also exchange ideas or feedback with other contributors via the 23 `#contributing` [Slack channel](https://cuelang.slack.com/archives/CMY132JKY), 24 as well as the contributor office hours calls which we hold via the 25 [community calendar](https://cuelang.org/s/community-calendar) once per week. 26 27 ### Check the issue tracker 28 29 Whether you already know what contribution to make, or you are searching for an 30 idea, the [issue tracker](https://cuelang.org/issues) is always the first place 31 to go. Issues are triaged to categorize them and manage the workflow. 32 33 Most issues will be marked with one of the following workflow labels (links are 34 to queries in the issue tracker): 35 36 - [**Triage**](https://cuelang.org/issues?q=is%3Aissue+is%3Aopen+label%3ATriage): 37 Requires review by one of the core project maintainers. 38 - [**NeedsInvestigation**](https://cuelang.org/issues?q=is%3Aissue+is%3Aopen+label%3ANeedsInvestigation): 39 The issue is not fully understood and requires analysis to understand the root 40 cause. 41 - [**NeedsDecision**](https://cuelang.org/issues?q=is%3Aissue+is%3Aopen+label%3ANeedsDecision): 42 the issue is relatively well understood, but the CUE team hasn't yet decided 43 the best way to address it. It would be better to wait for a decision before 44 writing code. If you are interested on working on an issue in this state, feel 45 free to "ping" maintainers in the issue's comments if some time has passed 46 without a decision. 47 - [**NeedsFix**](https://cuelang.org/issues?q=is%3Aissue+is%3Aopen+label%3ANeedsFix): 48 the issue is fully understood and code can be written to fix it. 49 - [**help 50 wanted**](https://cuelang.org/issues?q=is%3Aissue+is%3Aopen+label%3A"help+wanted"): 51 project maintainers need input from someone who has experience or expertise to 52 answer or progress this issue. 53 - [**good first 54 issue**](https://cuelang.org/issues?q=is%3Aissue+is%3Aopen+label%3A"good+first+issue"): 55 often combined with `NeedsFix`, `good first issue` indicates an issue is very 56 likely a good candidate for someone 57 looking to make their first code contribution. 58 59 60 ### Open an issue for any new problem 61 62 Excluding very trivial changes, all contributions should be connected to an 63 existing issue. Feel free to open one and discuss your plans. This process 64 gives everyone a chance to validate the design, helps prevent duplication of 65 effort, and ensures that the idea fits inside the goals for the language and 66 tools. It also checks that the design is sound before code is written; the code 67 review tool is not the place for high-level discussions. 68 69 Sensitive security-related issues should be reported to <a 70 href="mailto:security@cuelang.org">security@cuelang.org</a>. 71 72 ## Becoming a code contributor 73 74 The code contribution process used by the CUE project is a little different from 75 that used by other open source projects. We assume you have a basic 76 understanding of [`git`](https://git-scm.com/) and [Go](https://golang.org) 77 (1.22 or later). 78 79 The first thing to decide is whether you want to contribute a code change via 80 GitHub or GerritHub. Both workflows are fully supported, and whilst GerritHub is 81 used by the core project maintainers as the "source of truth", the GitHub Pull 82 Request workflow is 100% supported - contributors should feel entirely 83 comfortable contributing this way if they prefer. 84 85 Contributions via either workflow must be accompanied by a Developer Certificate 86 of Origin. 87 88 ### Asserting a Developer Certificate of Origin 89 90 Contributions to the CUE project must be accompanied by a [Developer Certificate 91 of Origin](https://developercertificate.org/), the text of which is reproduced 92 here for convenience: 93 94 ``` 95 Developer Certificate of Origin 96 Version 1.1 97 98 Copyright (C) 2004, 2006 The Linux Foundation and its contributors. 99 1 Letterman Drive 100 Suite D4700 101 San Francisco, CA, 94129 102 103 Everyone is permitted to copy and distribute verbatim copies of this 104 license document, but changing it is not allowed. 105 106 107 Developer's Certificate of Origin 1.1 108 109 By making a contribution to this project, I certify that: 110 111 (a) The contribution was created in whole or in part by me and I 112 have the right to submit it under the open source license 113 indicated in the file; or 114 115 (b) The contribution is based upon previous work that, to the best 116 of my knowledge, is covered under an appropriate open source 117 license and I have the right under that license to submit that 118 work with modifications, whether created in whole or in part 119 by me, under the same open source license (unless I am 120 permitted to submit under a different license), as indicated 121 in the file; or 122 123 (c) The contribution was provided directly to me by some other 124 person who certified (a), (b) or (c) and I have not modified 125 it. 126 127 (d) I understand and agree that this project and the contribution 128 are public and that a record of the contribution (including all 129 personal information I submit with it, including my sign-off) is 130 maintained indefinitely and may be redistributed consistent with 131 this project or the open source license(s) involved. 132 ``` 133 134 All commit messages must contain the `Signed-off-by` line with an email address 135 that matches the commit author. This line asserts the Developer Certificate of Origin. 136 137 When committing, use the `--signoff` (or `-s`) flag: 138 139 ```console 140 $ git commit -s 141 ``` 142 143 You can also [set up a prepare-commit-msg git 144 hook](#do-i-really-have-to-add-the--s-flag-to-each-commit) to not have to supply 145 the `-s` flag. 146 147 The explanations of the GitHub and GerritHub contribution workflows that follow 148 assume all commits you create are signed-off in this way. 149 150 151 ## Preparing for GitHub Pull Request (PR) Contributions 152 153 First-time contributors that are already familiar with the <a 154 href="https://guides.github.com/introduction/flow/">GitHub flow</a> are 155 encouraged to use the same process for CUE contributions. Even though CUE 156 maintainers use GerritHub for code review, the GitHub PR workflow is 100% 157 supported. 158 159 Here is a checklist of the steps to follow when contributing via GitHub PR 160 workflow: 161 162 - **Step 0**: Review the guidelines on [Good Commit 163 Messages](#good-commit-messages), [The Review Process](#the-review-process) 164 and [Miscellaneous Topics](#miscellaneous-topics) 165 - **Step 1**: Create a GitHub account if you do not have one. 166 - **Step 2**: 167 [Fork](https://docs.github.com/en/get-started/quickstart/fork-a-repo) the CUE 168 project, and clone your fork locally 169 170 171 That's it! You are now ready to send a change via GitHub, the subject of the 172 next section. 173 174 175 176 ## Sending a change via GitHub 177 178 The GitHub documentation around [working with 179 forks](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/getting-started/about-collaborative-development-models) 180 is extensive so we will not cover that ground here. 181 182 Before making any changes it's a good idea to verify that you have a stable 183 baseline by running the tests: 184 185 ```console 186 $ go test ./... 187 ``` 188 189 Then make your planned changes and create a commit from the staged changes: 190 191 ```console 192 # Edit files 193 $ git add file1 file2 194 $ git commit -s 195 ``` 196 197 Notice as we explained above, the `-s` flag asserts the Developer Certificate of 198 Origin by adding a `Signed-off-by` line to a commit. When writing a commit 199 message, remember the guidelines on [good commit 200 messages](#good-commit-messages). 201 202 You’ve written and tested your code, but before sending code out for review, run 203 all the tests from the root of the repository to ensure the changes don’t break 204 other packages or programs: 205 206 ```console 207 $ go test ./... 208 ``` 209 210 Your change is now ready! [Submit a 211 PR](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request) 212 in the usual way. 213 214 Once your PR is submitted, a maintainer will trigger continuous integration (CI) 215 workflows to run and [review your proposed 216 change](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/reviewing-proposed-changes-in-a-pull-request). 217 The results from CI and the review might indicate further changes are required, 218 and this is where the CUE project differs from others: 219 220 ### Making changes to a PR 221 222 Some projects accept and encourage multiple commits in a single PR. Either as a 223 way of breaking down the change into smaller parts, or simply as a record of the 224 various changes during the review process. 225 226 The CUE project follows the Gerrit model of a single commit being the unit of 227 change. Therefore, all PRs must only contain a single commit. But how does this 228 work if you need to make changes requested during the review process? Does this 229 not require you to create additional commits? 230 231 The easiest way to maintain a single commit is to amend an existing commit. 232 Rather misleadingly, this doesn't actually amend a commit, but instead creates a 233 new commit which is the result of combining the last commit and any new changes: 234 235 ```console 236 # PR is submitted, feedback received. Time to make some changes! 237 238 $ git add file1 file2 # stage the files we have added/removed/changed 239 $ git commit --amend # amend the last commit 240 $ git push -f # push the amended commit to your PR 241 ``` 242 243 The `-f` flag is required to force push your branch to GitHub: this overrides a 244 warning from `git` telling you that GitHub knows nothing about the relationship 245 between the original commit in your PR and the amended commit. 246 247 What happens if you accidentally create an additional commit and now have two 248 commits on your branch? No worries, you can "squash" commits on a branch to 249 create a single commit. See the GitHub documentation on [how to squash commits 250 with GitHub 251 Desktop](https://docs.github.com/en/desktop/contributing-and-collaborating-using-github-desktop/managing-commits/squashing-commits), 252 or using the [`git` command 253 interactively](https://medium.com/@slamflipstrom/a-beginners-guide-to-squashing-commits-with-git-rebase-8185cf6e62ec). 254 255 ### PR approved! 256 257 With the review cycle complete, the CI checks green and your PR approved, it 258 will be imported into GerritHub and then submitted. Your PR will close 259 automatically as it is "merged" in GerritHub. Congratulations! You will have 260 made your first contribution to the CUE project. 261 262 263 ## Preparing for GerritHub [CL](https://google.github.io/eng-practices/#terminology) Contributions 264 265 CUE maintainers use GerritHub for code review. It has a powerful review 266 interface with comments that are attributed to patchsets (versions of a change). 267 Orienting changes around a single commit allows for "stacked" changes, and also 268 encourages unrelated changes to be broken into separate CLs because the process 269 of creating and linking CLs is so easy. 270 271 For those more comfortable with contributing via GitHub PRs, please continue to 272 do so: the CUE project supports both workflows so that people have a choice. 273 274 For those who would like to contribute via GerritHub, read on! 275 276 ### Overview 277 278 The first step in the GerritHub flow is registering as a CUE contributor and 279 configuring your environment. Here is a checklist of the required steps to 280 follow: 281 282 - **Step 0**: Review the guidelines on [Good Commit Messages](#good-commit-messages), [The Review Process](#the-review-process) and [Miscellaneous Topics](#miscellaneous-topics) 283 - **Step 1**: Decide which email address you want to use for contributions. 284 - **Step 2**: Set up a [GerritHub](http://gerrithub.io/) account. 285 - **Step 3**: [Install `git-codereview`](#step-3-install-the-git-codereview-command) 286 - **Step 4**: Clone the CUE repository locally. 287 288 289 We cover steps 1-4 in more detail below. 290 291 ### Step 1: Decide which email address you want to use for contributions 292 293 A contribution to CUE is made through a specific e-mail address. Make sure to 294 use the same account throughout the process and for all your subsequent 295 contributions. You may need to decide whether to use a personal address or a 296 corporate address. The choice will depend on who will own the copyright for the 297 code that you will be writing and submitting. You might want to discuss this 298 topic with your employer before deciding which account to use. 299 300 You also need to make sure that your `git` tool is configured to create commits 301 using your chosen e-mail address. You can either configure Git globally (as a 302 default for all projects), or locally (for a single specific project). You can 303 check the current configuration with this command: 304 305 ```console 306 $ git config --global user.email # check current global config 307 $ git config user.email # check current local config 308 ``` 309 310 To change the configured address: 311 312 ```console 313 $ git config --global user.email name@example.com # change global config 314 $ git config user.email name@example.com # change local config 315 ``` 316 317 ### Step 2: Setup a GerritHub account 318 319 If you have not used GerritHub before, setting up an account is a simple 320 process: 321 322 - Visit [GerritHub](http://gerrithub.io/). 323 - Click "First Time Sign In". 324 - Click the green "Sign In" button, to sign in using your GitHub 325 credentials. 326 - When prompted "Which level of GitHub access do you need?", choose 327 "Default" and then click "Login." 328 - Click "Authorize gerritforge-ltd" on the GitHub auth page. 329 - Confirm account profile details and click "Next." 330 331 If you want to use SSH for authentication *to GerritHub*, SSH keys can be 332 [configured in your user 333 profile](https://review.gerrithub.io/settings/#SSHKeys). If you choose to use 334 SSH for authentication, you will not be able to use the `git-codereview` 335 command that's suggested later in this document, as the command [doesn't 336 support SSH-based git 337 origins](https://github.com/golang/go/issues/9599#issuecomment-70538097). 338 339 For HTTP Credentials, [generate a password via your user 340 profile](https://review.gerrithub.io/settings/#HTTPCredentials). Then use an 341 existing HTTP authentication mechanism like `.netrc`, macOS KeyChain, or some 342 other [credential helper](https://git-scm.com/docs/gitcredentials). If you have 343 any troubles with this step, please [raise an 344 issue](https://cuelang.org/issues/new). 345 346 347 ### Step 3: Install the `git-codereview` command 348 349 Changes to CUE must be reviewed before they are accepted, no matter who makes 350 the change. A custom `git` command called `git-codereview` simplifies sending 351 changes to Gerrit. 352 353 Install the `git-codereview` command by running, 354 355 ```console 356 $ go install golang.org/x/review/git-codereview@master 357 ``` 358 359 Make sure `git-codereview` is installed in your shell `PATH`, so that the 360 `git` command can find it. 361 Check that 362 363 ```console 364 $ git codereview help 365 ``` 366 367 prints help text, not an error. 368 369 On Windows, when using git-bash you must make sure that `git-codereview.exe` is 370 in your `git` exec-path. Run `git --exec-path` to discover the right location 371 then create a symbolic link or just copy the executable from $GOPATH/bin to this 372 directory. 373 374 ### Step 4: Clone the CUE repository locally 375 376 Visit https://review.gerrithub.io/admin/repos/cue-lang/cue, then click "SSH" or 377 "HTTP" depending on which authentication mechanism you configured in step 2. 378 Then copy and run the corresponding "Clone" command. Make sure not to use 379 "ANONYMOUS HTTP", as that will not work with `git-codereview` command. 380 381 ## Sending a change via GerritHub 382 383 Sending a change via GerritHub is quite different to the GitHub PR flow. At 384 first the differences might be jarring, but with practice the workflow is 385 incredibly intuitive and far more powerful when it comes to chains of "stacked" 386 changes. 387 388 ### Step 1: Ensure you have a stable baseline 389 390 With a working directory of your local clone of the CUE repository, run the tests: 391 392 ```console 393 $ go test ./... 394 ``` 395 396 ### Step 2: Prepare changes in a new branch 397 398 Each CUE change must be made in a branch, created from the `master` branch. You 399 can use the normal `git` commands to create a branch and stage changes: 400 401 402 ```console 403 $ git checkout -b mybranch 404 $ [edit files...] 405 $ git add [files...] 406 ``` 407 408 To commit changes, instead of `git commit -s`, use `git codereview change -s`. 409 410 411 ```console 412 $ git codereview change -s 413 (opens $EDITOR) 414 ``` 415 416 You can edit the commit description in your favorite editor as usual. The 417 `git codereview change` command will automatically add a unique Change-Id 418 line near the bottom. That line is used by Gerrit to match successive uploads 419 of the same change. Do not edit or delete it. A Change-Id looks like this: 420 421 422 ``` 423 Change-Id: I2fbdbffb3aab626c4b6f56348861b7909e3e8990 424 ``` 425 426 The `git-codereview` command also checks that you've run `go fmt` over the 427 source code, and that the commit message follows the suggested format. 428 429 430 If you need to edit the files again, you can stage the new changes and re-run 431 `git codereview change -s`: each subsequent run will amend the existing commit 432 while preserving the Change-Id. 433 434 Make sure that you always keep a single commit in each branch. If you add more 435 commits by mistake, you can use `git rebase` to [squash them 436 together](https://medium.com/@slamflipstrom/a-beginners-guide-to-squashing-commits-with-git-rebase-8185cf6e62ec) 437 into a single one. 438 439 440 441 442 443 ### Step 3: Test your changes 444 445 You've written and tested your code, but before sending code out for review, run 446 all the tests for the whole tree to ensure the changes don't break other 447 packages or programs: 448 449 450 ```console 451 $ go test ./... 452 ``` 453 454 455 ### Step 4: Send changes for review 456 457 Once the change is ready and tested over the whole tree, send it for review. 458 This is done with the `mail` sub-command which, despite its name, doesn't 459 directly mail anything; it just sends the change to Gerrit: 460 461 462 ```console 463 $ git codereview mail 464 ``` 465 466 Gerrit assigns your change a number and URL, which `git codereview mail` will 467 print, something like: 468 469 470 ``` 471 remote: New Changes: 472 remote: https://review.gerrithub.io/99999 math: improved Sin, Cos and Tan precision for very large arguments 473 ``` 474 475 If you get an error instead, see the ["Troubleshooting mail 476 errors"](#troubleshooting-gerrithub-mail-errors). 477 478 479 ### Step 5: Revise changes after a review 480 481 CUE maintainers will review your code on Gerrit, and you will get notifications 482 via e-mail. You can see the review on Gerrit and comment on them there. You 483 can also reply [using 484 e-mail](https://gerrit-review.googlesource.com/Documentation/intro-user.html#reply-by-email) 485 if you prefer. 486 487 488 If you need to revise your change after the review, edit the files in the same 489 branch you previously created, add them to the Git staging area, and then amend 490 the commit with `git codereview change`: 491 492 493 ```console 494 $ git codereview change # amend current commit (without -s because we already signed-off, above) 495 (open $EDITOR) 496 $ git codereview mail # send new changes to Gerrit 497 ``` 498 499 If you don't need to change the commit description, just save and exit from the 500 editor. Remember not to touch the special `Change-Id` line. 501 502 503 Again, make sure that you always keep a single commit in each branch. If you 504 add more commits by mistake, you can use `git rebase` to [squash them 505 together](https://medium.com/@slamflipstrom/a-beginners-guide-to-squashing-commits-with-git-rebase-8185cf6e62ec) 506 into a single one. 507 508 509 ### CL approved! 510 511 With the review cycle complete, the CI checks green and your CL approved with 512 `+2`, it will be submitted. Congratulations! You will have made your first 513 contribution to the CUE project. 514 515 516 ## Good commit messages 517 518 Commit messages in CUE follow a specific set of conventions, which we discuss in 519 this section. 520 521 522 Here is an example of a good one: 523 524 525 ``` 526 cue/ast/astutil: fix resolution bugs 527 528 This fixes several bugs and documentation bugs in 529 identifier resolution. 530 531 1. Resolution in comprehensions would resolve identifiers 532 to themselves. 533 534 2. Label aliases now no longer bind to references outside 535 the scope of the field. The compiler would catch this invalid 536 bind and report an error, but it is better not to bind in the 537 first place. 538 539 3. Remove some more mentions of Template labels. 540 541 4. Documentation for comprehensions was incorrect 542 (Scope and Node were reversed). 543 544 5. Aliases X in `X=[string]: foo` should only be visible 545 in foo. 546 547 Fixes #946 548 ``` 549 550 ### First line 551 552 The first line of the change description is conventionally a short one-line 553 summary of the change, prefixed by the primary affected package 554 (`cue/ast/astutil` in the example above). 555 556 557 A rule of thumb is that it should be written so to complete the sentence "This 558 change modifies CUE to \_\_\_\_." That means it does not start with a capital 559 letter, is not a complete sentence, and actually summarizes the result of the 560 change. 561 562 563 Follow the first line by a blank line. 564 565 566 ### Main content 567 568 The rest of the description elaborates and should provide context for the change 569 and explain what it does. Write in complete sentences with correct punctuation, 570 just like for your comments in CUE. Don't use HTML, Markdown, or any other 571 markup language. 572 573 574 575 ### Referencing issues 576 577 The special notation `Fixes #12345` associates the change with issue 12345 in 578 the [CUE issue tracker](https://cuelang.org/issue/12345) When this change is 579 eventually applied, the issue tracker will automatically mark the issue as 580 fixed. 581 582 583 If the change is a partial step towards the resolution of the issue, uses the 584 notation `Updates #12345`. This will leave a comment in the issue linking back 585 to the change in Gerrit, but it will not close the issue when the change is 586 applied. 587 588 589 All issues are tracked in the main repository's issue tracker. 590 If you are sending a change against a subrepository, you must use the 591 fully-qualified syntax supported by GitHub to make sure the change is linked to 592 the issue in the main repository, not the subrepository (eg. `Fixes cue-lang/cue#999`). 593 594 595 596 ## The review process 597 598 This section explains the review process in detail and how to approach reviews 599 after a change has been sent to either GerritHub or GitHub. 600 601 602 603 ### Common mistakes 604 605 When a change is sent to Gerrit, it is usually triaged within a few days. A 606 maintainer will have a look and provide some initial review that for first-time 607 contributors usually focuses on basic cosmetics and common mistakes. These 608 include things like: 609 610 611 - Commit message not following the suggested format. 612 - The lack of a linked GitHub issue. The vast majority of changes require a 613 linked issue that describes the bug or the feature that the change fixes or 614 implements, and consensus should have been reached on the tracker before 615 proceeding with it. Gerrit reviews do not discuss the merit of the change, just 616 its implementation. Only trivial or cosmetic changes will be accepted without 617 an associated issue. 618 619 ### Continuous Integration (CI) checks 620 621 After an initial reading of your change, maintainers will trigger CI checks, 622 that run a full test suite and [Unity](https://cuelabs.dev/unity/) 623 checks. Most CI tests complete in a few minutes, at which point a link will be 624 posted in Gerrit where you can see the results, or if you are submitting a PR 625 results are presented as checks towards the bottom of the PR. 626 627 628 If any of the CI checks fail, follow the link and check the full logs. Try to 629 understand what broke, update your change to fix it, and upload again. 630 Maintainers will trigger a new CI run to see if the problem was fixed. 631 632 633 ### Reviews 634 635 The CUE community values very thorough reviews. Think of each review comment 636 like a ticket: you are expected to somehow "close" it by acting on it, either by 637 implementing the suggestion or convincing the reviewer otherwise. 638 639 640 After you update the change, go through the review comments and make sure to 641 reply to every one. In GerritHub you can click the "Done" button to reply 642 indicating that you've implemented the reviewer's suggestion and in GitHub you 643 can mark a comment as resolved; otherwise, click on "Reply" and explain why you 644 have not, or what you have done instead. 645 646 647 It is perfectly normal for changes to go through several round of reviews, with 648 one or more reviewers making new comments every time and then waiting for an 649 updated change before reviewing again. This cycle happens even for experienced 650 contributors, so don't be discouraged by it. 651 652 653 ### Voting conventions in GerritHub 654 655 As they near a decision, reviewers will make a "vote" on your change. 656 The Gerrit voting system involves an integer in the range -2 to +2: 657 658 659 - **+2** The change is approved for being merged. Only CUE maintainers can cast 660 a +2 vote. 661 - **+1** The change looks good, but either the reviewer is requesting minor 662 changes before approving it, or they are not a maintainer and cannot approve 663 it, but would like to encourage an approval. 664 - **-1** The change is not good the way it is but might be fixable. A -1 vote 665 will always have a comment explaining why the change is unacceptable. 666 - **-2** The change is blocked by a maintainer and cannot be approved. Again, 667 there will be a comment explaining the decision. 668 669 ### Reviewed changed in GitHub 670 671 When reviewing a PR, a reviewer will indicate the nature of their response: 672 673 * **Comments** - general feedback without explicit approval. 674 * **Approve** - feedback and approval for this PR to accepted and submitted in 675 GerritHub. 676 * **Request changes** - feedback that must be addressed before this PR can 677 proceed. 678 679 680 681 ### Submitting an approved change 682 683 After the code has been `+2`'ed in GerritHub or "Approved" in GitHub, an 684 approver will apply it to the `master` branch using the Gerrit user interface. 685 This is called "submitting the change". 686 687 688 The two steps (approving and submitting) are separate because in some cases 689 maintainers may want to approve it but not to submit it right away (for 690 instance, the tree could be temporarily frozen). 691 692 693 Submitting a change checks it into the repository. The change description will 694 include a link to the code review, which will be updated with a link to the 695 change in the repository. Since the method used to integrate the changes is 696 Git's "Cherry Pick", the commit hashes in the repository will be changed by the 697 submit operation. 698 699 700 If your change has been approved for a few days without being submitted, feel 701 free to write a comment in GerritHub or GitHub requesting submission. 702 703 704 ## Miscellaneous topics 705 706 This section collects a number of other comments that are outside the 707 issue/edit/code review/submit process itself. 708 709 710 711 ### Copyright headers 712 713 Files in the CUE repository don't list author names, both to avoid clutter and 714 to avoid having to keep the lists up to date. Instead, your name will appear in 715 the [git change log](https://review.gerrithub.io/plugins/gitiles/cue-lang/cue/+log) 716 and in [GitHub's contributor stats](https://github.com/cue-lang/cue/graphs/contributors) 717 when using an email address linked to a GitHub account. 718 719 New files that you contribute should use the standard copyright header 720 with the current year reflecting when they were added. 721 Do not update the copyright year for existing files that you change. 722 723 724 ``` 725 // Copyright 2018 The CUE Authors 726 // 727 // Licensed under the Apache License, Version 2.0 (the "License"); 728 // you may not use this file except in compliance with the License. 729 // You may obtain a copy of the License at 730 // 731 // http://www.apache.org/licenses/LICENSE-2.0 732 // 733 // Unless required by applicable law or agreed to in writing, software 734 // distributed under the License is distributed on an "AS IS" BASIS, 735 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 736 // See the License for the specific language governing permissions and 737 // limitations under the License. 738 ``` 739 740 ### Troubleshooting GerritHub mail errors 741 742 The most common way that the `git codereview mail` command fails is because 743 the e-mail address in the commit does not match the one that you used during the 744 registration process. 745 746 If you see something like... 747 748 749 ``` 750 remote: Processing changes: refs: 1, done 751 remote: 752 remote: ERROR: In commit ab13517fa29487dcf8b0d48916c51639426c5ee9 753 remote: ERROR: author email address your.email@domain.com 754 remote: ERROR: does not match your user account. 755 ``` 756 757 you need to configure Git for this repository to use the e-mail address that you 758 registered with. To change the e-mail address to ensure this doesn't happen 759 again, run: 760 761 762 ```console 763 $ git config user.email email@address.com 764 ``` 765 766 Then change the commit to use this alternative e-mail address with this command: 767 768 769 ```console 770 $ git commit --amend --author="Author Name <email@address.com>" 771 ``` 772 773 Then retry by running: 774 775 776 ```console 777 $ git codereview mail 778 ``` 779 780 781 ### Quickly testing your changes 782 783 Running `go test ./...` for every single change to the code tree is burdensome. 784 Even though it is strongly suggested to run it before sending a change, during 785 the normal development cycle you may want to compile and test only the package 786 you are developing. 787 788 789 In this section, we'll call the directory into which you cloned the CUE 790 repository `$CUEDIR`. As CUE uses Go modules, The `cue` tool built by `go 791 install` will be installed in the `bin/go` in your home directory by default. 792 793 If you're changing the CUE APIs or code, you can test the results in just 794 this package directory. 795 796 ```console 797 $ cd $CUEDIR/cue 798 $ [make changes...] 799 $ go test 800 ``` 801 802 You don't need to build a new cue tool to test it. 803 Instead you can run the tests from the root. 804 805 ```console 806 $ cd $CUEDIR 807 $ go test ./... 808 ``` 809 810 To use the new tool you would still need to build and install it. 811 812 813 ### Specifying a reviewer / CCing others in GerritHub 814 815 You can specify a reviewer or CC interested parties using the `-r` or `-cc` 816 options. Both accept a comma-separated list of e-mail addresses: 817 818 819 ```console 820 $ git codereview mail -r joe@cuelang.org -cc mabel@example.com,math-nuts@swtch.com 821 ``` 822 823 824 ### Synchronize your client with GerritHub 825 826 While you were working, others might have submitted changes to the repository. 827 To update your local branch, run 828 829 830 ```console 831 $ git codereview sync 832 ``` 833 834 (Under the covers this runs 835 `git pull -r`.) 836 837 838 839 ### Reviewing code by others 840 841 As part of the review process reviewers can propose changes directly (in the 842 GitHub workflow this would be someone else attaching commits to a pull request). 843 844 You can import these changes proposed by someone else into your local Git 845 repository. On the Gerrit review page, click the "Download ▼" link in the upper 846 right corner, copy the "Checkout" command and run it from your local Git repo. 847 It will look something like this: 848 849 850 ```console 851 $ git fetch https://review.gerrithub.io/a/cue-lang/cue refs/changes/67/519567/1 && git checkout FETCH_HEAD 852 ``` 853 854 To revert, change back to the branch you were working in. 855 856 857 ### Set up git aliases 858 859 The `git-codereview` command can be run directly from the shell 860 by typing, for instance, 861 862 863 ```console 864 $ git codereview sync 865 ``` 866 867 but it is more convenient to set up aliases for `git-codereview`'s own 868 subcommands, so that the above becomes, 869 870 871 ```console 872 $ git sync 873 ``` 874 875 The `git-codereview` subcommands have been chosen to be distinct from Git's own, 876 so it's safe to define these aliases. To install them, copy this text into your 877 Git configuration file (usually `.gitconfig` in your home directory): 878 879 880 ``` 881 [alias] 882 change = codereview change 883 gofmt = codereview gofmt 884 mail = codereview mail 885 pending = codereview pending 886 submit = codereview submit 887 sync = codereview sync 888 ``` 889 890 891 ### Sending multiple dependent changes 892 893 Advanced users may want to stack up related commits in a single branch. Gerrit 894 allows for changes to be dependent on each other, forming such a dependency 895 chain. Each change will need to be approved and submitted separately but the 896 dependency will be visible to reviewers. 897 898 899 To send out a group of dependent changes, keep each change as a different commit 900 under the same branch, and then run: 901 902 903 ```console 904 $ git codereview mail HEAD 905 ``` 906 907 Make sure to explicitly specify `HEAD`, which is usually not required when 908 sending single changes. 909 910 This is covered in more detail in [the Gerrit 911 documentation](https://gerrit-review.googlesource.com/Documentation/concept-changes.html). 912 913 ### Do I really have to add the `-s` flag to each commit? 914 915 Earlier in this guide we explained the role the [Developer Certificate of 916 Origin](https://developercertificate.org/) plays in contributions to the CUE 917 project. we also explained how `git commit -s` can be used to sign-off each 918 commit. But: 919 920 * it's easy to forget the `-s` flag; 921 * it's not always possible/easy to fix up other tools that wrap the `git commit` 922 step. 923 924 You can automate the sign-off step using a [`git` 925 hook](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks). Run the 926 following commands in the root of a `git` repository where you want to 927 automatically sign-off each commit: 928 929 ``` 930 cat <<'EOD' > .git/hooks/prepare-commit-msg 931 #!/bin/sh 932 933 NAME=$(git config user.name) 934 EMAIL=$(git config user.email) 935 936 if [ -z "$NAME" ]; then 937 echo "empty git config user.name" 938 exit 1 939 fi 940 941 if [ -z "$EMAIL" ]; then 942 echo "empty git config user.email" 943 exit 1 944 fi 945 946 git interpret-trailers --if-exists doNothing --trailer \ 947 "Signed-off-by: $NAME <$EMAIL>" \ 948 --in-place "$1" 949 EOD 950 chmod +x .git/hooks/prepare-commit-msg 951 ``` 952 953 If you already have a `prepare-commit-msg` hook, adapt it accordingly. The `-s` 954 flag will now be implied every time a commit is created. 955 956 957 ## Code of Conduct 958 959 Guidelines for participating in CUE community spaces and a reporting process for 960 handling issues can be found in the [Code of 961 Conduct](https://cuelang.org/docs/contribution_guidelines/conduct).