]> git.openstreetmap.org Git - rails.git/blob - CONTRIBUTING.md
Fix next page boundary condition for user notes
[rails.git] / CONTRIBUTING.md
1 # Contributing
2
3 This guide covers our development workflow, coding standards, and how to get your changes merged.
4
5 ## Table of Contents
6
7 1. [Getting Started](#getting-started)
8 2. [How to Contribute](#how-to-contribute)
9 3. [Code Quality Guidelines](#code-quality-guidelines)
10 4. [Submitting Changes](#submitting-changes)
11 5. [Localization (i18n)](#localization-i18n)
12 6. [Copyright Attribution](#copyright-attribution)
13
14 ## Getting Started
15
16 ### Useful Resources
17
18 * https://www.ruby-lang.org/ - The homepage of Ruby which has more links and some great tutorials.
19 * https://rubyonrails.org/ - The homepage of Rails, also has links and tutorials.
20
21 ### Finding Issues to Work On
22
23 > [!NOTE]
24 > We don't assign issues to individual contributors. You are welcome to work on any issue, and there's no need to ask first.
25
26 For more details see [our FAQ](FAQ.md)
27
28 ## How to Contribute
29
30 Here's the typical contribution workflow:
31
32 1. **Find an Issue**: Browse our [issues](https://github.com/openstreetmap/openstreetmap-website/issues) or identify a bug/feature you'd like to work on
33 2. **Fork & Clone**: Fork the repository and clone it to your local machine
34 3. **Set Up**: Follow the [installation guide](INSTALL.md) to set up your development environment
35 4. **Develop**: Make your changes following our [code quality guidelines](#code-quality-guidelines)
36 5. **Test**: Write tests for your changes and ensure all existing tests pass
37 6. **Commit**: Write clear commit messages following our [guidelines](#committing)
38 7. **Submit a Pull Request**: Create a pull request with a clear description of your changes
39
40 ## Code Quality Guidelines
41
42 ### Coding Style
43
44 We use [Rubocop](https://github.com/rubocop-hq/rubocop) (for ruby files), [ESLint](https://eslint.org/) (for javascript files), and [ERB Lint](https://github.com/Shopify/erb-lint) (for erb templates) to help maintain consistency in our code. You can run these utilities during development to check that your code matches our guidelines:
45
46 ```bash
47 bundle exec rubocop
48 bundle exec rails eslint
49 bundle exec erb_lint .
50 ```
51
52 You can automatically fix many linting issues with:
53
54 ```bash
55 bundle exec rubocop -a
56 bundle exec rails eslint:fix
57 bundle exec erb_lint . --autocorrect
58 ```
59
60 > [!NOTE]
61 > Use `bundle exec rails eslint:fix` instead of the standard `eslint --fix` option, which is silently ignored in this Rails project.
62
63 > [!TIP]
64 > You can also install hooks to have git run checks automatically when you commit using [overcommit](https://github.com/sds/overcommit) with:
65
66 > ```bash
67 > bundle exec overcommit --install
68 > ```
69
70 ### Testing
71
72 > [!IMPORTANT]
73 > Having a good suite of tests is very important to the stability and maintainability of any code base. The tests in the `openstreetmap-website` code are by no means complete, but they are extensive, and must continue to be so with any new functionality which is written. Tests are also useful in giving others confidence in the code you've written, and can greatly speed up the process of merging in new code.
74
75 When contributing, you should:
76
77 * Write new tests to cover the new functionality you've added.
78 * Where appropriate, modify existing tests to reflect new or changed functionality.
79
80 > [!WARNING]
81 > Never comment out or remove a test just because it doesn't pass.
82
83 You can run the existing test suite with:
84
85 ```bash
86 bundle exec rails test:all
87 ```
88
89 You can run javascript tests with:
90
91 ```bash
92 RAILS_ENV=test bundle exec teaspoon
93 ```
94
95 You can view test coverage statistics by browsing the `coverage` directory.
96
97 The tests are automatically run on Pull Requests and other commits via github actions. The results shown are within the PR display on github.
98
99 > [!TIP]
100 > **System tests** use Selenium with Firefox for browser automation. On Ubuntu 24.04, if Firefox is installed via snap, you may need to override the Firefox binary path in `config/settings.local.yml`:
101
102 > ```yaml
103 > system_test_firefox_binary: /snap/firefox/current/usr/lib/firefox/firefox
104 > ```
105
106 ### Static Analysis
107
108 We also perform static analysis of our code. You can run the analysis yourself with:
109
110 ```bash
111 bundle exec brakeman -q
112 ```
113
114 ### Comments
115
116 Sometimes it's not apparent from the code itself what it does, or, more importantly, **why** it does that. Good comments help your fellow developers to read the code and satisfy themselves that it's doing the right thing.
117
118 When contributing, you should:
119
120 * Comment your code where necessary - explain the bits which might be difficult to understand what the code does, why it does it and why it should be the way it is.
121 * Check existing comments to ensure that they are not misleading.
122
123 ## Submitting Changes
124
125 ### Committing
126
127 When you submit your changes, the project maintainers have to read them and understand them. This is difficult enough at the best of times, and misunderstanding commits can lead to them being more difficult to merge. To help with this, when committing you should:
128
129 * Split up large commits into smaller units of functionality.
130 * Keep your commit messages relevant to the changes in each individual commit.
131
132 When writing commit messages please try and stick to the same style as other commits, namely:
133
134 * A one line summary, starting with a capital and with no full stop.
135 * A blank line.
136 * Full description, as proper sentences with capitals and full stops.
137
138 > [!TIP]
139 > Use the imperative verb form in your summary line (e.g., "Add feature" not "Added feature"). A good test is whether your summary line completes the sentence "This commit will...". For example: "This commit will **Fix user login validation**" or "This commit will **Update README installation steps**".
140
141 For simple commits the one line summary is often enough and the body of the commit message can be left out.
142
143 ### Pull Requests
144
145 If you have forked on GitHub then the best way to submit your patches is to push your changes back to GitHub and open a Pull Request on GitHub.
146
147 If your pull request is small, for example one or two commits each containing only a few lines of code, then it is easy for the maintainers to review.
148
149 > [!IMPORTANT]
150 > If you are creating a larger pull request, then please help the maintainers with making the reviews as straightforward as possible:
151
152 > * The smaller the PR, the easier it is to review. In particular if a PR is too large to review in one sitting, or if changes are requested, then the maintainer needs to repeatedly re-read code that has already been considered.
153 > * The commit history is important. This is a large codebase, developed over many years by many developers. We frequently need to read the commit history (for example using `git blame`) to figure out what is going on. So small, understandable, and relevant commits are important for other developers looking back at your work in future.
154
155 > [!TIP]
156 > If you are creating a large pull request then please:
157
158 > * Consider splitting your pull request into multiple PRs. If part of your work can be considered standalone, or is a foundation for the rest of your work, please submit it separately first.
159 > * Avoid including "fixup" commits. If you have added a fixup commit (for example to fix a rubocop warning, or because you changed your own new code) please combine the fixup commit into the commit that introduced the problem. `git rebase -i` is very useful for this.
160 > * Avoid including "merge" commits. If your PR can no longer be merged cleanly (for example, an unrelated change to Gemfile.lock on master now conflicts with your PR) then please rebase your PR onto the latest master. This allows you to fix the conflicts, while keeping the PR a straightforward list of commits. If there are no conflicts, then there is no need to rebase anything.
161
162 ## Localization (i18n)
163
164 > [!IMPORTANT]
165 > If you make a change that involves the locale files (in `config/locales`) then please only submit changes to the `en.yml` file. The other files are updated via [Translatewiki](https://translatewiki.net/wiki/Translating:OpenStreetMap) and should not be included in your pull request.
166
167 ## Copyright Attribution
168
169 The list of attributions on the /copyright page is managed by the [OSMF Licensing Working Group (LWG)](https://wiki.osmfoundation.org/wiki/Licensing_Working_Group).
170
171 > [!IMPORTANT]
172 > If you want to add another attribution, or make changes to the text of an existing attribution, please follow these steps:
173
174 > * First, contact the LWG to discuss your proposed changes.
175 > * If the LWG approves, please create a pull request with your proposed changes.
176 > * Finally, please ask the LWG to formally approve the wording used in the pull request (by having an LWG member comment on the PR).
177
178 > When we have formal confirmation from LWG, we can go ahead and merge the PR.