github.com/vmware/govmomi@v0.37.2/CONTRIBUTING.md (about)

     1  # Contributing to `govmomi`
     2  
     3  ## Getting started
     4  
     5  First, fork the repository on GitHub to your personal account.
     6  
     7  Change `$USER` in the examples below to your Github username if they are not the
     8  same.
     9  
    10  ```bash
    11  git clone https://github.com/vmware/govmomi.git && cd govmomi
    12  
    13  # prevent accidentally pushing to vmware/govmomi
    14  git config push.default nothing
    15  git remote rename origin vmware
    16  
    17  # add your fork
    18  git remote add $USER git@github.com:$USER/govmomi.git
    19  
    20  git fetch -av
    21  ```
    22  
    23  ## Contribution Flow
    24  
    25  This is a rough outline of what a contributor's workflow looks like:
    26  
    27  - Create an issue describing the feature/fix
    28  - Create a topic branch from where you want to base your work.
    29  - Make commits of logical units.
    30  - Make sure your commit messages are in the proper format (see below).
    31  - Push your changes to a topic branch in your fork of the repository.
    32  - Submit a pull request to `vmware/govmomi`.
    33  
    34  See [below](#format-of-the-commit-message) for details on commit best practices
    35  and **supported prefixes**, e.g. `govc: <message>`.
    36  
    37  > **Note:** If you are new to Git(hub) check out [Git rebase, squash...oh
    38  > my!](https://www.mgasch.com/2021/05/git-basics/) for more details on how to
    39  > successfully contribute to an open source project.
    40  
    41  ### Example 1 - Fix a Bug in `govmomi`
    42  
    43  ```bash
    44  git checkout -b issue-<number> main
    45  git add <files>
    46  git commit -m "fix: ..." -m "Closes: #<issue-number>"
    47  git push $USER issue-<number>
    48  ```
    49  
    50  ### Example 2 - Add a new (non-breaking) API to `govmomi`
    51  
    52  ```bash
    53  git checkout -b issue-<number> main
    54  git add <files>
    55  git commit -m "Add API ..." -m "Closes: #<issue-number>"
    56  git push $USER issue-<number>
    57  ```
    58  
    59  ### Example 3 - Add a Feature to `govc`
    60  
    61  ```bash
    62  git checkout -b issue-<number> main
    63  git add <files>
    64  git commit -m "govc: Add feature ..." -m "Closes: #<issue-number>"
    65  git push $USER issue-<number>
    66  ```
    67  **Note**:  
    68  To register the new `govc` command package, add a blank `_` import to `govmomi/govc/main.go`.
    69  
    70  ### Example 4 - Fix a Bug in `vcsim`
    71  
    72  ```bash
    73  git checkout -b issue-<number> main
    74  git add <files>
    75  git commit -m "vcsim: Fix ..." -m "Closes: #<issue-number>"
    76  git push $USER issue-<number>
    77  ```
    78  
    79  ### Example 5 - Document Breaking (API) Changes
    80  
    81  Breaking changes, e.g. to the `govmomi` APIs, are highlighted in the `CHANGELOG`
    82  and release notes when the keyword `BREAKING:` is used in the commit message
    83  body. 
    84  
    85  The text after `BREAKING:` is used in the corresponding highlighted section.
    86  Thus these details should be stated at the body of the commit message.
    87  Multi-line strings are supported.
    88  
    89  ```bash
    90  git checkout -b issue-<number> main
    91  git add <files>
    92  cat << EOF | git commit -F -
    93  Add ctx to funcXYZ
    94  
    95  This commit introduces context.Context to function XYZ
    96  Closes: #1234
    97  
    98  BREAKING: Add ctx to funcXYZ()
    99  EOF
   100  
   101  git push $USER issue-<number>
   102  ```
   103  
   104  ### Stay in sync with Upstream
   105  
   106  When your branch gets out of sync with the main branch, use the
   107  following to update (rebase):
   108  
   109  ```bash
   110  git checkout issue-<number>
   111  git fetch -a
   112  git rebase main
   113  git push --force-with-lease $USER issue-<number>
   114  ```
   115  
   116  ### Updating Pull Requests
   117  
   118  If your PR fails to pass CI or needs changes based on code review, it's ok to
   119  add more commits stating the changes made, e.g. "Address review comments". This
   120  is to assist the reviewer(s) to easily detect and review the recent changes.
   121  
   122  In case of small PRs, it's ok to squash and force-push (see further below)
   123  directly instead.
   124  
   125  ```bash
   126  # incorporate review feedback
   127  git add .
   128  
   129  # create a fixup commit which will be merged into your (original) <commit>
   130  git commit --fixup <commit>
   131  git push $USER issue-<number>
   132  ```
   133  
   134  Be sure to add a comment to the PR indicating your new changes are ready to
   135  review, as Github does not generate a notification when you git push.
   136  
   137  Once the review is complete, squash and push your final commit(s):
   138  
   139  ```bash
   140  # squash all commits into one
   141  # --autosquash will automatically detect and merge fixup commits
   142  git rebase -i --autosquash main
   143  git push --force-with-lease $USER issue-<number>
   144  ```
   145  
   146  ### Code Style
   147  
   148  The coding style suggested by the Go community is used in `govmomi`. See the
   149  [style doc](https://github.com/golang/go/wiki/CodeReviewComments) for details.
   150  
   151  Try to limit column width to 120 characters for both code and markdown documents
   152  such as this one.
   153  
   154  ### Format of the Commit Message
   155  
   156  We follow the conventions described in [How to Write a Git Commit
   157  Message](http://chris.beams.io/posts/git-commit/).
   158  
   159  Be sure to include any related GitHub issue references in the commit message,
   160  e.g. `Closes: #<number>`.
   161  
   162  The [`CHANGELOG.md`](./CHANGELOG.md) and release page uses **commit message
   163  prefixes** for grouping and highlighting. A commit message that
   164  starts with `[prefix:] ` will place this commit under the respective
   165  section in the `CHANGELOG`. 
   166  
   167  The following example creates a commit referencing the `issue: 1234` and puts
   168  the commit message in the `govc` `CHANGELOG` section:
   169  
   170  ```bash
   171  git commit -s -m "govc: Add CLI command X" -m "Closes: #1234"
   172  ```
   173  
   174  Currently the following prefixes are used:
   175  
   176  - `api:` - Use for API-related changes
   177  - `govc:` - Use for changes to `govc` CLI
   178  - `vcsim:` - Use for changes to vCenter Simulator
   179  - `chore:` - Use for repository related activities
   180  - `fix:` - Use for bug fixes
   181  - `docs:` - Use for changes to the documentation
   182  - `examples:` - Use for changes to examples
   183  
   184  If your contribution falls into multiple categories, e.g. `api` and `vcsim` it
   185  is recommended to break up your commits using distinct prefixes.
   186  
   187  ### Running CI Checks and Tests
   188  You can run both `make check` and `make test` from the top level of the
   189  repository. 
   190  
   191  While `make check` will catch formatting and import errors, it will not apply
   192  any fixes. The developer is expected to do that.
   193  
   194  ## Reporting Bugs and Creating Issues
   195  
   196  When opening a new issue, try to roughly follow the commit message format
   197  conventions above.