You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

364 lines
18 KiB

  1. # Contribution Guidelines
  2. ## Table of Contents
  3. - [Contribution Guidelines](#contribution-guidelines)
  4. - [Introduction](#introduction)
  5. - [Bug reports](#bug-reports)
  6. - [Discuss your design](#discuss-your-design)
  7. - [Testing redux](#testing-redux)
  8. - [Vendoring](#vendoring)
  9. - [Translation](#translation)
  10. - [Code review](#code-review)
  11. - [Styleguide](#styleguide)
  12. - [Design guideline](#design-guideline)
  13. - [API v1](#api-v1)
  14. - [Developer Certificate of Origin (DCO)](#developer-certificate-of-origin-dco)
  15. - [Release Cycle](#release-cycle)
  16. - [Maintainers](#maintainers)
  17. - [Owners](#owners)
  18. - [Versions](#versions)
  19. - [Releasing Gitea](#releasing-gitea)
  20. - [Copyright](#copyright)
  21. ## Introduction
  22. This document explains how to contribute changes to the Gitea project.
  23. It assumes you have followed the
  24. [installation instructions](https://docs.gitea.io/en-us/).
  25. Sensitive security-related issues should be reported to
  26. [security@gitea.io](mailto:security@gitea.io).
  27. For configuring IDE or code editor to develop Gitea see [IDE and code editor configuration](contrib/ide/)
  28. ## Bug reports
  29. Please search the issues on the issue tracker with a variety of keywords
  30. to ensure your bug is not already reported.
  31. If unique, [open an issue](https://github.com/go-gitea/gitea/issues/new)
  32. and answer the questions so we can understand and reproduce the
  33. problematic behavior.
  34. To show us that the issue you are having is in Gitea itself, please
  35. write clear, concise instructions so we can reproduce the behavior—
  36. even if it seems obvious. The more detailed and specific you are,
  37. the faster we can fix the issue. Check out [How to Report Bugs
  38. Effectively](http://www.chiark.greenend.org.uk/~sgtatham/bugs.html).
  39. Please be kind, remember that Gitea comes at no cost to you, and you're
  40. getting free help.
  41. ## Discuss your design
  42. The project welcomes submissions. If you want to change or add something,
  43. please let everyone know what you're working on—[file an issue](https://github.com/go-gitea/gitea/issues/new)!
  44. Significant changes must go through the change proposal process
  45. before they can be accepted. To create a proposal, file an issue with
  46. your proposed changes documented, and make sure to note in the title
  47. of the issue that it is a proposal.
  48. This process gives everyone a chance to validate the design, helps
  49. prevent duplication of effort, and ensures that the idea fits inside
  50. the goals for the project and tools. It also checks that the design is
  51. sound before code is written; the code review tool is not the place for
  52. high-level discussions.
  53. ## Testing redux
  54. Before submitting a pull request, run all the tests for the whole tree
  55. to make sure your changes don't cause regression elsewhere.
  56. Here's how to run the test suite:
  57. - Install the correct version of the drone-cli package. As of this
  58. writing, the correct drone-cli version is
  59. [1.2.0](https://docs.drone.io/cli/install/).
  60. - Ensure you have enough free disk space. You will need at least
  61. 15-20 Gb of free disk space to hold all of the containers drone
  62. creates (a default AWS or GCE disk size won't work -- see
  63. [#6243](https://github.com/go-gitea/gitea/issues/6243)).
  64. - Change into the base directory of your copy of the gitea repository,
  65. and run `drone exec --event pull_request`.
  66. - At the moment `drone exec` doesn't support the Docker Toolbox on Windows 10
  67. (see [drone-cli#135](https://github.com/drone/drone-cli/issues/135))
  68. The drone version, command line, and disk requirements do change over
  69. time (see [#4053](https://github.com/go-gitea/gitea/issues/4053) and
  70. [#6243](https://github.com/go-gitea/gitea/issues/6243)); if you
  71. discover any issues, please feel free to send us a pull request to
  72. update these instructions.
  73. ## Vendoring
  74. We keep a cached copy of dependencies within the `vendor/` directory,
  75. managing updates via [Modules](https://golang.org/cmd/go/#hdr-Module_maintenance).
  76. Pull requests should only include `vendor/` updates if they are part of
  77. the same change, be it a bugfix or a feature addition.
  78. The `vendor/` update needs to be justified as part of the PR description,
  79. and must be verified by the reviewers and/or merger to always reference
  80. an existing upstream commit.
  81. You can find more information on how to get started with it on the [Modules Wiki](https://github.com/golang/go/wiki/Modules).
  82. ## Translation
  83. We do all translation work inside [Crowdin](https://crowdin.com/project/gitea).
  84. The only translation that is maintained in this git repository is
  85. [`en_US.ini`](https://github.com/go-gitea/gitea/blob/master/options/locale/locale_en-US.ini)
  86. and is synced regularly to Crowdin. Once a translation has reached
  87. A SATISFACTORY PERCENTAGE it will be synced back into this repo and
  88. included in the next released version.
  89. ## Building Gitea
  90. Generally, the go build tools are installed as-needed in the `Makefile`.
  91. An exception are the tools to build the CSS, JS and images.
  92. - To build CSS and JS: Install [Node.js](https://nodejs.org/en/download/package-manager) at version 10.0 or above
  93. with `npm` and then run `npm install`, `make css` and `make js`.
  94. - To build Images: ImageMagick, inkscape and zopflipng binaries must be
  95. available in your `PATH` to run `make generate-images`.
  96. For more details on how to generate files, build and test Gitea, see the [hacking instructions](https://docs.gitea.io/en-us/hacking-on-gitea/)
  97. ## Code review
  98. Changes to Gitea must be reviewed before they are accepted—no matter who
  99. makes the change, even if they are an owner or a maintainer. We use GitHub's
  100. pull request workflow to do that. And, we also use [LGTM](http://lgtm.co)
  101. to ensure every PR is reviewed by at least 2 maintainers.
  102. Please try to make your pull request easy to review for us. And, please read
  103. the *[How to get faster PR reviews](https://github.com/kubernetes/community/blob/261cb0fd089b64002c91e8eddceebf032462ccd6/contributors/guide/pull-requests.md#best-practices-for-faster-reviews)* guide;
  104. it has lots of useful tips for any project you may want to contribute.
  105. Some of the key points:
  106. * Make small pull requests. The smaller, the faster to review and the
  107. more likely it will be merged soon.
  108. * Don't make changes unrelated to your PR. Maybe there are typos on
  109. some comments, maybe refactoring would be welcome on a function... but
  110. if that is not related to your PR, please make *another* PR for that.
  111. * Split big pull requests into multiple small ones. An incremental change
  112. will be faster to review than a huge PR.
  113. ## Styleguide
  114. For imports you should use the following format (_without_ the comments)
  115. ```go
  116. import (
  117. // stdlib
  118. "encoding/json"
  119. "fmt"
  120. // local packages
  121. "code.gitea.io/gitea/models"
  122. "code.gitea.io/sdk/gitea"
  123. // external packages
  124. "github.com/foo/bar"
  125. "gopkg.io/baz.v1"
  126. )
  127. ```
  128. ## Design guideline
  129. To maintain understandable code and avoid circular dependencies it is important to have a good structure of the code. The gitea code is divided into the following parts:
  130. - **integration:** Integrations tests
  131. - **models:** Contains the data structures used by xorm to construct database tables. It also contains supporting functions to query and update the database. Dependecies to other code in Gitea should be avoided although some modules might be needed (for example for logging).
  132. - **models/fixtures:** Sample model data used in integration tests.
  133. - **models/migrations:** Handling of database migrations between versions. PRs that changes a database structure shall also have a migration step.
  134. - **modules:** Different modules to handle specific functionality in Gitea.
  135. - **public:** Frontend files (javascript, images, css, etc.)
  136. - **routers:** Handling of server requests. As it uses other Gitea packages to serve the request, other packages (models, modules or services) shall not depend on routers
  137. - **services:** Support functions for common routing operations. Uses models and modules to handle the request.
  138. - **templates:** Golang templates for generating the html output.
  139. - **vendor:** External code that Gitea depends on.
  140. ## API v1
  141. The API is documented by [swagger](http://try.gitea.io/api/swagger) and is based on [GitHub API v3](https://developer.github.com/v3/).
  142. Thus, Gitea´s API should use the same endpoints and fields as GitHub´s API as far as possible, unless there are good reasons to deviate.
  143. If Gitea provides functionality that GitHub does not, a new endpoint can be created.
  144. If information is provided by Gitea that is not provided by the GitHub API, a new field can be used that doesn't collide with any GitHub fields.
  145. Updating an existing API should not remove existing fields unless there is a really good reason to do so.
  146. The same applies to status responses. If you notice a problem, feel free to leave a comment in the code for future refactoring to APIv2 (which is currently not planned).
  147. All expected results (errors, success, fail messages) should be documented
  148. ([example](https://github.com/go-gitea/gitea/blob/c620eb5b2d0d874da68ebd734d3864c5224f71f7/routers/api/v1/repo/issue.go#L319-L327)).
  149. All JSON input types must be defined as a struct in `models/structs/`
  150. ([example](https://github.com/go-gitea/gitea/blob/c620eb5b2d0d874da68ebd734d3864c5224f71f7/modules/structs/issue.go#L76-L91))
  151. and referenced in
  152. [routers/api/v1/swagger/options.go](https://github.com/go-gitea/gitea/blob/c620eb5b2d0d874da68ebd734d3864c5224f71f7/routers/api/v1/swagger/options.go).
  153. They can then be used like the following:
  154. ([example](https://github.com/go-gitea/gitea/blob/c620eb5b2d0d874da68ebd734d3864c5224f71f7/routers/api/v1/repo/issue.go#L318)).
  155. All JSON responses must be defined as a struct in `models/structs/`
  156. ([example](https://github.com/go-gitea/gitea/blob/c620eb5b2d0d874da68ebd734d3864c5224f71f7/modules/structs/issue.go#L36-L68))
  157. and referenced in its category in `routers/api/v1/swagger/`
  158. ([example](https://github.com/go-gitea/gitea/blob/c620eb5b2d0d874da68ebd734d3864c5224f71f7/routers/api/v1/swagger/issue.go#L11-L16))
  159. They can be used like the following:
  160. ([example](https://github.com/go-gitea/gitea/blob/c620eb5b2d0d874da68ebd734d3864c5224f71f7/routers/api/v1/repo/issue.go#L277-L279))
  161. In general, HTTP methods are chosen as follows:
  162. * **GET** endpoints return requested object and status **OK (200)**
  163. * **DELETE** endpoints return status **No Content (204)**
  164. * **POST** endpoints return status **Created (201)**, used to **create** new objects (e.g. a User)
  165. * **PUT** endpoints return status **No Content (204)**, used to **add/assign** existing Obejcts (e.g. User) to something (e.g. Org-Team)
  166. * **PATCH** endpoints return changed object and status **OK (200)**, used to **edit/change** an existing object
  167. An endpoint which changes/edits an object expects all fields to be optional (except ones to identify the object, which are required).
  168. ## Developer Certificate of Origin (DCO)
  169. We consider the act of contributing to the code by submitting a Pull
  170. Request as the "Sign off" or agreement to the certifications and terms
  171. of the [DCO](DCO) and [MIT license](LICENSE). No further action is required.
  172. Additionally you could add a line at the end of your commit message.
  173. ```
  174. Signed-off-by: Joe Smith <joe.smith@email.com>
  175. ```
  176. If you set your `user.name` and `user.email` git configs, you can add the
  177. line to the end of your commit automatically with `git commit -s`.
  178. We assume in good faith that the information you provide is legally binding.
  179. ## Release Cycle
  180. We adopted a release schedule to streamline the process of working
  181. on, finishing, and issuing releases. The overall goal is to make a
  182. minor release every two months, which breaks down into one month of
  183. general development followed by one month of testing and polishing
  184. known as the release freeze. All the feature pull requests should be
  185. merged in the first month of one release period. And, during the frozen
  186. period, a corresponding release branch is open for fixes backported from
  187. master. Release candidates are made during this period for user testing to
  188. obtain a final version that is maintained in this branch. A release is
  189. maintained by issuing patch releases to only correct critical problems
  190. such as crashes or security issues.
  191. Major release cycles are bimonthly. They always begin on the 25th and end on
  192. the 24th (i.e., the 25th of December to February 24th).
  193. During a development cycle, we may also publish any necessary minor releases
  194. for the previous version. For example, if the latest, published release is
  195. v1.2, then minor changes for the previous release—e.g., v1.1.0 -> v1.1.1—are
  196. still possible.
  197. ## Maintainers
  198. To make sure every PR is checked, we have [team
  199. maintainers](MAINTAINERS). Every PR **MUST** be reviewed by at least
  200. two maintainers (or owners) before it can get merged. A maintainer
  201. should be a contributor of Gitea (or Gogs) and contributed at least
  202. 4 accepted PRs. A contributor should apply as a maintainer in the
  203. [Discord](https://discord.gg/NsatcWJ) #develop channel. The owners
  204. or the team maintainers may invite the contributor. A maintainer
  205. should spend some time on code reviews. If a maintainer has no
  206. time to do that, they should apply to leave the maintainers team
  207. and we will give them the honor of being a member of the [advisors
  208. team](https://github.com/orgs/go-gitea/teams/advisors). Of course, if
  209. an advisor has time to code review, we will gladly welcome them back
  210. to the maintainers team. If a maintainer is inactive for more than 3
  211. months and forgets to leave the maintainers team, the owners may move
  212. him or her from the maintainers team to the advisors team.
  213. For security reasons, Maintainers should use 2FA for their accounts and
  214. if possible provide gpg signed commits.
  215. https://help.github.com/articles/securing-your-account-with-two-factor-authentication-2fa/
  216. https://help.github.com/articles/signing-commits-with-gpg/
  217. ## Owners
  218. Since Gitea is a pure community organization without any company support,
  219. to keep the development healthy we will elect three owners every year. All
  220. contributors may vote to elect up to three candidates, one of which will
  221. be the main owner, and the other two the assistant owners. When the new
  222. owners have been elected, the old owners will give up ownership to the
  223. newly elected owners. If an owner is unable to do so, the other owners
  224. will assist in ceding ownership to the newly elected owners.
  225. For security reasons, Owners or any account with write access (like a bot)
  226. must use 2FA.
  227. https://help.github.com/articles/securing-your-account-with-two-factor-authentication-2fa/
  228. After the election, the new owners should proactively agree
  229. with our [CONTRIBUTING](CONTRIBUTING.md) requirements in the
  230. [Discord](https://discord.gg/NsatcWJ) #general channel. Below are the
  231. words to speak:
  232. ```
  233. I'm honored to having been elected an owner of Gitea, I agree with
  234. [CONTRIBUTING](CONTRIBUTING.md). I will spend part of my time on Gitea
  235. and lead the development of Gitea.
  236. ```
  237. To honor the past owners, here's the history of the owners and the time
  238. they served:
  239. * 2016-11-04 ~ 2017-12-31
  240. * [Lunny Xiao](https://github.com/lunny) <xiaolunwen@gmail.com>
  241. * [Thomas Boerger](https://github.com/tboerger) <thomas@webhippie.de>
  242. * [Kim Carlbäcker](https://github.com/bkcsoft) <kim.carlbacker@gmail.com>
  243. * 2018-01-01 ~ 2018-12-31
  244. * [Lunny Xiao](https://github.com/lunny) <xiaolunwen@gmail.com>
  245. * [Lauris Bukšis-Haberkorns](https://github.com/lafriks) <lauris@nix.lv>
  246. * [Kim Carlbäcker](https://github.com/bkcsoft) <kim.carlbacker@gmail.com>
  247. * 2019-01-01 ~ 2019-12-31
  248. * [Lunny Xiao](https://github.com/lunny) <xiaolunwen@gmail.com>
  249. * [Lauris Bukšis-Haberkorns](https://github.com/lafriks) <lauris@nix.lv>
  250. * [Matti Ranta](https://github.com/techknowlogick) <techknowlogick@gitea.io>
  251. * 2020-01-01 ~ 2020-12-31
  252. * [Lunny Xiao](https://gitea.com/lunny) <xiaolunwen@gmail.com>
  253. * [Lauris Bukšis-Haberkorns](https://gitea.com/lafriks) <lauris@nix.lv>
  254. * [Matti Ranta](https://gitea.com/techknowlogick) <techknowlogick@gitea.io>
  255. ## Versions
  256. Gitea has the `master` branch as a tip branch and has version branches
  257. such as `release/v0.9`. `release/v0.9` is a release branch and we will
  258. tag `v0.9.0` for binary download. If `v0.9.0` has bugs, we will accept
  259. pull requests on the `release/v0.9` branch and publish a `v0.9.1` tag,
  260. after bringing the bug fix also to the master branch.
  261. Since the `master` branch is a tip version, if you wish to use Gitea
  262. in production, please download the latest release tag version. All the
  263. branches will be protected via GitHub, all the PRs to every branch must
  264. be reviewed by two maintainers and must pass the automatic tests.
  265. ## Releasing Gitea
  266. * Let $vmaj, $vmin and $vpat be Major, Minor and Patch version numbers, $vpat should be rc1, rc2, 0, 1, ...... $vmaj.$vmin will be kept the same as milestones on github or gitea in future.
  267. * Before releasing, confirm all the version's milestone issues or PRs has been resolved. Then discuss the release on discord channel #maintainers and get agreed with almost all the owners and mergers. Or you can declare the version and if nobody against in about serval hours.
  268. * If this is a big version first you have to create PR for changelog on branch `master` with PRs with label `changelog` and after it has been merged do following steps:
  269. * Create `-dev` tag as `git tag -s -F release.notes v$vmaj.$vmin.0-dev` and push the tag as `git push origin v$vmaj.$vmin.0-dev`.
  270. * When CI has finished building tag then you have to create a new branch named `release/v$vmaj.$vmin`
  271. * If it is bugfix version create PR for changelog on branch `release/v$vmaj.$vmin` and wait till it is reviewed and merged.
  272. * Add a tag as `git tag -s -F release.notes v$vmaj.$vmin.$`, release.notes file could be a temporary file to only include the changelog this version which you added to `CHANGELOG.md`.
  273. * And then push the tag as `git push origin v$vmaj.$vmin.$`. Drone CI will automatically created a release and upload all the compiled binary. (But currently it didn't add the release notes automatically. Maybe we should fix that.)
  274. * If needed send PR for changelog on branch `master`.
  275. * Send PR to [blog repository](https://gitea.com/gitea/blog) announcing the release.
  276. ## Copyright
  277. Code that you contribute should use the standard copyright header:
  278. ```
  279. // Copyright 2020 The Gitea Authors. All rights reserved.
  280. // Use of this source code is governed by a MIT-style
  281. // license that can be found in the LICENSE file.
  282. ```
  283. Files in the repository contain copyright from the year they are added
  284. to the year they are last changed. If the copyright author is changed,
  285. just paste the header below the old one.