|
| 1 | +--- |
| 2 | +title: Write Code for CosmoScout VR |
| 3 | +description: Some guidelines for contributing to CosmoScout VR |
| 4 | +--- |
| 5 | + |
| 6 | +Whenever you encounter a 🪲 **bug** or have 🎉 **feature request**, |
| 7 | +report this via [Github issues](https://github.com/cosmoscout/cosmoscout-vr/issues). |
| 8 | + |
| 9 | +We are happy to receive contributions to CosmoScout VR in the form of **pull requests** via Github. |
| 10 | +Feel free to fork the repository, implement your changes and create a merge request to the `main` branch. |
| 11 | +There is a [forking guide](#forking-cosmoscout-vr) available to get you started! |
| 12 | + |
| 13 | +## Branching Guidelines |
| 14 | + |
| 15 | +New features and bug fixes are implemented in `feature/*` branches and are merged to `main` once they are finished. |
| 16 | +When a milestone is reached, a new tag is created. |
| 17 | + |
| 18 | +:::tip |
| 19 | +[Github Actions](https://github.com/cosmoscout/cosmoscout-vr/actions) are used for continuous integration. |
| 20 | +All pull requests and pushes to `main` are built automatically. |
| 21 | +If you want to test a specific commit on any other branch, add **`[run-ci]`** to your commit message. |
| 22 | +::: |
| 23 | + |
| 24 | +## Coding Guidelines |
| 25 | + |
| 26 | +* Each header file should contain an include guard. For CosmoScout VR classes the naming scheme should be `CS_{NAMESPACE}_{FILNAME}_HPP` and for plugins it should be `CSP_{PLUGIN}_{FILNAME}_HPP`. |
| 27 | +* Class names should be written in CamelCase (e.g. `MyClass`). |
| 28 | +* Class methods should be written in small camelCase (e.g. `doSomething()`). |
| 29 | +* Class members should start with a small `m` and continue in CamelCase (e.g. `mMyClassMember`). |
| 30 | +* Apply clang-format before you create a merge request (either setup your IDE to do this or use the `clang-format.sh` script) |
| 31 | +* Never use `using namespace`. |
| 32 | +* Use features of modern C++11 / C++14 / C++17 (e.g. range-based for-loops, std::optional, std::variant, ...)! |
| 33 | + |
| 34 | +### Git Commit Messages |
| 35 | + |
| 36 | +Commits should start with a Capital letter and should be written in present tense (e.g. __:tada: Add cool new feature__ instead of __:tada: Added cool new feature__). |
| 37 | +It's a great idea to start the commit message with an applicable emoji. This does not only look great but also makes you rethink what to add to a commit. |
| 38 | +* 🎉 `:tada:` when when adding a cool new feature |
| 39 | +* 🔧 `:wrench:` when refactoring / improving a small piece of code |
| 40 | +* 🔨 `:hammer:` when refactoring / improving large parts of the code |
| 41 | +* ✨ `:sparkles:` when applying clang-format |
| 42 | +* 🎨 `:art:` improving / adding assets like textures or 3D-models |
| 43 | +* 🚀 `:rocket:` when improving performance |
| 44 | +* 📝 `:memo:` when writing docs |
| 45 | +* 🪲 `:beetle:` when fixing a bug |
| 46 | +* 💚 `:green_heart:` when fixing the CI build |
| 47 | +* ✔️ `:heavy_check_mark:` when working on tests |
| 48 | +* 🔼 `:arrow_up_small:` when adding / upgrading dependencies |
| 49 | +* 🔽 `:arrow_down_small:` when removing / downgrading dependencies |
| 50 | +* 🔀 `:twisted_rightwards_arrows:` when merging branches |
| 51 | +* 🔥 `:fire:` when removing files |
| 52 | +* 🚚 `:truck:` when moving / renaming files or namespaces |
| 53 | + |
| 54 | +:::tip |
| 55 | +A good way to enforce this on your side is to use a `commit-hook`. To do this, paste the following script into `.git/hooks/commit-msg`. |
| 56 | + |
| 57 | +```bash title=".git/hooks/commit-msg" |
| 58 | +#!/bin/bash |
| 59 | + |
| 60 | +# regex to validate in commit msg |
| 61 | +commit_regex='(:(tada|wrench|hammer|sparkles|art|rocket|memo|beetle|green_heart|arrow_up_small|arrow_down_small|twisted_rightwards_arrows|fire|truck|heavy_check_mark):(.+))' |
| 62 | +error_msg="Aborting commit. Your commit message is missing an emoji as described in CONTRIBUTING.md" |
| 63 | + |
| 64 | +if ! grep -xqE "$commit_regex" "$1"; then |
| 65 | + echo "$error_msg" >&2 |
| 66 | + exit 1 |
| 67 | +fi |
| 68 | +``` |
| 69 | + |
| 70 | +And make sure that it is executable: |
| 71 | + |
| 72 | +``` bash |
| 73 | +chmod +x .git/hooks/commit-msg |
| 74 | +``` |
| 75 | +::: |
| 76 | + |
| 77 | +# Forking CosmoScout VR |
| 78 | + |
| 79 | +This is pretty straight-forward. Just click the **Fork** button on the top right of this page. Then clone the forked repository, perform your changes, push to a feature branch and create a pull request to CosmoScout's `main` branch. |
| 80 | + |
| 81 | +``` bash |
| 82 | +git clone [email protected]: <your user name >/cosmoscout-vr.git |
| 83 | +cd cosmoscout-vr |
| 84 | +git remote add upstream [email protected]:cosmoscout/cosmoscout-vr.git |
| 85 | +git checkout main |
| 86 | +git submodule update --init --recursive |
| 87 | +git checkout -b feature/your-new-feature |
| 88 | + |
| 89 | +# ... do and commit your changes! |
| 90 | + |
| 91 | +git push origin feature/your-new-feature |
| 92 | +``` |
| 93 | + |
| 94 | +When there were changes in CosmoScout's `main` branch, you will need to merge those to your fork before creating a pull request: |
| 95 | + |
| 96 | +``` bash |
| 97 | +git fetch upstream |
| 98 | +git merge upstream/main |
| 99 | +``` |
| 100 | + |
| 101 | +Then you can create a pull request on GitHub to CosmoScout's `main` branch. |
| 102 | + |
| 103 | +## Creating a new plugin |
| 104 | + |
| 105 | +From a git-perspective, this is pretty straight-forward. |
| 106 | +All you need to do is creating a new directory in `plugins/`. |
| 107 | +For the beginning, you can copy the contents of another similar plugin to that directory. |
| 108 | +It will be picked up automatically by the build system. |
| 109 | + |
| 110 | +:::tip |
| 111 | +The new directory will also be ignored by git (due to the toplevel `.gitignore` file). |
| 112 | +That means that you can use a git repository for your plugin. |
| 113 | +::: |
0 commit comments