diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md deleted file mode 100644 index b752abb794de..000000000000 --- a/.github/pull_request_template.md +++ /dev/null @@ -1,9 +0,0 @@ - -Please check the following: -1. Make sure you are targeting the `main` branch, pull requests on release branches are only allowed for backports. -2. Make sure you have read contributing guidelines: https://github.com/go-gitea/gitea/blob/main/CONTRIBUTING.md . -3. Describe what your pull request does and which issue you're targeting (if any). -4. It is recommended to enable "Allow edits by maintainers", so maintainers can help more easily. -5. Your input here will be included in the commit message when this PR has been merged. If you don't want some content to be included, please separate them with a line like `---`. -6. Delete all these tips before posting. - diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5d20bc258947..e8b3a293b982 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,605 +1,246 @@ # Contribution Guidelines -
Table of Contents - -- [Contribution Guidelines](#contribution-guidelines) - - [Introduction](#introduction) - - [Issues](#issues) - - [How to report issues](#how-to-report-issues) - - [Types of issues](#types-of-issues) - - [Discuss your design before the implementation](#discuss-your-design-before-the-implementation) - - [Issue locking](#issue-locking) - - [Building Gitea](#building-gitea) - - [Dependencies](#dependencies) - - [Backend](#backend) - - [Frontend](#frontend) - - [Design guideline](#design-guideline) - - [Styleguide](#styleguide) - - [Copyright](#copyright) - - [Testing](#testing) - - [Translation](#translation) - - [Code review](#code-review) - - [Pull request format](#pull-request-format) - - [PR title and summary](#pr-title-and-summary) - - [Milestone](#milestone) - - [Labels](#labels) - - [Breaking PRs](#breaking-prs) - - [What is a breaking PR?](#what-is-a-breaking-pr) - - [How to handle breaking PRs?](#how-to-handle-breaking-prs) - - [Maintaining open PRs](#maintaining-open-prs) - - [Getting PRs merged](#getting-prs-merged) - - [Final call](#final-call) - - [Commit messages](#commit-messages) - - [PR Co-authors](#pr-co-authors) - - [PRs targeting `main`](#prs-targeting-main) - - [Backport PRs](#backport-prs) - - [Documentation](#documentation) - - [API v1](#api-v1) - - [GitHub API compatibility](#github-api-compatibility) - - [Adding/Maintaining API routes](#addingmaintaining-api-routes) - - [When to use what HTTP method](#when-to-use-what-http-method) - - [Requirements for API routes](#requirements-for-api-routes) - - [Backports and Frontports](#backports-and-frontports) - - [What is backported?](#what-is-backported) - - [How to backport?](#how-to-backport) - - [Format of backport PRs](#format-of-backport-prs) - - [Frontports](#frontports) - - [Developer Certificate of Origin (DCO)](#developer-certificate-of-origin-dco) - - [Release Cycle](#release-cycle) - - [Maintainers](#maintainers) - - [Technical Oversight Committee (TOC)](#technical-oversight-committee-toc) - - [TOC election process](#toc-election-process) - - [Current TOC members](#current-toc-members) - - [Previous TOC/owners members](#previous-tocowners-members) - - [Governance Compensation](#governance-compensation) - - [TOC \& Working groups](#toc--working-groups) - - [Roadmap](#roadmap) - - [Versions](#versions) - - [Releasing Gitea](#releasing-gitea) - -
- -## Introduction - -This document explains how to contribute changes to the Gitea project. \ -It assumes you have followed the [installation instructions](https://docs.gitea.com/category/installation). \ -Sensitive security-related issues should be reported to [security@gitea.io](mailto:security@gitea.io). - -For configuring IDEs for Gitea development, see the [contributed IDE configurations](contrib/ide/). - -## Issues - -### How to report issues - -Please search the issues on the issue tracker with a variety of related keywords to ensure that your issue has not already been reported. - -If your issue has not been reported yet, [open an issue](https://github.com/go-gitea/gitea/issues/new) -and answer the questions so we can understand and reproduce the problematic behavior. \ -Please write clear and concise instructions so that we can reproduce the behavior — even if it seems obvious. \ -The more detailed and specific you are, the faster we can fix the issue. \ -It is really helpful if you can reproduce your problem on a site running on the latest commits, i.e. , as perhaps your problem has already been fixed on a current version. \ -Please follow the guidelines described in [How to Report Bugs Effectively](http://www.chiark.greenend.org.uk/~sgtatham/bugs.html) for your report. - -Please be kind, remember that Gitea comes at no cost to you, and you're getting free help. - -### Types of issues - -Typically, issues fall in one of the following categories: - -- `bug`: Something in the frontend or backend behaves unexpectedly -- `security issue`: bug that has serious implications such as leaking another users data. Please do not file such issues on the public tracker and send a mail to security@gitea.io instead -- `feature`: Completely new functionality. You should describe this feature in enough detail that anyone who reads the issue can understand how it is supposed to be implemented -- `enhancement`: An existing feature should get an upgrade -- `refactoring`: Parts of the code base don't conform with other parts and should be changed to improve Gitea's maintainability - -### Discuss your design before the implementation - -We welcome submissions. \ -If you want to change or add something, please let everyone know what you're working on — [file an issue](https://github.com/go-gitea/gitea/issues/new) or comment on an existing one before starting your work! - -Significant changes such as new features must go through the change proposal process before they can be accepted. \ -This is mainly to save yourself the trouble of implementing it, only to find out that your proposed implementation has some potential problems. \ -Furthermore, this process gives everyone a chance to validate the design, helps prevent duplication of effort, and ensures that the idea fits inside -the goals for the project and tools. - -Pull requests should not be the place for architecture discussions. - -### Issue locking - -Commenting on closed or merged issues/PRs is strongly discouraged. -Such comments will likely be overlooked as some maintainers may not view notifications on closed issues, thinking that the item is resolved. -As such, commenting on closed/merged issues/PRs may be disabled prior to the scheduled auto-locking if a discussion starts or if unrelated comments are posted. -If further discussion is needed, we encourage you to open a new issue instead and we recommend linking to the issue/PR in question for context. - -## Building Gitea +After following the instructions to set up your instance, please read below for guidelines on contributions to RIA Hub. -See the [development setup instructions](https://docs.gitea.com/development/hacking-on-gitea). +## Guidelines for Backend Development -## Dependencies +### Backend Background -### Backend +Gitea uses Golang as the backend programming language. It uses many third-party packages and also writes some itself. For example, Gitea uses [Chi](https://github.com/go-chi/chi) as a 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. -Go dependencies are managed using [Go Modules](https://go.dev/cmd/go/#hdr-Module_maintenance). \ -You can find more details in the [go mod documentation](https://go.dev/ref/mod) and the [Go Modules Wiki](https://github.com/golang/go/wiki/Modules). +### Package Design Guideline -Pull requests should only modify `go.mod` and `go.sum` where it is related to your change, be it a bugfix or a new feature. \ -Apart from that, these files should only be modified by Pull Requests whose only purpose is to update dependencies. +#### Packages List -The `go.mod`, `go.sum` update needs to be justified as part of the PR description, -and must be verified by the reviewers and/or merger to always reference -an existing upstream commit. +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: -### Frontend +- `build`: Scripts to help build Gitea. +- `cmd`: All Gitea actual subcommands, including web, doctor, serv, hooks, admin, etc. `web` will start the web service. `serv` and `hooks` will be invoked by Git or OpenSSH. Other subcommands could help to maintain Gitea. +- `tests`: Common test utility functions. + - `tests/integration`: Integration tests, to test back-end regressions. + - `tests/e2e`: End-to-end tests, to test front-end and 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, with exceptions like 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 the database when tests begin. + - `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 should be moved to services, particularly those that depend on models.) + - `modules/setting`: Stores all system configurations read from ini files and is referenced everywhere. Should be used as function parameters when possible. + - `modules/git`: Package to interact with Git command line or Gogit package. +- `public`: Compiled frontend files (JavaScript, images, CSS, etc.). +- `routers`: Handles server requests. As it uses other Gitea packages to serve requests, other packages (models, modules, or services) must not depend on routers. + - `routers/api`: Contains routers for `/api/v1`, aimed to handle RESTful API requests. + - `routers/install`: Responds only when the system is in INSTALL mode (`INSTALL_LOCK=false`). + - `routers/private`: Invoked only by internal subcommands, especially serv and hooks. + - `routers/web`: Handles 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 requests. +- `templates`: Golang templates for generating HTML output. -For the frontend, we use [npm](https://www.npmjs.com/). +### Package Dependencies -The same restrictions apply for frontend dependencies as for backend dependencies, with the exceptions that the files for it are `package.json` and `package-lock.json`, and that new versions must always reference an existing version. +Since Golang doesn't support import cycles, we have to decide package dependencies carefully. There are some levels between packages. Below is the ideal package dependency direction: -## Design guideline +`cmd -> routers -> services -> models -> modules` -Depending on your change, please read the +From left to right, packages on the left can depend on packages on the right, but packages on the right MUST not depend on those on the left. Subpackages on the same level may depend according to this level's rules. -- [backend development guideline](https://docs.gitea.com/contributing/guidelines-backend) -- [frontend development guideline](https://docs.gitea.com/contributing/guidelines-frontend) -- [refactoring guideline](https://docs.gitea.com/contributing/guidelines-refactoring) +### Package Name -## Styleguide - -You should always run `make fmt` before committing to conform to Gitea's styleguide. - -## Copyright - -New code files that you contribute should use the standard copyright header: - -``` -// Copyright The Gitea Authors. All rights reserved. -// SPDX-License-Identifier: MIT -``` - -Afterwards, copyright should only be modified when the copyright author changes. - -## Testing - -Before submitting a pull request, run all tests to make sure your changes don't cause a regression elsewhere. - -Here's how to run the test suite: - -- code lint - -| | | -| :-------------------- | :---------------------------------------------------------------- | -|``make lint`` | lint everything (not needed if you only change the front- **or** backend) | -|``make lint-frontend`` | lint frontend files | -|``make lint-backend`` | lint backend files | +For top-level packages, use a plural as the package name, i.e., `services`, `models`. For subpackages, use the singular, i.e., `services/user`, `models/repository`. -- run tests (we suggest running them on Linux) +### Import Alias -| Command | Action | | -| :------------------------------------- | :----------------------------------------------- | ------------ | -|``make test[\#SpecificTestName]`` | run unit test(s) | | -|``make test-sqlite[\#SpecificTestName]``| run [integration](tests/integration) test(s) for SQLite |[More details](tests/integration/README.md) | -|``make test-e2e-sqlite[\#SpecificTestName]``| run [end-to-end](tests/e2e) test(s) for SQLite |[More details](tests/e2e/README.md) | +Since some packages use the same package name, you might encounter 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 is being used and whether it's a variable or import name. Therefore, it is recommended to use import aliases. To differentiate from package variables (which are commonly in camelCase), use snake_case for import aliases, e.g., `import user_service "code.gitea.io/gitea/services/user"`. -## Translation +## Guidelines for Frontend Development -All translation work happens on [Crowdin](https://crowdin.com/project/gitea). -The only translation that is maintained in this repository is [the English translation](https://github.com/go-gitea/gitea/blob/main/options/locale/locale_en-US.ini). -It is synced regularly with Crowdin. \ -Other locales on main branch **should not** be updated manually as they will be overwritten with each sync. \ -Once a language has reached a **satisfactory percentage** of translated keys (~25%), it will be synced back into this repo and included in the next released version. +### Frontend Background -The tool `go run build/backport-locale.go` can be used to backport locales from the main branch to release branches that were missed. +Gitea uses `Fomantic-UI` (based on jQuery) and `Vue3` for its frontend. -## Code review +The HTML pages are rendered by Go HTML Template. -### Pull request format +The source files can be found in the following directories: -Please try to make your pull request easy to review for us. \ -For that, please read the [*Best Practices for Faster Reviews*](https://github.com/kubernetes/community/blob/261cb0fd089b64002c91e8eddceebf032462ccd6/contributors/guide/pull-requests.md#best-practices-for-faster-reviews) guide. \ -It has lots of useful tips for any project you may want to contribute to. \ -Some of the key points: +- CSS styles: `web_src/css/` +- JavaScript files: `web_src/js/` +- Vue components: `web_src/js/components/` +- Go HTML templates: `templates/` -- Make small pull requests. \ - The smaller, the faster to review and the more likely it will be merged soon. -- Don't make changes unrelated to your PR. \ - Maybe there are typos on some comments, maybe refactoring would be welcome on a function... \ - but if that is not related to your PR, please make *another* PR for that. -- Split big pull requests into multiple small ones. \ - An incremental change will be faster to review than a huge PR. -- Allow edits by maintainers. This way, the maintainers will take care of merging the PR later on instead of you. +### General Guidelines -### PR title and summary +We recommend the following style guides: -In the PR title, describe the problem you are fixing, not how you are fixing it. \ -Use the first comment as a summary of your PR. \ -In the PR summary, you can describe exactly how you are fixing this problem. +- [Google HTML/CSS Style Guide](https://google.github.io/styleguide/htmlcssguide.html) +- [Google JavaScript Style Guide](https://google.github.io/styleguide/jsguide.html) -Keep this summary up-to-date as the PR evolves. \ -If your PR changes the UI, you must add **after** screenshots in the PR summary. \ -If you are not implementing a new feature, you should also post **before** screenshots for comparison. +#### Gitea Specific Guidelines -If you are implementing a new feature, your PR will only be merged if your screenshots are up to date.\ -Furthermore, feature PRs will only be merged if their summary contains a clear usage description (understandable for users) and testing description (understandable for reviewers). -You should strive to combine both into a single description. +- Every feature (`Fomantic-UI`/`jQuery` module) should be put in separate files/directories. +- HTML ids and classes should use **kebab-case** and contain 2-3 feature-related keywords. +- HTML ids and classes used in JavaScript should be unique across the entire project and contain 2-3 feature-related keywords. Use the `js-` prefix for classes that are only used in JavaScript. +- Avoid overwriting CSS styling for framework-provided classes. Use new class names with 2-3 feature-related keywords. Gitea's helper CSS classes in `helpers.less` could be useful. +- The backend can pass complex data to the frontend by using `ctx.PageData["myModuleData"] = map[]{}`, but do not expose entire models to the frontend to avoid leaking sensitive data. +- Simple and SEO-related pages should use Go HTML Template to generate static `Fomantic-UI` HTML output. More complex pages can use `Vue3`. +- 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)`. +- Use semantic elements. Prefer `