aboutsummaryrefslogtreecommitdiffstats
path: root/services
Commit message (Collapse)AuthorAgeFilesLines
* Fix SSPI user creation (#28948)KN4CK3R2024-01-271-7/+3
| | | | | | Fixes #28945 Setting the avatar is wrong and creating a random password is equal to leave it empty.
* Implement `MigrateRepository` for the actions notifier (#28920)Zettat1232024-01-251-0/+12
| | | | | | | Fixes #28699 This PR implements the `MigrateRepository` method for `actionsNotifier` to detect the schedules from the workflow files in the migrated repository.
* Allow to sync tags from admin dashboard (#28045)JakobDev2024-01-242-0/+67
| | | | | | | | | Inspired by #28043 This PR adds a option to the Admin Dashboard to sync all tags to the database. ![grafik](https://github.com/go-gitea/gitea/assets/15185051/26ac51ef-82a4-4fd9-a6a6-5aefec612ff6)
* Only migrate the first 255 chars of a Github issue title (#28902)JakobDev2024-01-241-1/+2
| | | Fixes #28846
* Fix `DeleteCollaboration` transaction behaviour (#28886)KN4CK3R2024-01-221-2/+5
| | | | | | | | | The method can't be called with an outer transaction because if the user is not a collaborator the outer transaction will be rolled back even if the inner transaction uses the no-error path. `has == 0` leads to `return nil` which cancels the transaction. A standalone call of this method does nothing but if used with an outer transaction, that will be canceled.
* Fix schedule not trigger bug because matching full ref name with short ref ↵Lunny Xiao2024-01-221-12/+16
| | | | | | | name (#28874) Fix #28533 Caused by #28691
* Fix branch list bug which displayed default branch twice (#28878)Lunny Xiao2024-01-211-3/+2
| | | Fix #28876
* Move doctor package from modules to services (#28856)Lunny Xiao2024-01-2017-0/+2386
|
* Add support for sha256 repositories (#23894)Adam Majer2024-01-192-11/+16
| | | | | | | | | | | | | | | | Currently only SHA1 repositories are supported by Gitea. This adds support for alternate SHA256 with the additional aim of easier support for additional hash types in the future. Fixes: #13794 Limited by: https://github.com/go-git/go-git/issues/899 Depend on: #28138 <img width="776" alt="图片" src="https://github.com/go-gitea/gitea/assets/81045/5448c9a7-608e-4341-a149-5dd0069c9447"> --------- Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: 6543 <6543@obermui.de>
* Fix some RPM registry flaws (#28782)KN4CK3R2024-01-192-17/+57
| | | | | | | | | | | | | | | | | | | Related #26984 (https://github.com/go-gitea/gitea/pull/26984#issuecomment-1889588912) Fix admin cleanup message. Fix models `Get` not respecting default values. Rebuild RPM repository files after cleanup. Do not add RPM group to package version name. Force stable sorting of Alpine/Debian/RPM repository data. Fix missing deferred `Close`. Add tests for multiple RPM groups. Removed non-cached `ReplaceAllStringRegex`. If there are multiple groups available, it's stated in the package installation screen: ![grafik](https://github.com/go-gitea/gitea/assets/1666336/8f132760-882c-4ab8-9678-77e47dfc4415)
* Retarget depending pulls when the parent branch is deleted (#28686)Viktor Kuzmin2024-01-171-0/+37
| | | | | | | | | | | | | | | | | | | | | | | | | | | Sometimes you need to work on a feature which depends on another (unmerged) feature. In this case, you may create a PR based on that feature instead of the main branch. Currently, such PRs will be closed without the possibility to reopen in case the parent feature is merged and its branch is deleted. Automatic target branch change make life a lot easier in such cases. Github and Bitbucket behave in such way. Example: $PR_1$: main <- feature1 $PR_2$: feature1 <- feature2 Currently, merging $PR_1$ and deleting its branch leads to $PR_2$ being closed without the possibility to reopen. This is both annoying and loses the review history when you open a new PR. With this change, $PR_2$ will change its target branch to main ($PR_2$: main <- feature2) after $PR_1$ has been merged and its branch has been deleted. This behavior is enabled by default but can be disabled. For security reasons, this target branch change will not be executed when merging PRs targeting another repo. Fixes #27062 Fixes #18408 --------- Co-authored-by: Denys Konovalov <kontakt@denyskon.de> Co-authored-by: delvh <dev.lh@web.de>
* Fix reverting a merge commit failing (#28794)Mihir Joshi2024-01-167-8/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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: ``` $ git update-index --refresh $ git read-tree -m 1f085d7ed8 1f085d7ed8 9933caed00 ```
* Remove trust model selection from repository creation on web page because it ↵Lunny Xiao2024-01-161-8/+0
| | | | | | | | | | | | | | | | | | can be changed in settings later (#28814) As more and more options can be set for creating the repository, I don't think we should put all of them into the creation web page which will make things look complicated and confusing. And I think we need some rules about how to decide which should/should not be put in creating a repository page. One rule I can imagine is if this option can be changed later and it's not a MUST on the creation, then it can be removed on the page. So I found trust model is the first one. This PR removed the trust model selections on creating a repository web page and kept others as before. This is also a preparation for #23894 which will add a choice about SHA1 or SHA256 that cannot be changed once the repository created.
* Rework markup link rendering (#26745)KN4CK3R2024-01-152-6/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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> --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Add branch protection setting for ignoring stale approvals (#28498)Jimmy Praet2024-01-152-0/+2
| | | | | | | | | | | | | | | | | | | | | | Fixes #27114. * In Gitea 1.12 (#9532), a "dismiss stale approvals" branch protection setting was introduced, for ignoring stale reviews when verifying the approval count of a pull request. * In Gitea 1.14 (#12674), the "dismiss review" feature was added. * This caused confusion with users (#25858), as "dismiss" now means 2 different things. * In Gitea 1.20 (#25882), the behavior of the "dismiss stale approvals" branch protection was modified to actually dismiss the stale review. For some users this new behavior of dismissing the stale reviews is not desirable. So this PR reintroduces the old behavior as a new "ignore stale approvals" branch protection setting. --------- Co-authored-by: delvh <dev.lh@web.de>
* Forbid removing the last admin user (#28337)yp053272024-01-151-1/+6
| | | Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Move more functions to db.Find (#28419)Lunny Xiao2024-01-156-11/+35
| | | | | | | | | Following #28220 This PR move more functions to use `db.Find`. --------- Co-authored-by: delvh <dev.lh@web.de>
* Fix schedule tasks bugs (#28691)Lunny Xiao2024-01-125-22/+131
| | | | | | | | | | | | | | | | Fix #28157 This PR fix the possible bugs about actions schedule. ## The Changes - 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.
* Support for grouping RPMs using paths (#26984)Exploding Dragon2024-01-121-22/+25
| | | | | | | | | | | | The current rpm repository places all packages in the same repository, and different systems (el7,f34) may hit packages that do not belong to this distribution ( #25304 ) , which now supports grouping of rpm. ![图片](https://github.com/go-gitea/gitea/assets/33776693/d1e1d99f-7799-4b2b-a19b-cb2a5c692914) Fixes #25304 . Fixes #27056 . Refactor: [#25866](https://github.com/go-gitea/gitea/pull/25866)
* Fix `convert.ToTeams` on empty input (#28426)KN4CK3R2024-01-112-26/+26
| | | | | Fixes #28420 Don't return `nil` if the input was empty.
* Concatenate error in `checkIfPRContentChanged` (#28731)Earl Warren2024-01-091-0/+4
| | | | | | | | | - If there's a error with the Git command in `checkIfPRContentChanged` the stderr wasn't concatendated to the error, which results in still not knowing why an error happend. - Adds concatenation for stderr to the returned error. - Ref: https://codeberg.org/forgejo/forgejo/issues/2077 Co-authored-by: Gusted <postmaster@gusted.xyz>
* Fix alpine package files are not rebuilt (#28638)Nanguan Lin2023-12-311-0/+5
| | | | | I noticed the `BuildAllRepositoryFiles` function under the Alpine folder is unused and I thought it was a bug. But I'm not sure about this. Was it on purpose?
* fix empty ref for cron workflow runs (#28640)Denys Konovalov2023-12-291-2/+3
| | | | | | Fix #27678 Please see https://github.com/go-gitea/gitea/issues/27678#issuecomment-1871445853 for details.
* Refactor timeutil package (#28623)wxiaoguang2023-12-281-5/+5
| | | | | 1. make names more readable 2. remove unused FormatLong/FormatShort 3. use `FormatDate` instead of `Format "2006-01-02"`
* Remove unnecessary syncbranchToDB with tests (#28624)Lunny Xiao2023-12-281-20/+9
| | | | | | #28361 introduced `syncBranchToDB` in `CreateNewBranchFromCommit`. This PR will revert the change because it's unnecessary. Every push will already be checked by `syncBranchToDB`. This PR also created a test to ensure it's right.
* Use known issue IID to generate new PR index number when migrating from ↵wxiaoguang2023-12-262-11/+45
| | | | | GitLab (#28616) Fix #13884
* Refactor deletion (#28610)delvh2023-12-256-8/+10
| | | | | | | | | | | | | | | | | | Introduce the new generic deletion methods - `func DeleteByID[T any](ctx context.Context, id int64) (int64, error)` - `func DeleteByIDs[T any](ctx context.Context, ids ...int64) error` - `func Delete[T any](ctx context.Context, opts FindOptions) (int64, error)` So, we no longer need any specific deletion method and can just use the generic ones instead. Replacement of #28450 Closes #28450 --------- Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Remove deadcode under models/issues (#28536)Nanguan Lin2023-12-191-1/+5
| | | | | | | Using the Go Official tool `golang.org/x/tools/cmd/deadcode@latest` mentioned by [go blog](https://go.dev/blog/deadcode). Just use `deadcode .` in the project root folder and it gives a list of unused functions. Though it has some false alarms. This PR removes dead code detected in `models/issues`.
* Always enable caches (#28527)Lunny Xiao2023-12-191-5/+0
| | | | | | | | | Nowadays, cache will be used on almost everywhere of Gitea and it cannot be disabled, otherwise some features will become unaviable. Then I think we can just remove the option for cache enable. That means cache cannot be disabled. But of course, we can still use cache configuration to set how should Gitea use the cache.
* Improve ObjectFormat interface (#28496)Lunny Xiao2023-12-192-6/+4
| | | | | | | | | | | | | | | | | | | | | | | The 4 functions are duplicated, especially as interface methods. I think we just need to keep `MustID` the only one and remove other 3. ``` MustID(b []byte) ObjectID MustIDFromString(s string) ObjectID NewID(b []byte) (ObjectID, error) NewIDFromString(s string) (ObjectID, error) ``` Introduced the new interfrace method `ComputeHash` which will replace the interface `HasherInterface`. Now we don't need to keep two interfaces. Reintroduced `git.NewIDFromString` and `git.MustIDFromString`. The new function will detect the hash length to decide which objectformat of it. If it's 40, then it's SHA1. If it's 64, then it's SHA256. This will be right if the commitID is a full one. So the parameter should be always a full commit id. @AdamMajer Please review.
* Update go dependencies (#28518)wxiaoguang2023-12-191-6/+12
| | | | | Update golang.org/x/crypto for CVE-2023-48795 and update other packages. `go-git` is not updated because it needs time to figure out why some tests fail.
* Bump google/go-github to v57 (#28514)Yevhen Pavlov2023-12-182-5/+5
|
* Add option to disable ambiguous unicode characters detection (#28454)wxiaoguang2023-12-172-6/+6
| | | | | | | | * Close #24483 * Close #28123 * Close #23682 * Close #23149 (maybe more)
* Adjust object format interface (#28469)Lunny Xiao2023-12-1721-67/+57
| | | | | | | - Remove `ObjectFormatID` - Remove function `ObjectFormatFromID`. - Use `Sha1ObjectFormat` directly but not a pointer because it's an empty struct. - Store `ObjectFormatName` in `repository` struct
* Abstract hash function usage (#28138)Adam Majer2023-12-1332-99/+147
| | | | | | Refactor Hash interfaces and centralize hash function. This will allow easier introduction of different hash function later on. This forms the "no-op" part of the SHA256 enablement patch.
* Fix possible nil pointer access (#28428)KN4CK3R2023-12-124-28/+14
| | | | There could be a nil pointer exception if the file is not found because that specific error is suppressed but not handled.
* Deprecate query string auth tokens (#28390)Jack Hay2023-12-121-7/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ## Changes - Add deprecation warning to `Token` and `AccessToken` authentication methods in swagger. - Add deprecation warning header to API response. Example: ``` HTTP/1.1 200 OK ... Warning: token and access_token API authentication is deprecated ... ``` - Add setting `DISABLE_QUERY_AUTH_TOKEN` to reject query string auth tokens entirely. Default is `false` ## Next steps - `DISABLE_QUERY_AUTH_TOKEN` should be true in a subsequent release and the methods should be removed in swagger - `DISABLE_QUERY_AUTH_TOKEN` should be removed and the implementation of the auth methods in question should be removed ## Open questions - Should there be further changes to the swagger documentation? Deprecation is not yet supported for security definitions (coming in [OpenAPI Spec version 3.2.0](https://github.com/OAI/OpenAPI-Specification/issues/2506)) - Should the API router logger sanitize urls that use `token` or `access_token`? (This is obviously an insufficient solution on its own) --------- Co-authored-by: delvh <dev.lh@web.de>
* Second part of refactor `db.Find` (#28194)Lunny Xiao2023-12-112-14/+9
| | | Continue of #27798 and move more functions to `db.Find` and `db.Count`.
* Actually recover from a panic in cron task (#28409)Earl Warren2023-12-101-5/+7
| | | | | | | | | | | | | | - Currently there's code to recover gracefully from panics that happen within the execution of cron tasks. However this recover code wasn't being run, because `RunWithShutdownContext` also contains code to recover from any panic and then gracefully shutdown Forgejo. Because `RunWithShutdownContext` registers that code as last, that would get run first which in this case is not behavior that we want. - Move the recover code to inside the function, so that is run first before `RunWithShutdownContext`'s recover code (which is now a noop). Fixes: https://codeberg.org/forgejo/forgejo/issues/1910 Co-authored-by: Gusted <postmaster@gusted.xyz>
* Also sync DB branches on push if necessary (#28361)Lunny Xiao2023-12-092-36/+66
| | | | | | | | | | | | | | | | | | | | | | | | | | Fix #28056 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.
* Remove GetByBean method because sometimes it's danger when query condition ↵Lunny Xiao2023-12-075-8/+6
| | | | | | | | | | | | | | | | | | | | parameter is zero and also introduce new generic methods (#28220) The function `GetByBean` has an obvious defect that when the fields are empty values, it will be ignored. Then users will get a wrong result which is possibly used to make a security problem. To avoid the possibility, this PR removed function `GetByBean` and all references. And some new generic functions have been introduced to be used. The recommand usage like below. ```go // if query an object according id obj, err := db.GetByID[Object](ctx, id) // query with other conditions obj, err := db.Get[Object](ctx, builder.Eq{"a": a, "b":b}) ```
* Fix migration panic due to an empty review comment diff (#28334)Nanguan Lin2023-12-051-1/+1
| | | | | | | | | | | | | | | | | Fix #28328 ``` func (p *PullRequestComment) GetDiffHunk() string { if p == nil || p.DiffHunk == nil { return "" } return *p.DiffHunk } ``` This function in the package `go-github` may return an empty diff. When it's empty, the following code will panic because it access `ss[1]` https://github.com/go-gitea/gitea/blob/ec1feedbf582b05b6a5e8c59fb2457f25d053ba2/services/migrations/gitea_uploader.go#L861-L867 https://github.com/go-gitea/gitea/blob/ec1feedbf582b05b6a5e8c59fb2457f25d053ba2/modules/git/diff.go#L97-L101
* Fix RPM/Debian signature key creation (#28352)KN4CK3R2023-12-052-4/+3
| | | | | | | Fixes #28324 The name parameter can't contain some characters (https://github.com/keybase/go-crypto/blob/master/openpgp/keys.go#L680) but is optional. Therefore just use an empty string.
* Fix missing issue search index update when changing status (#28325)Brecht Van Lommel2023-12-031-0/+22
| | | | | Changing an issue status, assignee, labels or milestone without also adding a comment would not update the index, resulting in wrong search results.
* Make pushUpdate error verbose (#28263)Earl Warren2023-11-301-1/+3
| | | | | | | | | | | - Push commits updates are run in a queue and updates can come from less traceable places such as Git over SSH, therefor add more information about on which repository the pushUpdate failed. Refs: https://codeberg.org/forgejo/forgejo/pulls/1723 (cherry picked from commit 37ab9460394800678d2208fed718e719d7a5d96f) Co-authored-by: Gusted <postmaster@gusted.xyz>
* Fix required error for token name (#28267)Earl Warren2023-11-291-1/+1
| | | | | | | | | - Say to the binding middleware which locale should be used for the required error. - Resolves https://codeberg.org/forgejo/forgejo/issues/1683 (cherry picked from commit 5a2d7966127b5639332038e9925d858ab54fc360) Co-authored-by: Gusted <postmaster@gusted.xyz>
* Fix comment permissions (#28213)Lunny Xiao2023-11-251-14/+4
| | | | This PR will fix some missed checks for private repositories' data on web routes and API routes.
* Use db.Find instead of writing methods for every object (#28084)Lunny Xiao2023-11-2417-32/+44
| | | | For those simple objects, it's unnecessary to write the find and count methods again and again.
* add skip ci functionality (#28075)Denys Konovalov2023-11-181-0/+25
| | | | | | | | | | | | Adds the possibility to skip workflow execution if the commit message contains a string like [skip ci] or similar. The default strings are the same as on GitHub, users can also set custom ones in app.ini Reference: https://docs.github.com/en/actions/managing-workflow-runs/skipping-workflow-runs Close #28020
* Fix Matrix and MSTeams nil dereference (#28089)KN4CK3R2023-11-1711-6/+155
| | | | | | | | | | Fixes #28088 Fixes #28094 Added missing tests. --------- Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>