summaryrefslogtreecommitdiffstats
path: root/models
Commit message (Collapse)AuthorAgeFilesLines
* Rework markup link rendering (#26745) (#28803)KN4CK3R2024-01-162-5/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Backport #26745 Fixes #26548 This PR refactors the rendering of markup links. The old code uses `strings.Replace` to change some urls while the new code uses more context to decide which link should be generated. The added tests should ensure the same output for the old and new behaviour (besides the bug). We may need to refactor the rendering a bit more to make it clear how the different helper methods render the input string. There are lots of options (resolve links / images / mentions / git hashes / emojis / ...) but you don't really know what helper uses which options. For example, we currently support images in the user description which should not be allowed I think: <details> <summary>Profile</summary> https://try.gitea.io/KN4CK3R ![grafik](https://github.com/go-gitea/gitea/assets/1666336/109ae422-496d-4200-b52e-b3a528f553e5) </details>
* Forbid removing the last admin user (#28337) (#28793)Giteabot2024-01-162-4/+40
| | | | | | Backport #28337 by @yp05327 Co-authored-by: yp05327 <576951401@qq.com> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Fix `GetCommitStatuses` (#28787) (#28804)KN4CK3R2024-01-152-36/+46
| | | | | Backport #28787 Replaces #28802
* Fix when private user following user, private user will not be counted in ↵Giteabot2024-01-151-0/+2
| | | | | | | | | | | | | | | | | | | | | | | his own view (#28037) (#28792) Backport #28037 by @yp05327 Doer: asdasasdasasdasasdasasdasasdasasdasasdas (private user) Followed: TestUser (public user) Before: (From doer's view) ![image](https://github.com/go-gitea/gitea/assets/18380374/9ba16b3b-068c-43c5-a3dd-e3343b5b32f2) (From followed user's view, can see doer) ![image](https://github.com/go-gitea/gitea/assets/18380374/dfd1b564-d689-4393-b3d3-1e6bf52c94ba) After: (From doer's view) ![image](https://github.com/go-gitea/gitea/assets/18380374/1c85c1d1-c9f7-40c8-948c-145f7cae9a04) Co-authored-by: yp05327 <576951401@qq.com>
* Speed up loading the dashboard on mysql/mariadb (#28546) (#28784)Giteabot2024-01-151-3/+6
| | | | | | | Backport #28546 by @lunny Fixes #28155 Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Fix schedule tasks bugs (#28691) (#28780)Lunny Xiao2024-01-146-34/+35
| | | | | | | | | | | | | | Fix #28157 Backport #28691 This PR fix the possible bugs about actions schedule. - Move `UpdateRepositoryUnit` and `SetRepoDefaultBranch` from models to service layer - Remove schedules plan from database and cancel waiting & running schedules tasks in this repository when actions unit has been disabled or global disabled. - Remove schedules plan from database and cancel waiting & running schedules tasks in this repository when default branch changed.
* Upgrade xorm to new version which supported update join for all supported ↵Giteabot2023-12-311-8/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | databases (#28590) (#28668) Backport #28590 by @lunny Fix https://github.com/go-gitea/gitea/pull/28547#issuecomment-1867740842 Since https://gitea.com/xorm/xorm/pulls/2383 merged, xorm now supports UPDATE JOIN. To keep consistent from different databases, xorm use `engine.Join().Update`, but the actural generated SQL are different between different databases. For MySQL, it's `UPDATE talbe1 JOIN table2 ON join_conditions SET xxx Where xxx`. For MSSQL, it's `UPDATE table1 SET xxx FROM TABLE1, TABLE2 WHERE join_conditions`. For SQLITE per https://www.sqlite.org/lang_update.html, sqlite support `UPDATE table1 SET xxx FROM table2 WHERE join conditions` from 3.33.0(2020-8-14). POSTGRES is the same as SQLITE. Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Avoid cycle-redirecting user/login page (#28636) (#28658)wxiaoguang2023-12-302-6/+0
| | | | | Backport #28636 Fix #28231, and remove some unused code.
* Revert "improve possible performance bottleneck (#28547)" (#28593) (#28608)Giteabot2023-12-251-3/+8
| | | | | | | | | | | | Backport #28593 by @lunny This reverts commit b35d3fddfac389a7be401a63b4e1283dd74af681. This is totally wrong. I think `Update join` hasn't been supported well by xorm. I just revert the PR and will try to send another one. Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* improve possible performance bottleneck (#28547) (#28578)Giteabot2023-12-211-8/+3
| | | | | | | Backport #28547 by @lunny Replace #28500 Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Fix inperformant query on retrifing review from database. (#28552) (#28562)Giteabot2023-12-201-8/+10
| | | | | | | | | | | Backport #28552 by @6543 can we please PLEAS PLEASE only use raw SQL statements if it is relay needed!!! source is https://github.com/go-gitea/gitea/pull/28544 (before refactoring) Co-authored-by: 6543 <m.huber@kithara.com>
* Only check online runner when detecting matching runners in workflows ↵Giteabot2023-12-191-2/+15
| | | | | | | | | | | | | | | | | (#28286) (#28512) Backport #28286 by @yp05327 Mentioned: [#28277](https://github.com/go-gitea/gitea/issues/28277#issuecomment-1831325276) We should only check online runner when detecting matching runners in workflows, as if runner is not online, the workflow will not run. ![image](https://github.com/go-gitea/gitea/assets/18380374/11855e9d-7241-4b7a-b8d7-49dbb94ba1c5) Co-authored-by: yp05327 <576951401@qq.com>
* Refactor SSH clone URL generation code (#28421) (#28480)Giteabot2023-12-152-13/+42
| | | | | | | Backport #28421 by wxiaoguang Refactor the code and add tests, keep the old logic. Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Retry SSH key verification with additional CRLF if it failed (#28392) (#28464)Giteabot2023-12-141-4/+9
| | | | | | | | | | | Backport #28392 by @nekrondev Windows-based shells will add a CRLF when piping the token into ssh-keygen command resulting in verification error. This resolves #21527. Co-authored-by: nekrondev <heiko@noordsee.de> Co-authored-by: Heiko Besemann <heiko.besemann@qbeyond.de> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Also sync DB branches on push if necessary (#28361) (#28403)Lunny Xiao2023-12-116-24/+62
| | | | | | | | | | | | | | | | | | | | | | | | | | | Fix #28056 Backport #28361 This PR will check whether the repo has zero branch when pushing a branch. If that, it means this repository hasn't been synced. The reason caused that is after user upgrade from v1.20 -> v1.21, he just push branches without visit the repository user interface. Because all repositories routers will check whether a branches sync is necessary but push has not such check. For every repository, it has two states, synced or not synced. If there is zero branch for a repository, then it will be assumed as non-sync state. Otherwise, it's synced state. So if we think it's synced, we just need to update branch/insert new branch. Otherwise do a full sync. So that, for every push, there will be almost no extra load added. It's high performance than yours. For the implementation, we in fact will try to update the branch first, if updated success with affect records > 0, then all are done. Because that means the branch has been in the database. If no record is affected, that means the branch does not exist in database. So there are two possibilities. One is this is a new branch, then we just need to insert the record. Another is the branches haven't been synced, then we need to sync all the branches into database.
* enable system users search via the API (#28013) (#28018)Giteabot2023-12-081-0/+1
| | | | | | | | | | | | Backport #28013 by @earl-warren Refs: https://codeberg.org/forgejo/forgejo/issues/1403 (cherry picked from commit dd4d17c159eaf8b642aa9e6105b0532e25972bb7) --------- Co-authored-by: Earl Warren <109468362+earl-warren@users.noreply.github.com> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* handle repository.size column being NULL in migration v263 (#28336) (#28363)Giteabot2023-12-051-1/+6
| | | | Co-authored-by: Nate Levesque <nate@thenaterhood.com>
* Increase "version" when update the setting value to a same value as before ↵Giteabot2023-11-282-1/+13
| | | | | | | | | | (#28243) (#28244) Backport #28243 Setting the same value should not trigger DuplicateKey error, and the "version" should be increased Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Fix comment permissions (#28213) (#28216)Lunny Xiao2023-11-2510-61/+96
| | | | | | | backport #28213 This PR will fix some missed checks for private repositories' data on web routes and API routes.
* Fix no ActionTaskOutput table waring (#28149) (#28152)Giteabot2023-11-211-0/+4
| | | | | | | | | | | | | | | | | | | Backport #28149 by @yp05327 Reproduce: - Create a new Gitea instance - Register a runner - Create a repo and add a workflow - Check the log, you will see warnings: ![image](https://github.com/go-gitea/gitea/assets/18380374/5f1278e0-114b-48bc-8113-8ba1404d9975) It comes from: ![image](https://github.com/go-gitea/gitea/assets/18380374/c2807831-e137-4229-9536-87f6114c8a5b) The reason is that we forgot registering `ActionTaskOutput` model. So `action_table_output` table will be missing in your db. Co-authored-by: yp05327 <576951401@qq.com>
* Fix system config cache expiration timing (#28072) (#28090)Giteabot2023-11-161-8/+10
| | | | | | | | | | Backport #28072 To avoid unnecessary database access, the `cacheTime` should always be set if the revision has been checked. Fix #28057 Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Restricted users only see repos in orgs which their team was assigned to ↵Giteabot2023-11-141-5/+5
| | | | | | | | | | | (#28025) (#28051) Backport #28025 by @6543 --- *Sponsored by Kithara Software GmbH* Co-authored-by: 6543 <m.huber@kithara.com>
* enable system users for comment.LoadPoster (#28014) (#28032)Giteabot2023-11-141-1/+1
| | | | | | | | | | | | | | | | Backport #28014 by @earl-warren System users (Ghost, ActionsUser, etc) have a negative id and may be the author of a comment, either because it was created by a now deleted user or via an action using a transient token. The GetPossibleUserByID function has special cases related to system users and will not fail if given a negative id. Refs: https://codeberg.org/forgejo/forgejo/issues/1425 (cherry picked from commit 6a2d2fa24390116d31ae2507c0a93d423f690b7b) Co-authored-by: Earl Warren <109468362+earl-warren@users.noreply.github.com>
* Fix wrong xorm Delete usage(backport for 1.21) (#28002)Nanguan Lin2023-11-121-1/+1
| | | | | manually backport for https://github.com/go-gitea/gitea/pull/27995 The conflict is `ctx` and `db.Defaultctx`.
* Fix 500 when deleting a dismissed review (#27903) (#27910)Giteabot2023-11-052-0/+40
| | | | | | | | Backport #27903 by @lng2020 Fix #27767 Add a test to ensure its behavior Co-authored-by: Nanguan Lin <70063547+lng2020@users.noreply.github.com>
* Remove action runners on user deletion (#27902) (#27908)Giteabot2023-11-051-0/+24
| | | | | | | | | | | | | Backport #27902 by @earl-warren - On user deletion, delete action runners that the user has created. - Add a database consistency check to remove action runners that have nonexistent belonging owner. - Resolves https://codeberg.org/forgejo/forgejo/issues/1720 (cherry picked from commit 009ca7223dab054f7f760b7ccae69e745eebfabb) Co-authored-by: Earl Warren <109468362+earl-warren@users.noreply.github.com> Co-authored-by: Gusted <postmaster@gusted.xyz>
* Delete repos of org when purge delete user (#27273) (#27728)65432023-11-011-2/+2
| | | | | | | | | Fixes https://codeberg.org/forgejo/forgejo/issues/1514 Backports #27273 --------- Co-authored-by: JakobDev <jakobdev@gmx.de>
* Upgrade xorm to 1.3.4 (#27807) (#27813)Giteabot2023-10-271-1/+1
| | | | | | | | | | | Backport #27807 by @lng2020 Noticeable change: Remove the `OrderBy("1") ` [patch](https://github.com/go-gitea/gitea/pull/27673#issuecomment-1768570142) for mssql since xorm has [fixed it](https://gitea.com/xorm/xorm/commit/0f085408afd85707635eadb2294ab52be04f3c0f). Co-authored-by: Nanguan Lin <70063547+lng2020@users.noreply.github.com>
* Upgrade xorm (#27673) (#27691)Giteabot2023-10-192-2/+10
| | | | | | | Backport #27673 by @lng2020 Related to https://gitea.com/xorm/xorm/pulls/2341 Co-authored-by: Nanguan Lin <70063547+lng2020@users.noreply.github.com>
* Respect SSH.KeygenPath option when calculating ssh key fingerprints (#27536) ↵Giteabot2023-10-101-1/+1
| | | | | | | | | (#27551) Backport #27536 by @picsel2 Fixes #27535 Co-authored-by: Sebastian Grabowski <sebastian@grabel.de>
* Restore warning commit status (#27504) (#27529)Giteabot2023-10-092-3/+4
| | | | | | | | | | | | | Backport #27504 by @silverwind Partial revert of https://github.com/go-gitea/gitea/pull/25839. This commit status is used by a number of external integrations, so I think we should not remove it (See https://github.com/go-gitea/gitea/pull/25839#issuecomment-1729002077). This is a rare case where an existing migration needed to be alterted to avoid data loss. Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: delvh <dev.lh@web.de>
* Don't let API add 2 exclusive labels from same scope (#27433) (#27460)Giteabot2023-10-062-0/+39
| | | | | | | Backport #27433 by @JakobDev Fixes #27380 Co-authored-by: JakobDev <jakobdev@gmx.de>
* Refactor system setting (#27000) (#27452)Giteabot2023-10-059-384/+174
| | | | | | | | | | | | | | | | Backport #27000 by @wxiaoguang This PR reduces the complexity of the system setting system. It only needs one line to introduce a new option, and the option can be used anywhere out-of-box. It is still high-performant (and more performant) because the config values are cached in the config system. ![image](https://github.com/go-gitea/gitea/assets/2114189/f8cdd743-1145-41ab-9f8f-3996aa97d440) Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Add Index to `action.user_id` (#27403) (#27425)Giteabot2023-10-043-1/+19
| | | | | | | | Backport #27403 by @JakobDev Another Column that needs a Index. Found at https://codeberg.org/forgejo/discussions/issues/61#issuecomment-1258744. Co-authored-by: JakobDev <jakobdev@gmx.de>
* Don't use subselect in `DeleteIssuesByRepoID` (#27332) (#27408)Giteabot2023-10-031-64/+79
| | | | | | | | | Backport #27332 by @JakobDev Part of https://codeberg.org/forgejo/discussions/issues/61 This is workaround for a bug in MariaDB Co-authored-by: JakobDev <jakobdev@gmx.de>
* Allow get release download files and lfs files with oauth2 token format ↵Giteabot2023-10-012-0/+27
| | | | | | | | | | (#26430) (#27379) Backport #26430 by @lunny Fix #26165 Fix #25257 Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* More `db.DefaultContext` refactor (#27265) (#27347)Giteabot2023-09-2921-231/+230
| | | | | | | | | | | Backport #27265 by @JakobDev Part of #27065 This PR touches functions used in templates. As templates are not static typed, errors are harder to find, but I hope I catch it all. I think some tests from other persons do not hurt. Co-authored-by: JakobDev <jakobdev@gmx.de>
* Add logs for data broken of comment review (#27326) (#27345)Giteabot2023-09-291-27/+9
| | | | | | | Backport #27326 by @lunny Fix #27306 Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Add Index to `comment.dependent_issue_id` (#27325) (#27340)Giteabot2023-09-293-1/+19
| | | | | | | | Backport #27325 by @JakobDev This Column is missing index. It is used by [issue_service.deleteIssue](https://github.com/go-gitea/gitea/blob/7ea2a910cebaf51cfd13c0941029c404e408ae54/services/issue/issue.go#L300). Co-authored-by: JakobDev <jakobdev@gmx.de>
* Fix the approval count of PR when there is no protection branch rule ↵Giteabot2023-09-291-8/+17
| | | | | | | | | | | (#27272) (#27343) Backport #27272 by @lng2020 As title ![ksnip_20230926-115158](https://github.com/go-gitea/gitea/assets/70063547/a60be44a-06ad-421e-ba27-e4e0adfa5db7) Co-authored-by: Nanguan Lin <70063547+lng2020@users.noreply.github.com>
* Redefine the meaning of column is_active to make Actions Registration Token ↵Giteabot2023-09-281-8/+18
| | | | | | | | | | | | | | | | | | | generation easier (#27143) (#27304) Backport #27143 by @lunny Partially Fix #25041 This PR redefined the meaning of column `is_active` in table `action_runner_token`. Before this PR, `is_active` means whether it has been used by any runner. If it's true, other runner cannot use it to register again. In this PR, `is_active` means whether it's validated to be used to register runner. And if it's true, then it can be used to register runners until it become false. When creating a new `is_active` register token, any previous tokens will be set `is_active` to false. Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Fix yaml test (#27297) (#27303)Giteabot2023-09-272-3/+6
| | | | | Backport #27297 by @lunny Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Fix more yaml lint errors (#27284) (#27288)Giteabot2023-09-2614-25/+21
| | | | | | | Backport #27284 by @lunny Fix #27268 Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Another round of `db.DefaultContext` refactor (#27103) (#27262)Giteabot2023-09-2523-105/+114
| | | | | | | | Backport #27103 by @JakobDev Part of #27065 Co-authored-by: JakobDev <jakobdev@gmx.de> Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
* Quote table `release` in sql queries (#27205) (#27218)Giteabot2023-09-231-5/+5
| | | | | | | | | | | | | | Backport #27205 by @KN4CK3R Fixes #27174 `release` is a reserved keyword in MySql. I can't reproduce the issue on my setup and we have a test for that code but it seems there can be setups where it fails. https://github.com/go-gitea/gitea/blob/a101dbaa7952e359843c6d8303ca24a0e63c865c/tests/integration/repo_activity_test.go#L45-L46 Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
* Fix review request number and add more tests (#27104) (#27168)Giteabot2023-09-218-4/+81
| | | | | | | | | | | | | | | | | | | | | Backport #27104 by @lng2020 fix #27019 ## testfixture yml 1. add issue20(a pr issue) in repo 23, org 17 2. add user15 to team 9 3. add four reviews about issue20 ## test case add two tests that are described with code comments the code before pr #26784 failed the first test <img width="479" alt="image" src="https://github.com/go-gitea/gitea/assets/70063547/1d9b5787-11b4-4c4d-931f-6a9869547f35"> current code failed the second test(as mentioned in #27019) <img width="484" alt="image" src="https://github.com/go-gitea/gitea/assets/70063547/05608055-7587-43d1-bae1-92c688270819"> Any advice is appreciated. Co-authored-by: Nanguan Lin <70063547+lng2020@users.noreply.github.com> Co-authored-by: CaiCandong <50507092+CaiCandong@users.noreply.github.com>
* Add index to `issue_user.issue_id` (#27154) (#27158)Giteabot2023-09-213-1/+19
| | | | | | | | | | | | | | | | Backport #27154 by @JakobDev This fixes a performance bottleneck. It was discovered by Codeberg. Every where query on that table (which has grown big over time) uses this column, but there is no index on it. See this part of the log which was posted on Matrix: ``` 2023/09/10 00:52:01 ...rs/web/repo/issue.go:1446:ViewIssue() [W] [Slow SQL Query] UPDATE `issue_user` SET is_read=? WHERE uid=? AND issue_id=? [true x y] - 51.395434887s 2023/09/10 00:52:01 ...rs/web/repo/issue.go:1447:ViewIssue() [E] ReadBy: Error 1205 (HY000): Lock wait timeout exceeded; try restarting transaction 2023/09/10 00:52:01 ...eb/routing/logger.go:102:func1() [I] router: completed GET /Codeberg/Community/issues/1201 for [::ffff:xxx]:0, 500 Internal Server Error in 52384.2ms @ repo/issue.go:1256(repo.ViewIssue) ``` Co-authored-by: JakobDev <jakobdev@gmx.de>
* Fix wrong xorm get usage on migration (#27111)Lunny Xiao2023-09-181-19/+14
| | | | | | | | | | | | | | | | | | Fix the bug on try.gitea.io ```log 2023/09/18 01:48:41 ...ations/migrations.go:635:Migrate() [I] Migration[276]: Add RemoteAddress to mirrors 2023/09/18 01:48:41 routers/common/db.go:34:InitDBEngine() [E] ORM engine initialization attempt #7/10 failed. Error: migrate: migration[276]: Add RemoteAddress to mirrors failed: exit status 128 - fatal: not a git repository (or any parent up to mount point /) Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set). - fatal: not a git repository (or any parent up to mount point /) Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set). ``` Caused by #26952 --------- Co-authored-by: Jason Song <i@wolfogre.com>
* Search branches (#27055)Lunny Xiao2023-09-171-0/+4
| | | | | | | | | Resolve #25233 <img width="1315" alt="图片" src="https://github.com/go-gitea/gitea/assets/81045/3ba59b58-471a-4e1b-985c-87edac2268c0"> <img width="1297" alt="图片" src="https://github.com/go-gitea/gitea/assets/81045/b6caa12f-323b-4f70-9c44-ef91cb71a26c">
* Fix wrong migration for email address (#27106)Lunny Xiao2023-09-171-18/+70
| | | | | On Iterate, `sess` should not be used in the closure function body. Caused by #26952