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.

354 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. - code lint
  58. | | |
  59. | :-------------------- | :---------------------------------------------------------------- |
  60. |``make lint`` | lint everything (not suggest if you only change one type code) |
  61. |``make lint-frontend`` | lint frontend files |
  62. |``make lint-backend`` | lint backend files |
  63. - run test code (Suggest run in linux)
  64. | | |
  65. | :------------------------------------- | :----------------------------------------------- |
  66. |``make test[\#TestSpecificName]`` | run unit test |
  67. |``make test-sqlite[\#TestSpecificName]``| run [integration](integrations) test for sqlite |
  68. |[More detail message about integrations](integrations/README.md) |
  69. ## Vendoring
  70. We keep a cached copy of dependencies within the `vendor/` directory,
  71. managing updates via [Modules](https://golang.org/cmd/go/#hdr-Module_maintenance).
  72. Pull requests should only include `vendor/` updates if they are part of
  73. the same change, be it a bugfix or a feature addition.
  74. The `vendor/` update needs to be justified as part of the PR description,
  75. and must be verified by the reviewers and/or merger to always reference
  76. an existing upstream commit.
  77. You can find more information on how to get started with it on the [Modules Wiki](https://github.com/golang/go/wiki/Modules).
  78. ## Translation
  79. We do all translation work inside [Crowdin](https://crowdin.com/project/gitea).
  80. The only translation that is maintained in this git repository is
  81. [`en_US.ini`](https://github.com/go-gitea/gitea/blob/master/options/locale/locale_en-US.ini)
  82. and is synced regularly to Crowdin. Once a translation has reached
  83. A SATISFACTORY PERCENTAGE it will be synced back into this repo and
  84. included in the next released version.
  85. ## Building Gitea
  86. See the [hacking instructions](https://docs.gitea.io/en-us/hacking-on-gitea/).
  87. ## Code review
  88. Changes to Gitea must be reviewed before they are accepted—no matter who
  89. makes the change, even if they are an owner or a maintainer. We use GitHub's
  90. pull request workflow to do that. And, we also use [LGTM](http://lgtm.co)
  91. to ensure every PR is reviewed by at least 2 maintainers.
  92. Please try to make your pull request easy to review for us. And, please read
  93. 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;
  94. it has lots of useful tips for any project you may want to contribute.
  95. Some of the key points:
  96. * Make small pull requests. The smaller, the faster to review and the
  97. more likely it will be merged soon.
  98. * Don't make changes unrelated to your PR. Maybe there are typos on
  99. some comments, maybe refactoring would be welcome on a function... but
  100. if that is not related to your PR, please make *another* PR for that.
  101. * Split big pull requests into multiple small ones. An incremental change
  102. will be faster to review than a huge PR.
  103. ## Styleguide
  104. For imports you should use the following format (_without_ the comments)
  105. ```go
  106. import (
  107. // stdlib
  108. "encoding/json"
  109. "fmt"
  110. // local packages
  111. "code.gitea.io/gitea/models"
  112. "code.gitea.io/sdk/gitea"
  113. // external packages
  114. "github.com/foo/bar"
  115. "gopkg.io/baz.v1"
  116. )
  117. ```
  118. ## Design guideline
  119. 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:
  120. - **integration:** Integrations tests
  121. - **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).
  122. - **models/fixtures:** Sample model data used in integration tests.
  123. - **models/migrations:** Handling of database migrations between versions. PRs that changes a database structure shall also have a migration step.
  124. - **modules:** Different modules to handle specific functionality in Gitea.
  125. - **public:** Frontend files (javascript, images, css, etc.)
  126. - **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
  127. - **services:** Support functions for common routing operations. Uses models and modules to handle the request.
  128. - **templates:** Golang templates for generating the html output.
  129. - **vendor:** External code that Gitea depends on.
  130. ## API v1
  131. The API is documented by [swagger](http://try.gitea.io/api/swagger) and is based on [GitHub API v3](https://developer.github.com/v3/).
  132. 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.
  133. If Gitea provides functionality that GitHub does not, a new endpoint can be created.
  134. 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.
  135. Updating an existing API should not remove existing fields unless there is a really good reason to do so.
  136. 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).
  137. All expected results (errors, success, fail messages) should be documented
  138. ([example](https://github.com/go-gitea/gitea/blob/c620eb5b2d0d874da68ebd734d3864c5224f71f7/routers/api/v1/repo/issue.go#L319-L327)).
  139. All JSON input types must be defined as a struct in `models/structs/`
  140. ([example](https://github.com/go-gitea/gitea/blob/c620eb5b2d0d874da68ebd734d3864c5224f71f7/modules/structs/issue.go#L76-L91))
  141. and referenced in
  142. [routers/api/v1/swagger/options.go](https://github.com/go-gitea/gitea/blob/c620eb5b2d0d874da68ebd734d3864c5224f71f7/routers/api/v1/swagger/options.go).
  143. They can then be used like the following:
  144. ([example](https://github.com/go-gitea/gitea/blob/c620eb5b2d0d874da68ebd734d3864c5224f71f7/routers/api/v1/repo/issue.go#L318)).
  145. All JSON responses must be defined as a struct in `models/structs/`
  146. ([example](https://github.com/go-gitea/gitea/blob/c620eb5b2d0d874da68ebd734d3864c5224f71f7/modules/structs/issue.go#L36-L68))
  147. and referenced in its category in `routers/api/v1/swagger/`
  148. ([example](https://github.com/go-gitea/gitea/blob/c620eb5b2d0d874da68ebd734d3864c5224f71f7/routers/api/v1/swagger/issue.go#L11-L16))
  149. They can be used like the following:
  150. ([example](https://github.com/go-gitea/gitea/blob/c620eb5b2d0d874da68ebd734d3864c5224f71f7/routers/api/v1/repo/issue.go#L277-L279))
  151. In general, HTTP methods are chosen as follows:
  152. * **GET** endpoints return requested object and status **OK (200)**
  153. * **DELETE** endpoints return status **No Content (204)**
  154. * **POST** endpoints return status **Created (201)**, used to **create** new objects (e.g. a User)
  155. * **PUT** endpoints return status **No Content (204)**, used to **add/assign** existing Obejcts (e.g. User) to something (e.g. Org-Team)
  156. * **PATCH** endpoints return changed object and status **OK (200)**, used to **edit/change** an existing object
  157. An endpoint which changes/edits an object expects all fields to be optional (except ones to identify the object, which are required).
  158. ## Developer Certificate of Origin (DCO)
  159. We consider the act of contributing to the code by submitting a Pull
  160. Request as the "Sign off" or agreement to the certifications and terms
  161. of the [DCO](DCO) and [MIT license](LICENSE). No further action is required.
  162. Additionally you could add a line at the end of your commit message.
  163. ```
  164. Signed-off-by: Joe Smith <joe.smith@email.com>
  165. ```
  166. If you set your `user.name` and `user.email` git configs, you can add the
  167. line to the end of your commit automatically with `git commit -s`.
  168. We assume in good faith that the information you provide is legally binding.
  169. ## Release Cycle
  170. We adopted a release schedule to streamline the process of working
  171. on, finishing, and issuing releases. The overall goal is to make a
  172. minor release every two months, which breaks down into one month of
  173. general development followed by one month of testing and polishing
  174. known as the release freeze. All the feature pull requests should be
  175. merged in the first month of one release period. And, during the frozen
  176. period, a corresponding release branch is open for fixes backported from
  177. master. Release candidates are made during this period for user testing to
  178. obtain a final version that is maintained in this branch. A release is
  179. maintained by issuing patch releases to only correct critical problems
  180. such as crashes or security issues.
  181. Major release cycles are bimonthly. They always begin on the 25th and end on
  182. the 24th (i.e., the 25th of December to February 24th).
  183. During a development cycle, we may also publish any necessary minor releases
  184. for the previous version. For example, if the latest, published release is
  185. v1.2, then minor changes for the previous release—e.g., v1.1.0 -> v1.1.1—are
  186. still possible.
  187. ## Maintainers
  188. To make sure every PR is checked, we have [team
  189. maintainers](MAINTAINERS). Every PR **MUST** be reviewed by at least
  190. two maintainers (or owners) before it can get merged. A maintainer
  191. should be a contributor of Gitea (or Gogs) and contributed at least
  192. 4 accepted PRs. A contributor should apply as a maintainer in the
  193. [Discord](https://discord.gg/NsatcWJ) #develop channel. The owners
  194. or the team maintainers may invite the contributor. A maintainer
  195. should spend some time on code reviews. If a maintainer has no
  196. time to do that, they should apply to leave the maintainers team
  197. and we will give them the honor of being a member of the [advisors
  198. team](https://github.com/orgs/go-gitea/teams/advisors). Of course, if
  199. an advisor has time to code review, we will gladly welcome them back
  200. to the maintainers team. If a maintainer is inactive for more than 3
  201. months and forgets to leave the maintainers team, the owners may move
  202. him or her from the maintainers team to the advisors team.
  203. For security reasons, Maintainers should use 2FA for their accounts and
  204. if possible provide gpg signed commits.
  205. https://help.github.com/articles/securing-your-account-with-two-factor-authentication-2fa/
  206. https://help.github.com/articles/signing-commits-with-gpg/
  207. ## Owners
  208. Since Gitea is a pure community organization without any company support,
  209. to keep the development healthy we will elect three owners every year. All
  210. contributors may vote to elect up to three candidates, one of which will
  211. be the main owner, and the other two the assistant owners. When the new
  212. owners have been elected, the old owners will give up ownership to the
  213. newly elected owners. If an owner is unable to do so, the other owners
  214. will assist in ceding ownership to the newly elected owners.
  215. For security reasons, Owners or any account with write access (like a bot)
  216. must use 2FA.
  217. https://help.github.com/articles/securing-your-account-with-two-factor-authentication-2fa/
  218. After the election, the new owners should proactively agree
  219. with our [CONTRIBUTING](CONTRIBUTING.md) requirements in the
  220. [Discord](https://discord.gg/NsatcWJ) #general channel. Below are the
  221. words to speak:
  222. ```
  223. I'm honored to having been elected an owner of Gitea, I agree with
  224. [CONTRIBUTING](CONTRIBUTING.md). I will spend part of my time on Gitea
  225. and lead the development of Gitea.
  226. ```
  227. To honor the past owners, here's the history of the owners and the time
  228. they served:
  229. * 2020-01-01 ~ 2020-12-31 - https://github.com/go-gitea/gitea/issues/9230
  230. * [Lunny Xiao](https://gitea.com/lunny) <xiaolunwen@gmail.com>
  231. * [Lauris Bukšis-Haberkorns](https://gitea.com/lafriks) <lauris@nix.lv>
  232. * [Matti Ranta](https://gitea.com/techknowlogick) <techknowlogick@gitea.io>
  233. * 2019-01-01 ~ 2019-12-31 - https://github.com/go-gitea/gitea/issues/5572
  234. * [Lunny Xiao](https://github.com/lunny) <xiaolunwen@gmail.com>
  235. * [Lauris Bukšis-Haberkorns](https://github.com/lafriks) <lauris@nix.lv>
  236. * [Matti Ranta](https://github.com/techknowlogick) <techknowlogick@gitea.io>
  237. * 2018-01-01 ~ 2018-12-31 - https://github.com/go-gitea/gitea/issues/3255
  238. * [Lunny Xiao](https://github.com/lunny) <xiaolunwen@gmail.com>
  239. * [Lauris Bukšis-Haberkorns](https://github.com/lafriks) <lauris@nix.lv>
  240. * [Kim Carlbäcker](https://github.com/bkcsoft) <kim.carlbacker@gmail.com>
  241. * 2016-11-04 ~ 2017-12-31
  242. * [Lunny Xiao](https://github.com/lunny) <xiaolunwen@gmail.com>
  243. * [Thomas Boerger](https://github.com/tboerger) <thomas@webhippie.de>
  244. * [Kim Carlbäcker](https://github.com/bkcsoft) <kim.carlbacker@gmail.com>
  245. ## Versions
  246. Gitea has the `master` branch as a tip branch and has version branches
  247. such as `release/v0.9`. `release/v0.9` is a release branch and we will
  248. tag `v0.9.0` for binary download. If `v0.9.0` has bugs, we will accept
  249. pull requests on the `release/v0.9` branch and publish a `v0.9.1` tag,
  250. after bringing the bug fix also to the master branch.
  251. Since the `master` branch is a tip version, if you wish to use Gitea
  252. in production, please download the latest release tag version. All the
  253. branches will be protected via GitHub, all the PRs to every branch must
  254. be reviewed by two maintainers and must pass the automatic tests.
  255. ## Releasing Gitea
  256. * 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.
  257. * 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.
  258. * 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:
  259. * 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`.
  260. * When CI has finished building tag then you have to create a new branch named `release/v$vmaj.$vmin`
  261. * If it is bugfix version create PR for changelog on branch `release/v$vmaj.$vmin` and wait till it is reviewed and merged.
  262. * 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`.
  263. * 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.)
  264. * If needed send PR for changelog on branch `master`.
  265. * Send PR to [blog repository](https://gitea.com/gitea/blog) announcing the release.
  266. ## Copyright
  267. Code that you contribute should use the standard copyright header:
  268. ```
  269. // Copyright 2020 The Gitea Authors. All rights reserved.
  270. // Use of this source code is governed by a MIT-style
  271. // license that can be found in the LICENSE file.
  272. ```
  273. Files in the repository contain copyright from the year they are added
  274. to the year they are last changed. If the copyright author is changed,
  275. just paste the header below the old one.