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.

CONTRIBUTING.md 18KB

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