]> granicus.if.org Git - icinga2/blob - CONTRIBUTING.md
Merge pull request #6665 from stblassitude/master
[icinga2] / CONTRIBUTING.md
1 # <a id="contributing"></a> Contributing
2
3 Icinga is an open source project and lives from your ideas and contributions.
4
5 There are many ways to contribute, from improving the documentation, submitting
6 bug reports and features requests or writing code to add enhancements or fix bugs.
7
8 #### Table of Contents
9
10 1. [Introduction](#contributing-intro)
11 2. [Fork the Project](#contributing-fork)
12 3. [Branches](#contributing-branches)
13 4. [Commits](#contributing-commits)
14 5. [Pull Requests](#contributing-pull-requests)
15 6. [Testing](#contributing-testing)
16 7. [Source Code Patches](#contributing-patches-source-code)
17 8. [Documentation Patches](#contributing-patches-documentation)
18 9. [Contribute CheckCommand Definitions](#contributing-patches-itl-checkcommands)
19 10. [Review](#contributing-review)
20
21 ## <a id="contributing-intro"></a> Introduction
22
23 Please consider our [roadmap](https://github.com/Icinga/icinga2/milestones) and
24 [open issues](https://github.com/icinga/icinga2/issues) when you start contributing
25 to the project.
26 Issues labeled with [help wanted](https://github.com/Icinga/icinga2/labels/help%20wanted) or
27 [good first issue](https://github.com/Icinga/icinga2/labels/good%20first%20issue) will
28 help you get started more easily.
29
30 Before starting your work on Icinga 2, you should [fork the project](https://help.github.com/articles/fork-a-repo/)
31 to your GitHub account. This allows you to freely experiment with your changes.
32 When your changes are complete, submit a [pull request](https://help.github.com/articles/using-pull-requests/).
33 All pull requests will be reviewed and merged if they suit some general guidelines:
34
35 * Changes are located in a topic branch
36 * For new functionality, proper tests are written
37 * Changes should follow the existing coding style and standards
38
39 Please continue reading in the following sections for a step by step guide.
40
41 ## <a id="contributing-fork"></a> Fork the Project
42
43 [Fork the project](https://help.github.com/articles/fork-a-repo/) to your GitHub account
44 and clone the repository:
45
46 ```
47 git clone git@github.com:dnsmichi/icinga2.git
48 cd icinga2
49 ```
50
51 Add a new remote `upstream` with this repository as value.
52
53 ```
54 git remote add upstream https://github.com/icinga/icinga2.git
55 ```
56
57 You can pull updates to your fork's master branch:
58
59 ```
60 git fetch --all
61 git pull upstream HEAD
62 ```
63
64 Please continue to learn about [branches](CONTRIBUTING.md#contributing-branches).
65
66 ## <a id="contributing-branches"></a> Branches
67
68 Choosing a proper name for a branch helps us identify its purpose and possibly
69 find an associated bug or feature.
70 Generally a branch name should include a topic such as `bugfix` or `feature` followed
71 by a description and an issue number if applicable. Branches should have only changes
72 relevant to a specific issue.
73
74 ```
75 git checkout -b bugfix/service-template-typo-1234
76 git checkout -b feature/config-handling-1235
77 ```
78
79 Continue to apply your changes and test them. More details on specific changes:
80
81 * [Source Code Patches](#contributing-patches-source-code)
82 * [Documentation Patches](#contributing-patches-documentation)
83 * [Contribute CheckCommand Definitions](#contributing-patches-itl-checkcommands)
84
85 ## <a id="contributing-commits"></a> Commits
86
87 Once you've finished your work in a branch, please ensure to commit
88 your changes. A good commit message includes a short topic, additional body
89 and a reference to the issue you wish to solve (if existing).
90
91 Fixes:
92
93 ```
94 Fix problem with notifications in HA cluster
95
96 There was a race condition when restarting.
97
98 refs #4567
99 ```
100
101 Features:
102
103 ```
104 Add ITL CheckCommand printer
105
106 Requires the check_printer plugin.
107
108 refs #1234
109 ```
110
111 You can add multiple commits during your journey to finish your patch.
112 Don't worry, you can squash those changes into a single commit later on.
113
114 ## <a id="contributing-pull-requests"></a> Pull Requests
115
116 Once you've commited your changes, please update your local master
117 branch and rebase your bugfix/feature branch against it before submitting a PR.
118
119 ```
120 git checkout master
121 git pull upstream HEAD
122
123 git checkout bugfix/notifications
124 git rebase master
125 ```
126
127 Once you've resolved any conflicts, push the branch to your remote repository.
128 It might be necessary to force push after rebasing - use with care!
129
130 New branch:
131 ```
132 git push --set-upstream origin bugfix/notifications
133 ```
134
135 Existing branch:
136 ```
137 git push -f origin bugfix/notifications
138 ```
139
140 You can now either use the [hub](https://hub.github.com) CLI tool to create a PR, or nagivate
141 to your GitHub repository and create a PR there.
142
143 The pull request should again contain a telling subject and a reference
144 with `fixes` to an existing issue id if any. That allows developers
145 to automatically resolve the issues once your PR gets merged.
146
147 ```
148 hub pull-request
149
150 <a telling subject>
151
152 fixes #1234
153 ```
154
155 Thanks a lot for your contribution!
156
157
158 ### <a id="contributing-rebase"></a> Rebase a Branch
159
160 If you accidentally sent in a PR which was not rebased against the upstream master,
161 developers might ask you to rebase your PR.
162
163 First off, fetch and pull `upstream` master.
164
165 ```
166 git checkout master
167 git fetch --all
168 git pull upstream HEAD
169 ```
170
171 Then change to your working branch and start rebasing it against master:
172
173 ```
174 git checkout bugfix/notifications
175 git rebase master
176 ```
177
178 If you are running into a conflict, rebase will stop and ask you to fix the problems.
179
180 ```
181 git status
182
183   both modified: path/to/conflict.cpp
184 ```
185
186 Edit the file and search for `>>>`. Fix, build, test and save as needed.
187
188 Add the modified file(s) and continue rebasing.
189
190 ```
191 git add path/to/conflict.cpp
192 git rebase --continue
193 ```
194
195 Once succeeded ensure to push your changed history remotely.
196
197 ```
198 git push -f origin bugfix/notifications
199 ```
200
201
202 If you fear to break things, do the rebase in a backup branch first and later replace your current branch.
203
204 ```
205 git checkout bugfix/notifications
206 git checkout -b bugfix/notifications-rebase
207
208 git rebase master
209
210 git branch -D bugfix/notifications
211 git checkout -b bugfix/notifications
212
213 git push -f origin bugfix/notifications
214 ```
215
216 ### <a id="contributing-squash"></a> Squash Commits
217
218 > **Note:**
219 >
220 > Be careful with squashing. This might lead to non-recoverable mistakes.
221 >
222 > This is for advanced Git users.
223
224 Say you want to squash the last 3 commits in your branch into a single one.
225
226 Start an interactive (`-i`)  rebase from current HEAD minus three commits (`HEAD~3`).
227
228 ```
229 git rebase -i HEAD~3
230 ```
231
232 Git opens your preferred editor. `pick` the commit in the first line, change `pick` to `squash` on the other lines.
233
234 ```
235 pick e4bf04e47 Fix notifications
236 squash d7b939d99 Tests
237 squash b37fd5377 Doc updates
238 ```
239
240 Save and let rebase to its job. Then force push the changes to the remote origin.
241
242 ```
243 git push -f origin bugfix/notifications
244 ```
245
246
247 ## <a id="contributing-testing"></a> Testing
248
249 Basic unit test coverage is provided by running `make test` during package builds.
250 Read the [INSTALL.md](INSTALL.md) file for more information about development builds.
251
252 Snapshot packages from the latest development branch are available inside the
253 [package repository](https://packages.icinga.com).
254
255 You can help test-drive the latest Icinga 2 snapshot packages inside the
256 [Icinga 2 Vagrant boxes](https://github.com/icinga/icinga-vagrant).
257
258
259 ## <a id="contributing-patches-source-code"></a> Source Code Patches
260
261 Icinga 2 is written in C++ and uses the Boost libraries. We are also using the C++11 standard where applicable (please
262 note the minimum required compiler versions in the [INSTALL.md](INSTALL.md) file.
263
264 Icinga 2 can be built on Linux/Unix nodes and Windows clients. In order to develop patches for Icinga 2,
265 you should prepare your own local build environment and know how to work with C++.
266
267 More tips:
268
269 * Requirements and source code installation for Linux/Unix is explained inside the [INSTALL.md](INSTALL.md) file.
270 * Debug requirements and GDB instructions can be found in the [documentation](https://github.com/Icinga/icinga2/blob/master/doc/20-development.md).
271 * If you are planning to develop and debug the Windows client, setup a Windows environment with [Visual Studio](https://www.visualstudio.com/vs/community/). An example can be found in [this blogpost](https://blog.netways.de/2015/08/24/developing-icinga-2-on-windows-10-using-visual-studio-2015/).
272
273 ## <a id="contributing-patches-documentation"></a> Documentation Patches
274
275 The documentation is written in GitHub flavored [Markdown](https://guides.github.com/features/mastering-markdown/).
276 It is located in the `doc/` directory and can be edited with your preferred editor. You can also
277 edit it online on GitHub.
278
279 ```
280 vim doc/2-getting-started.md
281 ```
282
283 In order to review and test changes, you can install the [mkdocs](http://www.mkdocs.org) Python library.
284
285 ```
286 pip install mkdocs
287 ```
288
289 This allows you to start a local mkdocs viewer instance on http://localhost:8000
290
291 ```
292 mkdocs serve
293 ```
294
295 Changes on the chapter layout can be done inside the `mkdocs.yml` file in the main tree.
296
297 There also is a script to ensure that relative URLs to other sections are updated. This script
298 also checks for broken URLs.
299
300 ```
301 ./doc/update-links.py doc/*.md
302 ```
303
304 ## <a id="contributing-patches-itl-checkcommands"></a> Contribute CheckCommand Definitions
305
306 The Icinga Template Library (ITL) and its plugin check commands provide a variety of CheckCommand
307 object definitions which can be included on-demand.
308
309 Advantages of sending them upstream:
310
311 * Everyone can use and update/fix them.
312 * One single place for configuration and documentation.
313 * Developers may suggest updates and help with best practices.
314 * You don't need to care about copying the command definitions to your satellites and clients.
315
316 #### <a id="contributing-itl-checkcommands-start"></a> Where do I start?
317
318 Get to know the check plugin and its options. Read the general documentation on how to integrate
319 your check plugins and how to create a good CheckCommand definition.
320
321 A good command definition uses:
322
323 * Command arguments including `value`, `description`, optional: `set_if`, `required`, etc.
324 * Comments `/* ... */` to describe difficult parts.
325 * Command name as prefix for the custom attributes referenced (e.g. `disk_`)
326 * Default values
327         * If `host.address` is involved, set a custom attribute (e.g. `ping_address`) to the default `$address$`. This allows users to override the host's address later on by setting the custom attribute inside the service apply definitions.
328         * If the plugin is also capable to use ipv6, import the `ipv4-or-ipv6` template and use `$check_address$` instead of `$address$`. This allows to fall back to ipv6 if only this address is set.
329         * If `set_if` is involved, ensure to specify a sane default value if required.
330 * Templates if there are multiple plugins with the same basic behaviour (e.g. ping4 and ping6).
331 * Your love and enthusiasm in making it the perfect CheckCommand.
332
333 #### <a id="contributing-itl-checkcommands-overview"></a> I have created a CheckCommand, what now?
334
335 Icinga 2 developers love documentation. This isn't just because we want to annoy anyone sending a patch,
336 it's a matter of making your contribution visible to the community.
337
338 Your patch should consist of 2 parts:
339
340 * The CheckCommand definition.
341 * The documentation bits.
342
343 [Fork the repository](https://help.github.com/articles/fork-a-repo/) and ensure that the master branch is up-to-date.
344
345 Create a new fix or feature branch and start your work.
346
347 ```
348 git checkout -b feature/itl-check-printer
349 ```
350
351 #### <a id="contributing-itl-checkcommands-add"></a> Add CheckCommand Definition to Contrib Plugins
352
353 There already exists a defined structure for contributed plugins. Navigate to `itl/plugins-contrib.d`
354 and verify where your command definitions fits into.
355
356 ```
357 cd itl/plugins-contrib.d/
358 ls
359 ```
360
361 If you want to add or modify an existing Monitoring Plugin please use `itl/command-plugins.conf` instead.
362
363 ```
364 vim itl/command-plugins-conf
365 ```
366
367 ##### Existing Configuration File
368
369 Just edit it, and add your CheckCommand definition.
370
371 ```
372 vim operating-system.conf
373 ```
374
375 Proceed to the documentation.
376
377 ##### New type for CheckCommand Definition
378
379 Create a new file with .conf suffix.
380
381 ```
382         $ vim printer.conf
383 ```
384
385 Add the file to `itl/CMakeLists.txt` in the FILES line in **alpha-numeric order**.
386 This ensures that the installation and packages properly include your newly created file.
387
388 ```
389 vim CMakeLists.txt
390
391 -FILES ipmi.conf network-components.conf operating-system.conf virtualization.conf vmware.conf
392 +FILES ipmi.conf network-components.conf operating-system.conf printer.conf virtualization.conf vmware.conf
393 ```
394
395 Add the newly created file to your git commit.
396
397 ```
398 git add printer.conf
399 ```
400
401 Do not commit it yet but finish with the documentation.
402
403 #### <a id="contributing-itl-checkcommands-docs"></a> Create CheckCommand Documentation
404
405 Edit the documentation file in the `doc/` directory. More details on documentation
406 updates can be found [here](CONTRIBUTING.md#contributing-documentation).
407
408 ```
409 vim doc/10-icinga-template-library.md
410 ```
411
412 The CheckCommand documentation should be located in the same chapter
413 similar to the configuration file you have just added/modified.
414
415 Create a section for your plugin, add a description and a table of parameters. Each parameter should have at least:
416
417 * optional or required
418 * description of its purpose
419 * the default value, if any
420
421 Look at the existing documentation and "copy" the same style and layout.
422
423
424 #### <a id="contributing-itl-checkcommands-patch"></a> Send a Patch
425
426 Commit your changes which includes a descriptive commit message.
427
428 ```
429 git commit -av
430 Add printer CheckCommand definition
431
432 Explain its purpose and possible enhancements/shortcomings.
433
434 refs #existingticketnumberifany
435 ```
436 Push the branch to the remote origin and create a [pull request](https://help.github.com/articles/using-pull-requests/).
437
438 ```
439 git push --set-upstream origin feature/itl-check-printer
440 hub pull-request
441 ```
442
443 In case developers ask for changes during review, please add them
444 to the branch and push those changes.
445
446 ## <a id="contributing-review"></a> Review
447
448 ### <a id="contributing-pr-review"></a> Pull Request Review
449
450 This is only important for developers who will review pull requests. If you want to join
451 the development team, kindly contact us.
452
453 - Ensure that the style guide applies.
454 - Verify that the patch fixes a problem or linked issue, if any.
455 - Discuss new features with team members.
456 - Test the patch in your local dev environment.
457
458 If there are changes required, kindly ask for an updated patch.
459
460 Once the review is completed, merge the PR via GitHub.
461
462 #### <a id="contributing-pr-review-fixes"></a> Pull Request Review Fixes
463
464 In order to amend the commit message, fix conflicts or add missing changes, you can
465 add your changes to the PR.
466
467 A PR is just a pointer to a different Git repository and branch.
468 By default, pull requests allow to push into the repository of the PR creator.
469
470 Example for [#4956](https://github.com/Icinga/icinga2/pull/4956):
471
472 At the bottom it says "Add more commits by pushing to the bugfix/persistent-comments-are-not-persistent branch on TheFlyingCorpse/icinga2."
473
474 First off, add the remote repository as additional origin and fetch its content:
475
476 ```
477 git remote add theflyingcorpse https://github.com/TheFlyingCorpse/icinga2
478 git fetch --all
479 ```
480
481 Checkout the mentioned remote branch into a local branch (Note: `theflyingcorpse` is the name of the remote):
482
483 ```
484 git checkout theflyingcorpse/bugfix/persistent-comments-are-not-persistent -b bugfix/persistent-comments-are-not-persistent
485 ```
486
487 Rebase, amend, squash or add your own commits on top.
488
489 Once you are satisfied, push the changes to the remote `theflyingcorpse` and its branch `bugfix/persistent-comments-are-not-persistent`.
490 The syntax here is `git push <remote> <localbranch>:<remotebranch>`.
491
492 ```
493 git push theflyingcorpse bugfix/persistent-comments-are-not-persistent:bugfix/persistent-comments-are-not-persistent
494 ```
495
496 In case you've changed the commit history (rebase, amend, squash), you'll need to force push. Be careful, this can't be reverted!
497
498 ```
499 git push -f theflyingcorpse bugfix/persistent-comments-are-not-persistent:bugfix/persistent-comments-are-not-persistent
500 ```