]> git.openstreetmap.org Git - rails.git/blob - CONTRIBUTING.md
Add table+model to store geoblock zones
[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. [AI Assisted Contributions](#ai-assisted-contributions)
11 5. [Submitting Changes](#submitting-changes)
12 6. [Localization (i18n)](#localization-i18n)
13 7. [Copyright Attribution](#copyright-attribution)
14
15 ## Getting Started
16
17 ### Useful Resources
18
19 * https://www.ruby-lang.org/ - The homepage of Ruby which has more links and some great tutorials.
20 * https://rubyonrails.org/ - The homepage of Rails, also has links and tutorials.
21
22 ### Finding Opportunities to Contribute
23
24 > [!NOTE]
25 > We don't assign issues to individual contributors. You are welcome to work on any issue, and there's no need to ask first.
26 > For more details see [our FAQ](doc/FAQ.md)
27
28 We welcome the community to contribute to this repository in any form:
29
30 - **Documentation:** are the docs clear? Are they correct? Did you come across
31   any issues when trying to follow them? Could something be explained more
32   clearly?
33 - **Bug reporting:** something is broken on the website? Something doesn't work
34   as expected? Create an issue and give as much detail as possible, so that
35   others can understand the context, the conditions in which it happens,
36   and your use case. Or comment on an existing report if one already exists.
37 - **Bug triage:** we receive many issue reports. Can you take one and reproduce
38   it? Can you add more detail that could help others fix the issue more
39   easily? Or perhaps you think it's not really an issue and should be left
40   as is? Come to the issue tracker and let us know your thoughts.
41 - **Feature discussion:** is there a use case that is not covered? Is there
42   something that you wish that the website did, or did differently? Create
43   an issue to discuss it, or comment on an existing issue if it's already
44   being discussed. Try to express your use case in a way that helps understand
45   your needs well, and frames them in the context of the wider community.
46 - **Code reviews:** at any given point, there will be pending PRs, waiting for
47   reviews. Can you take on one, understand what it's trying to do, and
48   provide actionable feedback? Is the code clear, maintainable, and readable?
49   Would you do something differently? Are useful, clear tests provided?
50 - **Code:** take an existing issue and try to fix it, or try to implement
51   an idea.
52 - And probably other ideas not captured here.
53
54 Bear in mind that OSM attracts very diverse contributors with very different
55 needs. Others may have needs different from yours, and reaching a consensus
56 is sometimes difficult.
57
58 If you want to code a feature to this repository, we recommend that you ask
59 for feedback early and often. Create an issue to discuss it, or start with a
60 ["draft" PR](https://github.blog/news-insights/product-news/introducing-draft-pull-requests/)
61 that shows your intention clearly and can be used to provide early
62 feedback. We are not strict on how you communicate, but it's important that
63 you do communicate, early and often, so that you can get feedback quickly.
64 This will help you get buy-in from the maintainers, which will translate into
65 less waste for everyone and a much easier time getting your code merged.
66
67 Bug fixes should be more straighforward than new features, but the same
68 guidance applies. If it turns out to be more complex than initially expected,
69 stop for a moment and seek feedback, be it in an issue or in a draft PR.
70
71 If you are looking for some additional inspiration, you may want to have
72 a look at the [Roadmap](https://github.com/openstreetmap/software-roadmap)
73 that the OSM Foundation published in 2025. This lists items that OSMF
74 would like to focus on, and is not limited to this website. Note that this
75 is not a mandatory list of the contributions that will be accepted. You
76 can choose to ignore it and provide your own contributions. After all,
77 the mission of the OSMF is to support OSM, not to control it.
78
79 ## How to Contribute
80
81 Here's the typical contribution workflow:
82
83 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
84 2. **Fork, Clone & Branch**: Fork the repository, clone it to your local machine, and create a new branch for your work. Avoid working directly on the `master` branch.
85 3. **Set Up**: Follow the [installation guide](doc/INSTALL.md) to set up your development environment
86 4. **Develop**: Make your changes following our [code quality guidelines](#code-quality-guidelines)
87 5. **Test**: Write tests for your changes and ensure all existing tests pass
88 6. **Commit**: Write clear commit messages following our [guidelines](#committing)
89 7. **Submit a Pull Request**: Create a pull request with a clear description of your changes
90   - In fact, we suggest that you publish a draft PR early in the process, so
91     that maintainers can provide feedback and guidance as soon as possible.
92
93 ## Code Quality Guidelines
94
95 ### Coding Style
96
97 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:
98
99 ```bash
100 bundle exec rubocop
101 bundle exec rails eslint
102 bundle exec erb_lint .
103 ```
104
105 You can automatically fix many linting issues with:
106
107 ```bash
108 bundle exec rubocop -a
109 bundle exec rails eslint:fix
110 bundle exec erb_lint . --autocorrect
111 ```
112
113 > [!NOTE]
114 > Use `bundle exec rails eslint:fix` instead of the standard `eslint --fix` option, which is silently ignored in this Rails project.
115
116 > [!TIP]
117 > You can also install hooks to have git run checks automatically when you commit using [overcommit](https://github.com/sds/overcommit) with:
118 >
119 > ```bash
120 > bundle exec overcommit --install
121 > ```
122
123 ### Testing
124
125 > [!IMPORTANT]
126 > 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.
127
128 When contributing, you should:
129
130 * Write new tests to cover the new functionality you've added.
131 * Where appropriate, modify existing tests to reflect new or changed functionality.
132
133 > [!WARNING]
134 > Never comment out or remove a test just because it doesn't pass.
135
136 You can run the existing test suite with:
137
138 ```bash
139 bundle exec rails test:all
140 ```
141
142 You can run javascript tests with:
143
144 ```bash
145 RAILS_ENV=test bundle exec teaspoon
146 ```
147
148 You can view test coverage statistics by browsing the `coverage` directory.
149
150 The tests are automatically run on Pull Requests and other commits via github actions. The results shown are within the PR display on github.
151
152 > [!TIP]
153 > **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/test.local.yml`:
154 >
155 > ```yaml
156 > system_test_firefox_binary: /snap/firefox/current/usr/lib/firefox/firefox
157 > ```
158
159 ### Static Analysis
160
161 We also perform static analysis of our code. You can run the analysis yourself with:
162
163 ```bash
164 bundle exec brakeman -q
165 ```
166
167 ### Comments
168
169 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.
170
171 When contributing, you should:
172
173 * 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.
174 * Check existing comments to ensure that they are not misleading.
175
176 ## AI-Assisted Contributions
177
178 If you choose to use AI tools to help create pull requests, you should follow these additional guidelines:
179
180 * Make sure that a human has reviewed, tested, and fully understands all the code changes being submitted.
181 * If you submit code that you don't understand, then you aren't actually helping anyone. Maintainers already have access to AI tools. If pasting the output into a PR is all that was required, then the maintainers would have done that themselves already.
182 * Issues tagged for new contributors are meant as learning opportunities, not as items that need to be addressed with urgency. Using AI for these issues removes the opportunity to learn, both from you and other contributors.
183 * If you submit a PR and the maintainers suspect that you haven't reviewed, tested, or understood the code, they may decline your PR without further discussion.
184
185 ## Submitting Changes
186
187 ### Committing
188
189 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:
190
191 * Split up large commits into smaller units of functionality.
192 * Keep your commit messages relevant to the changes in each individual commit.
193
194 When writing commit messages please try and stick to the same style as other commits, namely:
195
196 * A one line summary, starting with a capital and with no full stop.
197 * A blank line.
198 * Full description, as proper sentences with capitals and full stops.
199
200 > [!TIP]
201 > 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**".
202
203 For simple commits the one line summary is often enough and the body of the commit message can be left out.
204
205 ### Pull Requests
206
207 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.
208
209 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.
210
211 Please ensure your commit history is clean and 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.
212
213 > [!IMPORTANT]
214 > If you are creating a larger pull request, then please help the maintainers with making the reviews as straightforward as possible:
215 >
216 > * 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.
217 > * 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.
218
219 > [!TIP]
220 > If you are creating a large pull request then please:
221 >
222 > * 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.
223 > * 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.
224
225 ## Localization (i18n)
226
227 > [!IMPORTANT]
228 > 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.
229
230 ## Copyright Attribution
231
232 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).
233
234 > [!IMPORTANT]
235 > If you want to add another attribution, or make changes to the text of an existing attribution, please follow these steps:
236 >
237 > * First, contact the LWG to discuss your proposed changes.
238 > * If the LWG approves, please create a pull request with your proposed changes.
239 > * Finally, please ask the LWG to formally approve the wording used in the pull request (by having an LWG member comment on the PR).
240 >
241 > When we have formal confirmation from LWG, we can go ahead and merge the PR.