summaryrefslogtreecommitdiffstats
path: root/docs/content/doc/contributing
diff options
context:
space:
mode:
Diffstat (limited to 'docs/content/doc/contributing')
-rw-r--r--docs/content/doc/contributing/guidelines-backend.en-us.md123
-rw-r--r--docs/content/doc/contributing/guidelines-frontend.en-us.md136
-rw-r--r--docs/content/doc/contributing/guidelines-refactoring.en-us.md51
-rw-r--r--docs/content/doc/contributing/localization.en-us.md33
-rw-r--r--docs/content/doc/contributing/localization.zh-cn.md32
-rw-r--r--docs/content/doc/contributing/localization.zh-tw.md32
-rw-r--r--docs/content/doc/contributing/translation.de-de.md63
-rw-r--r--docs/content/doc/contributing/translation.en-us.md17
8 files changed, 487 insertions, 0 deletions
diff --git a/docs/content/doc/contributing/guidelines-backend.en-us.md b/docs/content/doc/contributing/guidelines-backend.en-us.md
new file mode 100644
index 0000000000..6ae0ba517d
--- /dev/null
+++ b/docs/content/doc/contributing/guidelines-backend.en-us.md
@@ -0,0 +1,123 @@
+---
+date: "2021-11-01T23:41:00+08:00"
+title: "Guidelines for Backend Development"
+slug: "guidelines-backend"
+weight: 20
+toc: false
+draft: false
+menu:
+ sidebar:
+ parent: "contributing"
+ name: "Guidelines for Backend"
+ weight: 20
+ identifier: "guidelines-backend"
+---
+
+# Guidelines for Backend Development
+
+**Table of Contents**
+
+{{< toc >}}
+
+## Background
+
+Gitea uses Golang as the backend programming language. It uses many third-party packages and also write some itself.
+For example, Gitea uses [Chi](https://github.com/go-chi/chi) as basic web framework. [Xorm](https://xorm.io) is an ORM framework that is used to interact with the database.
+So it's very important to manage these packages. Please take the below guidelines before you start to write backend code.
+
+## Package Design Guideline
+
+### Packages List
+
+To maintain understandable code and avoid circular dependencies it is important to have a good code structure. The Gitea backend is divided into the following parts:
+
+- `build`: Scripts to help build Gitea.
+- `cmd`: All Gitea actual sub commands includes web, doctor, serv, hooks, admin and etc. `web` will start the web service. `serv` and `hooks` will be invoked by Git or OpenSSH. Other sub commands could help to maintain Gitea.
+- `tests`: Common test utility functions
+ - `tests/integration`: Integration tests, to test back-end regressions
+ - `tests/e2e`: E2e tests, to test test front-end <> back-end compatibility and visual regressions.
+- `models`: Contains the data structures used by xorm to construct database tables. It also contains functions to query and update the database. Dependencies to other Gitea code should be avoided. You can make exceptions in cases such as logging.
+ - `models/db`: Basic database operations. All other `models/xxx` packages should depend on this package. The `GetEngine` function should only be invoked from `models/`.
+ - `models/fixtures`: Sample data used in unit tests and integration tests. One `yml` file means one table which will be loaded into database when beginning the tests.
+ - `models/migrations`: Stores database migrations between versions. PRs that change a database structure **MUST** also have a migration step.
+- `modules`: Different modules to handle specific functionality in Gitea. Work in Progress: Some of them should be moved to `services`, in particular those that depend on models because they rely on the database.
+ - `modules/setting`: Store all system configurations read from ini files and has been referenced by everywhere. But they should be used as function parameters when possible.
+ - `modules/git`: Package to interactive with `Git` command line or Gogit package.
+- `public`: Compiled frontend files (javascript, images, css, etc.)
+- `routers`: Handling of server requests. As it uses other Gitea packages to serve the request, other packages (models, modules or services) must not depend on routers.
+ - `routers/api` Contains routers for `/api/v1` aims to handle RESTful API requests.
+ - `routers/install` Could only respond when system is in INSTALL mode (INSTALL_LOCK=false).
+ - `routers/private` will only be invoked by internal sub commands, especially `serv` and `hooks`.
+ - `routers/web` will handle HTTP requests from web browsers or Git SMART HTTP protocols.
+- `services`: Support functions for common routing operations or command executions. Uses `models` and `modules` to handle the requests.
+- `templates`: Golang templates for generating the html output.
+
+### Package Dependencies
+
+Since Golang doesn't support import cycles, we have to decide the package dependencies carefully. There are some levels between those packages. Below is the ideal package dependencies direction.
+
+`cmd` -> `routers` -> `services` -> `models` -> `modules`
+
+From left to right, left packages could depend on right packages, but right packages MUST not depend on left packages. The sub packages on the same level could depend on according this level's rules.
+
+**NOTICE**
+
+Why do we need database transactions outside of `models`? And how?
+Some actions should allow for rollback when database record insertion/update/deletion failed.
+So services must be allowed to create a database transaction. Here is some example,
+
+```go
+// services/repository/repository.go
+func CreateXXXX() error {
+ return db.WithTx(func(ctx context.Context) error {
+ e := db.GetEngine(ctx)
+ // do something, if err is returned, it will rollback automatically
+ if err := issues.UpdateIssue(ctx, repoID); err != nil {
+ // ...
+ return err
+ }
+ // ...
+ return nil
+ })
+}
+```
+
+You should **not** use `db.GetEngine(ctx)` in `services` directly, but just write a function under `models/`.
+If the function will be used in the transaction, just let `context.Context` as the function's first parameter.
+
+```go
+// models/issues/issue.go
+func UpdateIssue(ctx context.Context, repoID int64) error {
+ e := db.GetEngine(ctx)
+
+ // ...
+}
+```
+
+### Package Name
+
+For the top level package, use a plural as package name, i.e. `services`, `models`, for sub packages, use singular,
+i.e. `services/user`, `models/repository`.
+
+### Import Alias
+
+Since there are some packages which use the same package name, it is possible that you find packages like `modules/user`, `models/user`, and `services/user`. When these packages are imported in one Go file, it's difficult to know which package we are using and if it's a variable name or an import name. So, we always recommend to use import aliases. To differ from package variables which are commonly in camelCase, just use **snake_case** for import aliases.
+i.e. `import user_service "code.gitea.io/gitea/services/user"`
+
+### Important Gotchas
+
+- Never write `x.Update(exemplar)` without an explicit `WHERE` clause:
+ - This will cause all rows in the table to be updated with the non-zero values of the exemplar - including IDs.
+ - You should usually write `x.ID(id).Update(exemplar)`.
+- If during a migration you are inserting into a table using `x.Insert(exemplar)` where the ID is preset:
+ - You will need to ``SET IDENTITY_INSERT `table` ON`` for the MSSQL variant (the migration will fail otherwise)
+ - However, you will also need to update the id sequence for postgres - the migration will silently pass here but later insertions will fail:
+ ``SELECT setval('table_name_id_seq', COALESCE((SELECT MAX(id)+1 FROM `table_name`), 1), false)``
+
+### Future Tasks
+
+Currently, we are creating some refactors to do the following things:
+
+- Correct that codes which doesn't follow the rules.
+- There are too many files in `models`, so we are moving some of them into a sub package `models/xxx`.
+- Some `modules` sub packages should be moved to `services` because they depend on `models`.
diff --git a/docs/content/doc/contributing/guidelines-frontend.en-us.md b/docs/content/doc/contributing/guidelines-frontend.en-us.md
new file mode 100644
index 0000000000..36c88739ec
--- /dev/null
+++ b/docs/content/doc/contributing/guidelines-frontend.en-us.md
@@ -0,0 +1,136 @@
+---
+date: "2021-10-13T16:00:00+02:00"
+title: "Guidelines for Frontend Development"
+slug: "guidelines-frontend"
+weight: 20
+toc: false
+draft: false
+menu:
+ sidebar:
+ parent: "contributing"
+ name: "Guidelines for Frontend"
+ weight: 20
+ identifier: "guidelines-frontend"
+---
+
+# Guidelines for Frontend Development
+
+**Table of Contents**
+
+{{< toc >}}
+
+## Background
+
+Gitea uses [Fomantic-UI](https://fomantic-ui.com/introduction/getting-started.html) (based on [jQuery](https://api.jquery.com)) and [Vue3](https://vuejs.org/) for its frontend.
+
+The HTML pages are rendered by [Go HTML Template](https://pkg.go.dev/html/template).
+
+The source files can be found in the following directories:
+
+* **CSS styles:** `web_src/css/`
+* **JavaScript files:** `web_src/js/`
+* **Vue components:** `web_src/js/components/`
+* **Go HTML templates:** `templates/`
+
+## General Guidelines
+
+We recommend [Google HTML/CSS Style Guide](https://google.github.io/styleguide/htmlcssguide.html) and [Google JavaScript Style Guide](https://google.github.io/styleguide/jsguide.html)
+
+### Gitea specific guidelines:
+
+1. Every feature (Fomantic-UI/jQuery module) should be put in separate files/directories.
+2. HTML ids and classes should use kebab-case, it's preferred to contain 2-3 feature related keywords.
+3. HTML ids and classes used in JavaScript should be unique for the whole project, and should contain 2-3 feature related keywords. We recommend to use the `js-` prefix for classes that are only used in JavaScript.
+4. CSS styling for classes provided by frameworks should not be overwritten. Always use new class names with 2-3 feature related keywords to overwrite framework styles. Gitea's helper CSS classes in `helpers.less` could be helpful.
+5. The backend can pass complex data to the frontend by using `ctx.PageData["myModuleData"] = map[]{}`, but do not expose whole models to the frontend to avoid leaking sensitive data.
+6. Simple pages and SEO-related pages use Go HTML Template render to generate static Fomantic-UI HTML output. Complex pages can use Vue3.
+7. Clarify variable types, prefer `elem.disabled = true` instead of `elem.setAttribute('disabled', 'anything')`, prefer `$el.prop('checked', var === 'yes')` instead of `$el.prop('checked', var)`.
+8. Use semantic elements, prefer `<button class="ui button">` instead of `<div class="ui button">`.
+9. Avoid unnecessary `!important` in CSS, add comments to explain why it's necessary if it can't be avoided.
+10. Avoid mixing different events in one event listener, prefer to use individual event listeners for every event.
+11. Custom event names are recommended to use `ce-` prefix.
+
+### Accessibility / ARIA
+
+In history, Gitea heavily uses Fomantic UI which is not an accessibility-friendly framework.
+Gitea uses some patches to make Fomantic UI more accessible (see the `aria.js` and `aria.md`),
+but there are still many problems which need a lot of work and time to fix.
+
+### Framework Usage
+
+Mixing different frameworks together is discouraged, it makes the code difficult to be maintained.
+A JavaScript module should follow one major framework and follow the framework's best practice.
+
+Recommended implementations:
+
+* Vue + Vanilla JS
+* Fomantic-UI (jQuery)
+* Vanilla JS
+
+Discouraged implementations:
+
+* Vue + Fomantic-UI (jQuery)
+* jQuery + Vanilla JS
+
+To make UI consistent, Vue components can use Fomantic-UI CSS classes.
+Although mixing different frameworks is discouraged,
+it should also work if the mixing is necessary and the code is well-designed and maintainable.
+
+### `async` Functions
+
+Only mark a function as `async` if and only if there are `await` calls
+or `Promise` returns inside the function.
+
+It's not recommended to use `async` event listeners, which may lead to problems.
+The reason is that the code after await is executed outside the event dispatch.
+Reference: https://github.com/github/eslint-plugin-github/blob/main/docs/rules/async-preventdefault.md
+
+If an event listener must be `async`, the `e.preventDefault()` should be before any `await`,
+it's recommended to put it at the beginning of the function.
+
+If we want to call an `async` function in a non-async context,
+it's recommended to use `const _promise = asyncFoo()` to tell readers
+that this is done by purpose, we want to call the async function and ignore the Promise.
+Some lint rules and IDEs also have warnings if the returned Promise is not handled.
+
+### HTML Attributes and `dataset`
+
+The usage of `dataset` is forbidden, its camel-casing behaviour makes it hard to grep for attributes.
+However, there are still some special cases, so the current guideline is:
+
+* For legacy code:
+ * `$.data()` should be refactored to `$.attr()`.
+ * `$.data()` can be used to bind some non-string data to elements in rare cases, but it is highly discouraged.
+
+* For new code:
+ * `node.dataset` should not be used, use `node.getAttribute` instead.
+ * never bind any user data to a DOM node, use a suitable design pattern to describe the relation between node and data.
+
+### Show/Hide Elements
+
+* Vue components are recommended to use `v-if` and `v-show` to show/hide elements.
+* Go template code should use Gitea's `.gt-hidden` and `showElem()/hideElem()/toggleElem()`, see more details in `.gt-hidden`'s comment.
+
+### Styles and Attributes in Go HTML Template
+
+It's recommended to use:
+
+```html
+<div class="gt-name1 gt-name2 {{if .IsFoo}}gt-foo{{end}}" {{if .IsFoo}}data-foo{{end}}></div>
+```
+
+instead of:
+
+```html
+<div class="gt-name1 gt-name2{{if .IsFoo}} gt-foo{{end}}"{{if .IsFoo}} data-foo{{end}}></div>
+```
+
+to make the code more readable.
+
+### Legacy Code
+
+A lot of legacy code already existed before this document's written. It's recommended to refactor legacy code to follow the guidelines.
+
+### Vue3 and JSX
+
+Gitea is using Vue3 now. We decided not to introduce JSX to keep the HTML and the JavaScript code separated.
diff --git a/docs/content/doc/contributing/guidelines-refactoring.en-us.md b/docs/content/doc/contributing/guidelines-refactoring.en-us.md
new file mode 100644
index 0000000000..913ce8d9bb
--- /dev/null
+++ b/docs/content/doc/contributing/guidelines-refactoring.en-us.md
@@ -0,0 +1,51 @@
+---
+date: "2023-02-14T00:00:00+00:00"
+title: "Guidelines for Refactoring"
+slug: "guidelines-refactoring"
+weight: 20
+toc: false
+draft: false
+menu:
+ sidebar:
+ parent: "contributing"
+ name: "Guidelines for Refactoring"
+ weight: 20
+ identifier: "guidelines-refactoring"
+---
+
+# Guidelines for Refactoring
+
+**Table of Contents**
+
+{{< toc >}}
+
+## Background
+
+Since the first line of code was written at Feb 12, 2014, Gitea has grown to be a large project.
+As a result, the codebase has become larger and larger. The larger the codebase is, the more difficult it is to maintain.
+A lot of outdated mechanisms exist, a lot of frameworks are mixed together, some legacy code might cause bugs and block new features.
+To make the codebase more maintainable and make Gitea better, developers should keep in mind to use modern mechanisms to refactor the old code.
+
+This document is a collection of guidelines for refactoring the codebase.
+
+## Refactoring Suggestions
+
+* Design more about the future, but not only resolve the current problem.
+* Reduce ambiguity, reduce conflicts, improve maintainability.
+* Describe the refactoring, for example:
+ * Why the refactoring is needed.
+ * How the legacy problems would be solved.
+ * What's the Pros/Cons of the refactoring.
+* Only do necessary changes, keep the old logic as much as possible.
+* Introduce some intermediate steps to make the refactoring easier to review, a complete refactoring plan could be done in several PRs.
+* If there is any divergence, the TOC(Technical Oversight Committee) should be involved to help to make decisions.
+* Add necessary tests to make sure the refactoring is correct.
+* Non-bug refactoring is preferred to be done at the beginning of a milestone, it would be easier to find problems before the release.
+
+## Reviewing & Merging Suggestions
+
+* A refactoring PR shouldn't be kept open for a long time (usually 7 days), it should be reviewed as soon as possible.
+* A refactoring PR should be merged as soon as possible, it should not be blocked by other PRs.
+* If there is no objection from TOC, a refactoring PR could be merged after 7 days with one core member's approval (not the author).
+* Tolerate some dirty/hacky intermediate steps if the final result is good.
+* Tolerate some regression bugs if the refactoring is necessary, fix bugs as soon as possible.
diff --git a/docs/content/doc/contributing/localization.en-us.md b/docs/content/doc/contributing/localization.en-us.md
new file mode 100644
index 0000000000..3006ca599b
--- /dev/null
+++ b/docs/content/doc/contributing/localization.en-us.md
@@ -0,0 +1,33 @@
+---
+date: "2016-12-01T16:00:00+02:00"
+title: "Localization"
+slug: "localization"
+weight: 10
+toc: false
+draft: false
+menu:
+ sidebar:
+ parent: "contributing"
+ name: "Localization"
+ weight: 20
+ identifier: "localization"
+---
+
+# Localization
+
+Gitea's localization happens through our [Crowdin project](https://crowdin.com/project/gitea).
+
+For changes to an **English** translation, a pull request can be made that changes the appropriate key in
+the [english locale](https://github.com/go-gitea/gitea/blob/master/options/locale/locale_en-US.ini).
+
+For changes to a **non-English** translation, refer to the Crowdin project above.
+
+## Supported Languages
+
+Any language listed in the above Crowdin project will be supported as long as 25% or more has been translated.
+
+After a translation has been accepted, it will be reflected in the main repository after the next Crowdin sync, which is generally after any PR is merged.
+
+At the time of writing, this means that a changed translation may not appear until the following Gitea release.
+
+If you use a bleeding edge build, it should appear as soon as you update after the change is synced.
diff --git a/docs/content/doc/contributing/localization.zh-cn.md b/docs/content/doc/contributing/localization.zh-cn.md
new file mode 100644
index 0000000000..10df44042f
--- /dev/null
+++ b/docs/content/doc/contributing/localization.zh-cn.md
@@ -0,0 +1,32 @@
+---
+date: "2016-12-01T16:00:00+02:00"
+title: "本地化"
+slug: "localization"
+weight: 10
+toc: false
+draft: false
+menu:
+ sidebar:
+ parent: "contributing"
+ name: "本地化"
+ weight: 20
+ identifier: "localization"
+---
+
+# 本地化
+
+Gitea的本地化是通过我们的[Crowdin项目](https://crowdin.com/project/gitea)进行的。
+
+对于对**英语翻译**的更改,可以发出pull-request,来更改[英语语言环境](https://github.com/go-gitea/gitea/blob/master/options/locale/locale_en-US.ini)中合适的关键字。
+
+有关对**非英语**翻译的更改,请参阅上面的 Crowdin 项目。
+
+## 支持的语言
+
+上述 Crowdin 项目中列出的任何语言一旦翻译了 25% 或更多都将得到支持。
+
+翻译被接受后,它将在下一次 Crowdin 同步后反映在主存储库中,这通常是在任何 PR 合并之后。
+
+在撰写本文时,这意味着更改后的翻译可能要到 Gitea 的下一个版本才会出现。
+
+如果使用开发版本,则在同步更改内容后,它应该会在更新后立即显示。
diff --git a/docs/content/doc/contributing/localization.zh-tw.md b/docs/content/doc/contributing/localization.zh-tw.md
new file mode 100644
index 0000000000..562aa4ecaf
--- /dev/null
+++ b/docs/content/doc/contributing/localization.zh-tw.md
@@ -0,0 +1,32 @@
+---
+date: "2016-12-01T16:00:00+02:00"
+title: "在地化"
+slug: "localization"
+weight: 10
+toc: false
+draft: false
+menu:
+ sidebar:
+ parent: "contributing"
+ name: "在地化"
+ weight: 20
+ identifier: "localization"
+---
+
+# 在地化
+
+我們在 [Crowdin 專案](https://crowdin.com/project/gitea)上進行在地化工作。
+
+**英語系**的翻譯,可在修改[英文語言檔](https://github.com/go-gitea/gitea/blob/master/options/locale/locale_en-US.ini)後提出合併請求。
+
+**非英語系**的翻譯,請前往上述的 Crowdin 專案。
+
+## 已支援的語言
+
+上述 Crowdin 專案中列出的語言在翻譯超過 25% 後將被支援。
+
+翻譯被認可後將在下次 Crowdin 同步後進入到主儲存庫,通常是在任何合併請求被合併之後。
+
+這表示更改的翻譯要到下次 Gitea 發佈後才會出現。
+
+如果您使用的是最新建置,它將會在同步完成、您更新後出現。
diff --git a/docs/content/doc/contributing/translation.de-de.md b/docs/content/doc/contributing/translation.de-de.md
new file mode 100644
index 0000000000..16cb267931
--- /dev/null
+++ b/docs/content/doc/contributing/translation.de-de.md
@@ -0,0 +1,63 @@
+---
+date: "2021-01-22T00:00:00+02:00"
+title: "Übersetzungs Richtlinien"
+weight: 10
+toc: true
+draft: false
+menu:
+ sidebar:
+ parent: "contributing"
+ name: "Übersetzungsrichtlinien"
+ weight: 70
+ identifier: "translation-guidelines"
+---
+
+## Allgemeines
+
+Anrede: Wenig förmlich:
+
+* "Du"-Form
+* Keine "Amtsdeusch"-Umschreibungen, einfach so als ob man den Nutzer direkt persönlich ansprechen würde
+
+Genauer definiert:
+
+* "falsch" anstatt "nicht korrekt/inkorrekt"
+* Benutzerkonto oder Konto? Oder Account?
+* "Wende dich an ..." anstatt "kontaktiere ..."
+* In der selben Zeit übersetzen (sonst wird aus "is" "war")
+* Richtige Anführungszeichen verwenden. Also `"` statt `''` oder `'` oder \` oder `´`
+ * `„` für beginnende Anführungszeichen, `“` für schließende Anführungszeichen
+
+Es gelten Artikel und Worttrennungen aus dem Duden.
+
+## Formulierungen in Modals und Buttons
+
+Es sollten die gleichen Formulierungen auf Buttons und Modals verwendet werden.
+
+Beispiel: Wenn der Button mit `löschen` beschriftet ist, sollte im Modal die Frage lauten `Willst du das wirklich löschen?` und nicht `Willst du das wirklich entfernen?`. Gleiches gilt für Success/Errormeldungen nach der Aktion.
+
+## Trennungen
+
+* Pull-Request
+* Time-Tracker
+* E-Mail-Adresse (siehe Duden)
+
+## Artikeldefinitionen für Anglizismen
+
+* _Der_ Commit (m.)
+* _Der_ Branch (m.), plural: die Branches
+* _Das_ Issue (n.)
+* _Der_ Fork (m.)
+* _Das_ Repository (n.), plural: die Repositories
+* _Der_ Pull-Request (m.)
+* _Der_ Token (m.), plural: die Token
+* _Das_ Review (n.)
+* _Der_ Key (m.)
+* _Der_ Committer (m.), plural: die Committer
+
+## Weiterführende Links
+
+Diese beiden Links sind sehr empfehlenswert:
+
+* http://docs.translatehouse.org/projects/localization-guide/en/latest/guide/translation_guidelines_german.html
+* https://docs.qgis.org/2.18/en/docs/documentation_guidelines/do_translations.html
diff --git a/docs/content/doc/contributing/translation.en-us.md b/docs/content/doc/contributing/translation.en-us.md
new file mode 100644
index 0000000000..23ff18a5b2
--- /dev/null
+++ b/docs/content/doc/contributing/translation.en-us.md
@@ -0,0 +1,17 @@
+---
+date: "2021-01-22T00:00:00+02:00"
+title: "Translation Guidelines"
+weight: 10
+toc: true
+draft: false
+menu:
+ sidebar:
+ parent: "contributing"
+ name: "Translation Guidelines"
+ weight: 70
+ identifier: "translation-guidelines"
+---
+
+This place is used to provide a common set of rules to make sure the translation is consistent.
+
+* [German](/de-de/übersetzungs-richtlinien/)