aboutsummaryrefslogtreecommitdiffstats
path: root/models
Commit message (Collapse)AuthorAgeFilesLines
* Get repo assignees and reviewers should ignore deactivated users (#30770) ↵65432024-04-302-9/+23
| | | | | | | | | | | | | (#30783) Backport https://github.com/go-gitea/gitea/pull/30770 If an user is deactivated, it should not be in the list of users who are suggested to be assigned or review-requested. old assignees or reviewers are not affected. --- *Sponsored by Kithara Software GmbH*
* Fix duplicate status check contexts (#30660) (#30776)Zettat1232024-04-302-25/+60
| | | | | | | | | | | | | | | | | | | | | Backport #30660. Caused by #30076. There may be some duplicate status check contexts when setting status checks for a branch protection rule. The duplicate contexts should be removed. Before: <img src="https://github.com/go-gitea/gitea/assets/15528715/97f4de2d-4868-47a3-8a99-5a180f9ac0a3" width="600px" /> After: <img src="https://github.com/go-gitea/gitea/assets/15528715/ff7289c5-9793-4090-ba31-e8cb3c85f8a3" width="600px" />
* Interpolate runs-on with variables when scheduling tasks(#30640) (#30672)sillyguodong2024-04-242-6/+21
| | | | | backport: #30640 Co-authored-by: Giteabot <teabot@gitea.io>
* Add a db consistency check to remove runners that do not belong to a ↵Zettat1232024-04-241-2/+24
| | | | | repository (#30614) (#30653) Backport #30614
* Fix wrong table name (#30557) (#30652)Lunny Xiao2024-04-234-8/+6
| | | | | | | | | Backport #30557 The table name should be `oauth2_application` but `o_auth2_application` Caused by https://github.com/go-gitea/gitea/pull/21316/files#diff-9610efbc608a41f1f2eaff5790423f0a187906f6ff0beb23a5e8d18366cc2ccfR38
* Use db.ListOptions directly instead of Paginator interface to make iteasier ↵Lunny Xiao2024-04-132-18/+10
| | | | | | | | | | | | | to use and fix performance of /pulls and /issues (#29990) (#30447) backport #29990 This PR uses `db.ListOptions` instead of `Paginor` to make the code simpler. And it also fixed the performance problem when viewing /pulls or /issues. Before the counting in fact will also do the search. Co-authored-by: Jason Song <i@wolfogre.com> Co-authored-by: silverwind <me@silverwind.io>
* Fix rename branch 500 when the target branch is deleted but exist in ↵Giteabot2024-04-121-6/+25
| | | | | | | | | | | database (#30430) (#30437) Backport #30430 by @lunny Fix #30428 --------- Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Check the token's owner and repository when registering a runner (#30406) ↵Zettat1232024-04-111-0/+3
| | | | | | | (#30412) Backport #30406 Fix #30378
* Avoid user does not exist error when detecting schedule actions when the ↵Giteabot2024-04-111-0/+3
| | | | | | | | | | | | | | | | | | | | commit author is an external user (#30357) (#30408) Backport #30357 by @yp05327 ![image](https://github.com/go-gitea/gitea/assets/18380374/ddf6ee84-2242-49b9-b066-bd8429ba4d76) When repo is a mirror, and commit author is an external user, then `GetUserByEmail` will return error. reproduce/test: - mirror Gitea to your instance - disable action and enable it again, this will trigger `DetectAndHandleSchedules` ps: also follow #24706, it only fixed normal runs, not scheduled runs. Co-authored-by: yp05327 <576951401@qq.com>
* No global variables (#30402)Jason Song2024-04-111-9/+2
| | | | | | | | | | | Fix #30361, regression of #29782 which is a backport, not the original #29468. #29468 did a small refactor which introduced a new function `GetVariablesOfRun`. However, it's designed for v1.22 which supports global variables. After backporting it to v1.21, it will still try to get global variables, which causes it to retrieve all variables.
* Fix missing 0 prefix of GPG key id (#30245) (#30247)Giteabot2024-04-023-7/+23
| | | | | | | | | | | | | | Backport #30245 by @KN4CK3R Fixes #30235 If the key id "front" byte has a single digit, `%X` is missing the 0 prefix. ` 38D1A3EADDBEA9C` instead of `038D1A3EADDBEA9C` When using the `IssuerFingerprint` slice `%X` is enough but I changed it to `%016X` too to be consistent. Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
* Move from `max( id )` to `max( index )` for latest commit statuses (#30076) ↵YR Chen2024-03-281-47/+73
| | | | | | | | | | | | | | | | | | | | (#30155) Backport https://github.com/go-gitea/gitea/pull/30076. This PR replaces the use of `max( id )`, and instead using ``max( `index` )`` for determining the latest commit status. Building business logic over an `auto_increment` primary key like `id` is risky and there’re already plenty of discussions on the Internet. There‘s no guarantee for `auto_increment` values to be monotonic, especially upon failures or with a cluster. In the specific case, we met the problem of commit statuses being outdated when using TiDB as the database. As [being documented](https://docs.pingcap.com/tidb/stable/auto-increment), `auto_increment` values assigned to an `insert` statement will only be monotonic on a per server (node) basis. Closes #30074.
* Load attachments for code comments (#30124) (#30126)yp053272024-03-271-0/+4
| | | backport #30124
* Fix misuse of `TxContext` (#30061) (#30062)Giteabot2024-03-252-1/+11
| | | | | | | | | | | | | | Backport #30061 by @wolfogre Help #29999, or its tests cannot pass. Also, add some comments to clarify the usage of `TxContext`. I don't check all usages of `TxContext` because there are too many (almost 140+). It's a better idea to replace them with `WithTx` instead of checking them one by one. However, that may be another refactoring PR. Co-authored-by: Jason Song <i@wolfogre.com>
* Respect DEFAULT_ORG_MEMBER_VISIBLE setting when adding creator to org ↵Giteabot2024-03-241-2/+3
| | | | | | | | | | | | (#30013) (#30035) Backport #30013 by @DrMaxNix This PR adds `setting.Service.DefaultOrgMemberVisible` value to dataset of user when the initial org creator is being added to the created org. Fixes #30012. Co-authored-by: DrMaxNix <mail@drmaxnix.de>
* Performance improvements for pull request list page (#29900) (#29972)Lunny Xiao2024-03-225-19/+45
| | | | | | | | | This PR will avoid load pullrequest.Issue twice in pull request list page. It will reduce x times database queries for those WIP pull requests. Partially fix #29585 Backport #29900
* Fix template error when comment review doesn't exist (#29888) (#29889)wxiaoguang2024-03-192-0/+17
| | | Backport #29888
* Fix user id column case (#29863) (#29867)Giteabot2024-03-171-2/+2
| | | | | | | Backport #29863 by @lng2020 Sometimes the column name is case-sensitive and it may cause 500. Co-authored-by: Nanguan Lin <nanguanlin6@gmail.com>
* Fix codeowner detected diff base branch to mergebase (#29783) (#29807)Lunny Xiao2024-03-172-83/+7
| | | | | | | | | | | | | | | Fix #29763 Backport #29783 This PR fixes 2 problems with CodeOwner in the pull request. - Don't use the pull request base branch but merge-base as a diff base to detect the code owner. - CodeOwner detection in fork repositories will be disabled because almost all the fork repositories will not change CODEOWNERS files but it should not be used on fork repositories' pull requests. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Make runs-on support variable expression (#29468) (#29782)sillyguodong2024-03-142-0/+72
| | | | | | | | | backport #29468 Close issue: https://gitea.com/gitea/act_runner/issues/445 Follow: https://gitea.com/gitea/act/pulls/91 Move `getSecretsOfTask` and `getVariablesOfTask` under models because of circular dependency issues.
* Fix bug hidden on CI and make ci failed if tests failure (#29254) (#29662)Lunny Xiao2024-03-096-11/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Backport #29254 The tests on migration tests failed but CI reports successfully https://github.com/go-gitea/gitea/actions/runs/7364373807/job/20044685969#step:8:141 This PR will fix the bug on migrations and also the CI hidden behaviour. The reason is on the Makefile `GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini $(GO) test $(GOTESTFLAGS) -tags='$(TEST_TAGS)' $(MIGRATE_TEST_PACKAGES)` will return the error exit code. But `for pkg in $(shell $(GO) list code.gitea.io/gitea/models/migrations/...); do \ GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' $$pkg; \ done` will not work. --------- Co-authored-by: Giteabot <teabot@gitea.io>
* Avoid issue info panic (#29625) (#29632)Giteabot2024-03-061-3/+7
| | | | | | | Backport #29625 by wxiaoguang Fix #29624 Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Add missing database transaction for new issue (#29490) (#29607)Lunny Xiao2024-03-051-2/+2
| | | | | | When creating an issue, inserting issue, assign users and set project should be in the same transaction. Backport #29490
* Only use supported sort order for "explore/users" page (#29430) (#29443)wxiaoguang2024-03-031-0/+3
| | | | | | | | | | | | | | Backport #29430 Thanks to inferenceus : some sort orders on the "explore/users" page could list users by their lastlogintime/updatetime. It leaks user's activity unintentionally. This PR makes that page only use "supported" sort orders. Removing the "sort orders" could also be a good solution, while IMO at the moment keeping the "create time" and "name" orders is also fine, in case some users would like to find a target user in the search result, the "sort order" might help.
* Fix incorrect relative/absolute URL usages (#29531) (#29547)Giteabot2024-03-021-3/+13
| | | | | | | | Backport #29531 by wxiaoguang Add two "HTMLURL" methods for PackageDescriptor. And rename "FullWebLink" to "VersionWebLink" Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Fix issue & comment history bugs (#29525) (#29527)Giteabot2024-03-022-6/+21
| | | | | | | | | | Backport #29525 by @wxiaoguang * Follow #17746: `HasIssueContentHistory` should use expr builder to make sure zero value (0) be respected. * Add "doer" check to make sure `canSoftDeleteContentHistory` only be called by sign-in users. Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Users with `read` permission of pull requests can be assigned too (#27263) ↵Giteabot2024-02-242-3/+5
| | | | | | | | | | (#29372) Backport #27263 by @lunny This PR will also keep the consistent between list assigned users and check assigned users. Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Fix gitea-action user avatar broken on edited menu (#29190) (#29307)yp053272024-02-221-1/+5
| | | | | Backport #29190 Fix #29178
* Workaround to clean up old reviews on creating a new one (#28554) (#29264)65432024-02-192-9/+39
| | | | | | | | close #28542 backport #28554 --- *Sponsored by Kithara Software GmbH*
* Fix bug when the linked account was disactived and list the linked accounts ↵Lunny Xiao2024-02-191-3/+7
| | | | | | | | | (#29263) The bug has been fixed on v1.22 but not backport to v1.21. This original PR have many refactors so I don't think it's necessary to backport all of them. Fix #28667
* Use ghost user if user was not found (#29161) (#29169)KN4CK3R2024-02-142-0/+12
| | | Backport #29161
* Dont load Review if Comment is CommentTypeReviewRequest (#28551) (#29160)65432024-02-133-1/+12
| | | | | | Backport #28551 RequestReview get deleted on review. So we don't have to try to load them on comments.
* Revert "Speed up loading the dashboard on mysql/mariadb (#28546)" (#29006) ↵Giteabot2024-02-011-6/+3
| | | | | | | | | | (#29007) Backport #29006 by @lunny This reverts commit fa8c3beb26acfcc7e732038c947225857ebcbf31. #28546 Because it seems performance become worse. Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Don't remove all mirror repository's releases when mirroring (#28817) (#28939)Giteabot2024-01-311-1/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Backport #28817 by @lunny Fix #22066 # Purpose This PR fix the releases will be deleted when mirror repository sync the tags. # The problem In the previous implementation of #19125. All releases record in databases of one mirror repository will be deleted before sync. Ref: https://github.com/go-gitea/gitea/pull/19125/files#diff-2aa04998a791c30e5a02b49a97c07fcd93d50e8b31640ce2ddb1afeebf605d02R481 # The Pros This PR introduced a new method which will load all releases from databases and all tags on git data into memory. And detect which tags needs to be inserted, which tags need to be updated or deleted. Only tags releases(IsTag=true) which are not included in git data will be deleted, only tags which sha1 changed will be updated. So it will not delete any real releases include drafts. # The Cons The drawback is the memory usage will be higher than before if there are many tags on this repository. This PR defined a special release struct to reduce columns loaded from database to memory. --------- Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Fix reverting a merge commit failing (#28794) (#28825)Mihir Joshi2024-01-213-1/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Backport https://github.com/go-gitea/gitea/pull/28794 Fixes #22236 --- Error occurring currently while trying to revert commit using read-tree -m approach: > 2022/12/26 16:04:43 ...rvices/pull/patch.go:240:AttemptThreeWayMerge() [E] [63a9c61a] Unable to run read-tree -m! Error: exit status 128 - fatal: this operation must be run in a work tree > - fatal: this operation must be run in a work tree We need to clone a non-bare repository for `git read-tree -m` to work. https://github.com/go-gitea/gitea/commit/bb371aee6ecf5e570cdf7b5f7f0d6f47a607a325 adds support to create a non-bare cloned temporary upload repository. After cloning a non-bare temporary upload repository, we [set default index](https://github.com/go-gitea/gitea/blob/main/services/repository/files/cherry_pick.go#L37) (`git read-tree HEAD`). This operation ends up resetting the git index file (see investigation details below), due to which, we need to call `git update-index --refresh` afterward. Here's the diff of the index file before and after we execute SetDefaultIndex: https://www.diffchecker.com/hyOP3eJy/ Notice the **ctime**, **mtime** are set to 0 after SetDefaultIndex. You can reproduce the same behavior using these steps: ```bash $ git clone https://try.gitea.io/me-heer/test.git -s -b main $ cd test $ git read-tree HEAD $ git read-tree -m 1f085d7ed8 1f085d7ed8 9933caed00 error: Entry '1' not uptodate. Cannot merge. ``` After which, we can fix like this: ```bash $ git update-index --refresh $ git read-tree -m 1f085d7ed8 1f085d7ed8 9933caed00 ```
* 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.