summaryrefslogtreecommitdiffstats
path: root/modules
Commit message (Collapse)AuthorAgeFilesLines
* Add tests for db indexer in indexer_test.go (#27087)Nanguan Lin2023-09-161-131/+324
| | | | | | | | | | | | | | | | | | | | As described in the title. Some points: 1. Why need those tests? Because `buildIssueOverview` is not well tested, there are several continuous bugs in the issue overview webpage. 2. Why in indexer_test.go? It's hard to put those tests in `./modules/indexer/issue/db/db_test.go` because those tests need 'real' data in db mocked by fixtures instead of random data in `./modules/indexer/issue/internal/tests`. When using 'real' data(`unittest.PrepareTestDatabase`), `InitIssueIndexer` and the package `init()` function of `indexer` are required to init indexer. 3. Why only db? The other three indexer engines are well tested by random data and it's okay to also test them with 'real' data in db mocked by fixtures. Any follow-up PR is welcome. 4. Those tests are really basic, any more complicated tests are welcome. 5. I think it's also necessary to add tests in `TestAPISearchIssues` in`api_test_issue.go` and `TestIssues` in `home_test.go`
* Actions are no longer experimental, so enable them by default (#27054)Lunny Xiao2023-09-151-1/+1
| | | | This PR makes the actions enabled by default, so people will find it easier to enable actions in repository setting.
* More refactoring of `db.DefaultContext` (#27083)JakobDev2023-09-156-16/+21
| | | Next step of #27065
* Reduce usage of `db.DefaultContext` (#27073)JakobDev2023-09-145-10/+13
| | | | | | | | | | | | | | Part of #27065 This reduces the usage of `db.DefaultContext`. I think I've got enough files for the first PR. When this is merged, I will continue working on this. Considering how many files this PR affect, I hope it won't take to long to merge, so I don't end up in the merge conflict hell. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Remove the useless function `GetUserIssueStats` and move relevant tests to ↵Nanguan Lin2023-09-141-1/+82
| | | | | | | | | | | | | | | | | | | `indexer_test.go` (#27067) Since the issue indexer has been refactored, the issue overview webpage is built by the `buildIssueOverview` function and underlying `indexer.Search` function and `GetIssueStats` instead of `GetUserIssueStats`. So the function is no longer used. I moved the relevant tests to `indexer_test.go` and since the search option changed from `IssueOptions` to `SearchOptions`, most of the tests are useless now. We need more tests about the db indexer because those tests are highly connected with the issue overview webpage and now this page has several bugs. Any advice about those test cases is appreciated. --------- Co-authored-by: CaiCandong <50507092+CaiCandong@users.noreply.github.com>
* Replace 'userxx' with 'orgxx' in all test files when the user type is org ↵Nanguan Lin2023-09-141-15/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (#27052) Currently 'userxx' and 'orgxx' are both used as username in test files when the user type is org, which is confusing. This PR replaces all 'userxx' with 'orgxx' when the user type is org(`user.type==1`). Some non-trivial changes 1. Rename `user3` dir to `org3` in `tests/git-repositories-meta` 2. Change `end` in `issue reference` because 'org3' is one char shorter than 'user3' ![ksnip_20230913-112819](https://github.com/go-gitea/gitea/assets/70063547/442988c5-4cf4-49b8-aa01-4dd6bf0ca954) 3. Change the search result number of `user/repo2` because `user3/repo21` can't be searched now ![ksnip_20230913-112931](https://github.com/go-gitea/gitea/assets/70063547/d9ebeba4-479f-4110-9a85-825efbc981fd) 4. Change the first org name getting from API because the result is ordered by alphabet asc and now `org 17` is before `org25` ![JW8U7NIO(J$H _YCRB36H)T](https://github.com/go-gitea/gitea/assets/70063547/f55a685c-cf24-40e5-a87f-3a2327319548) ![)KFD411O4I8RB5ZOH7E0 Z3](https://github.com/go-gitea/gitea/assets/70063547/a0dc3299-249c-46f6-91cb-d15d4ee88dd5) Other modifications are just find all and replace all. Unit tests with SQLite are all passed. --------- Co-authored-by: caicandong <1290147055@qq.com>
* fix media description render for orgmode (#26895)Earl Warren2023-09-132-9/+34
| | | | | | | | | | | | | | | - In org mode you can specify an description for media via the following syntax `[[description][media link]]`. The description is then used as title or alt. - This patch fixes the rendering of the description by seperating the description and non-description cases and using `org.String()`. - Added unit tests. - Inspired by https://github.com/niklasfasching/go-org/blob/6eb20dbda93cb88c3503f7508dc78cbbc639378f/org/html_writer.go#L406-L427 - Resolves https://codeberg.org/Codeberg/Community/issues/848 (cherry picked from commit 8b8aab83113b34bade61964e2097ed497abc39e9) Co-authored-by: Gusted <postmaster@gusted.xyz>
* Update status and code index after changing the default branch (#27018)Nanguan Lin2023-09-131-1/+8
| | | | | | | | | | | Fix #26723 Add `ChangeDefaultBranch` to the `notifier` interface and implement it in `indexerNotifier`. So when changing the default branch, `indexerNotifier` sends a message to the `indexer queue` to update the index. --------- Co-authored-by: techknowlogick <matti@mdranta.net>
* Fix object storage path handling (#27024)wxiaoguang2023-09-132-14/+48
| | | | | | Object storage path rules: * No single `/` or `.`, use empty string for root path * Need to use trailing `/` for a list prefix to distinguish a "dir/"
* S3: log human readable error on connection failure (#26856)Earl Warren2023-09-122-0/+55
| | | | | | | | | | | | | | | | | | | | | | | | | | | Should BucketExists (HeadBucket) fail because of an error related to the connection rather than the existence of the bucket, no information is available and the admin is left guessing. https://docs.aws.amazon.com/AmazonS3/latest/API/API_HeadBucket.html > This action is useful to determine if a bucket exists and you have > permission to access it. The action returns a 200 OK if the bucket > exists and you have permission to access it. > > If the bucket does not exist or you do not have permission to access > it, the HEAD request returns a generic 400 Bad Request, 403 > Forbidden or 404 Not Found code. A message body is not included, so > you cannot determine the exception beyond these error codes. GetBucketVersioning is used instead and exclusively dedicated to asserting if using the connection does not return a BadRequest. If it does the NewMinioStorage logs an error and returns. Otherwise it keeps going knowing that BucketExists is not going to fail for reasons unrelated to the existence of the bucket and the permissions to access it. (cherry picked from commit d1df4b3bc62e5e61893a923f1c4b58f084eb03af) Refs: https://codeberg.org/forgejo/forgejo/issues/1338
* Fix context cache bug & enable context cache for dashabord commits' authors ↵Lunny Xiao2023-09-112-45/+21
| | | | | | | | | | | (#26991) Unfortunately, when a system setting hasn't been stored in the database, it cannot be cached. Meanwhile, this PR also uses context cache for push email avatar display which should avoid to read user table via email address again and again. According to my local test, this should reduce dashboard elapsed time from 150ms -> 80ms .
* Use secure cookie for HTTPS sites (#26999)wxiaoguang2023-09-111-1/+1
| | | | | | | | | | | If the AppURL(ROOT_URL) is an HTTPS URL, then the COOKIE_SECURE's default value should be true. And, if a user visits an "http" site with "https" AppURL, they won't be able to login, and they should have been warned. The only problem is that the "language" can't be set either in such case, while I think it is not a serious problem, and it could be fixed easily if needed. ![image](https://github.com/go-gitea/gitea/assets/2114189/7bc9a859-dcc1-467d-bc7c-1dd6a10389e3)
* Fix INI parsing for value with trailing slash (#26995)wxiaoguang2023-09-102-2/+20
| | | Fix #26977 (a temp fix)
* Clarify the git command Stdin hanging problem (#26967)wxiaoguang2023-09-082-17/+12
|
* Expanding documentation in queue.go (#26889)zareck2023-09-081-13/+48
| | | | | | | | | A set of terminology, along with a broader description, can help more people engage with the Gitea queue system, providing insights and ensuring its correct use. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* move repository deletion to service layer (#26948)Lunny Xiao2023-09-086-2/+12
| | | Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Replace `util.SliceXxx` with `slices.Xxx` (#26958)CaiCandong2023-09-075-95/+20
|
* Add reverseproxy auth for API back with default disabled (#26703)Lunny Xiao2023-09-071-0/+2
| | | | | | | | | | | | | | | This feature was removed by #22219 to avoid possible CSRF attack. This PR takes reverseproxy auth for API back but with default disabled. To prevent possbile CSRF attack, the responsibility will be the reverseproxy but not Gitea itself. For those want to enable this `ENABLE_REVERSE_PROXY_AUTHENTICATION_API`, they should know what they are doing. --------- Co-authored-by: Giteabot <teabot@gitea.io>
* Move createrepository from module to service layer (#26927)Lunny Xiao2023-09-068-454/+23
| | | | Repository creation depends on many models, so moving it to service layer is better.
* Artifacts retention and auto clean up (#26131)FuXiaoHei2023-09-061-4/+10
| | | | | | | | | | | | | | Currently, Artifact does not have an expiration and automatic cleanup mechanism, and this feature needs to be added. It contains the following key points: - [x] add global artifact retention days option in config file. Default value is 90 days. - [x] add cron task to clean up expired artifacts. It should run once a day. - [x] support custom retention period from `retention-days: 5` in `upload-artifact@v3`. - [x] artifacts link in actions view should be non-clickable text when expired.
* Fix the display of org level badges (#26504)yp053272023-09-062-0/+2
| | | | | | | | | | | Follow #24654 #22705 #24232 In some pages we still have missing badges, for example: ![image](https://github.com/go-gitea/gitea/assets/18380374/f57fae6d-95ad-4996-8881-160c9cd27768) ![image](https://github.com/go-gitea/gitea/assets/18380374/11e86d43-b715-4d14-bdf0-51bf8b5c7b01) ![image](https://github.com/go-gitea/gitea/assets/18380374/61c514e7-d8f6-4c93-a61f-60604619e3a7)
* Move notification interface to services layer (#26915)Lunny Xiao2023-09-053-636/+0
| | | Extract from #22266
* Move feed notification service layer (#26908)Lunny Xiao2023-09-053-511/+0
| | | Extract from #22266
* Move ui notification to service layer (#26907)Lunny Xiao2023-09-052-257/+0
| | | Extract from #22266
* Move indexer notification to service layer (#26906)Lunny Xiao2023-09-052-125/+0
| | | Extract from #22266
* Move mail notification logic to service layer (#26905)Lunny Xiao2023-09-052-207/+0
| | | Extract from #22266
* Use Go 1.21 and update dependencies (#26878)wxiaoguang2023-09-032-19/+2
| | | | | | To make sure Gitea's next release's lifecycle could have active Golang support. And min/max are builtin now.
* Refactor `og:description` to limit the max length (#26876)wxiaoguang2023-09-031-0/+5
| | | | | | | | 1. The `og:description` should be "a one to two sentence description of your object" * It shouldn't output all the user inputted content -- it would be pretty huge. * Maybe it only needs at most 300 bytes. 2. Do not render commit message as HTML
* restrict certificate type for builtin SSH server (#26789)Earl Warren2023-09-011-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | - While doing some sanity checks over OpenSSH's code for how they handle certificates authentication. I stumbled on an condition that checks the certificate type is really an user certificate on the server-side authentication. This checks seems to be a formality and just for the sake of good domain seperation, because an user and host certificate don't differ in their generation, verification or flags that can be included. - Add this check to the builtin SSH server to stay close to the unwritten SSH specification. - This is an breaking change for setups where the builtin SSH server is being used and for some reason host certificates were being used for authentication. - (cherry picked from commit de35b141b79a3d6efe2127ed2c73fd481515e481) Refs: https://codeberg.org/forgejo/forgejo/pulls/1172 ## :warning: BREAKING :warning: Like OpenSSH, the built-in SSH server will now only accept SSH user certificates, not server certificates. Co-authored-by: Gusted <postmaster@gusted.xyz> Co-authored-by: Giteabot <teabot@gitea.io>
* Avoid double-unescaping of form value (#26853)wxiaoguang2023-09-012-22/+4
| | | | | | | 1. The old `prepareQueryArg` did double-unescaping of form value. 2. By the way, remove the unnecessary `ctx.Flash = ...` in `MockContext`. Co-authored-by: Giteabot <teabot@gitea.io>
* Move web/api context related testing function into a separate package (#26859)wxiaoguang2023-09-011-5/+4
| | | | | | | | | Just like `models/unittest`, the testing helper functions should be in a separate package: `contexttest` And complete the TODO: > // TODO: move this function to other packages, because it depends on "models" package
* Render code blocks in repo description (#26830)silverwind2023-08-311-3/+2
| | | | | | | | | | Backtick syntax now works in repo description too. Also, I replaced the CSS for this was a new single class, making it more flexible and not dependent on a parent. Also, very slightly reduced font size from 16.8px to 16px. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Check blocklist for emails when adding them to account (#26812)techknowlogick2023-08-301-0/+25
|
* Use `Set[Type]` instead of `map[Type]bool/struct{}`. (#26804)KN4CK3R2023-08-302-17/+12
|
* Fix some slice append usages (#26778)Chongyi Zheng2023-08-291-1/+1
| | | Co-authored-by: delvh <dev.lh@web.de>
* Remove redundant nil check in `WalkGitLog` (#26773)Eng Zer Jun2023-08-291-17/+15
| | | | | | | | | | From the Go specification: > "1. For a nil slice, the number of iterations is 0." https://go.dev/ref/spec#For_range Therefore, an additional nil check for before the loop is unnecessary. Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
* Add fix incorrect can_create_org_repo for org owner team (#26683)yp053272023-08-291-0/+61
| | | | | | | | | | | Related to: #8312 #26491 In migration v109, we only added a new column `CanCreateOrgRepo` in Team table, but not initial the value of it. This may cause bug like #26491. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Reduce some allocations in type conversion (#26772)Chongyi Zheng2023-08-291-1/+1
|
* refactor(API): refactor secret creation and update functionality (#26751)Bo-Yi Wu2023-08-281-14/+2
| | | | | | | | | | | | | | | | | | | | According to the GitHub API Spec: https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28#create-or-update-an-organization-secret Merge the Create and Update secret into a single API. - Remove the `CreateSecretOption` struct and replace it with `CreateOrUpdateSecretOption` in `modules/structs/secret.go` - Update the `CreateOrUpdateOrgSecret` function in `routers/api/v1/org/action.go` to use `CreateOrUpdateSecretOption` instead of `UpdateSecretOption` - Remove the `CreateOrgSecret` function in `routers/api/v1/org/action.go` and replace it with `CreateOrUpdateOrgSecret` - Update the Swagger documentation in `routers/api/v1/swagger/options.go` and `templates/swagger/v1_json.tmpl` to reflect the changes in the struct names and function names Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
* Fix bug for ctx usage (#26762)Lunny Xiao2023-08-281-4/+4
| | | | | Regression from #26158 Fix #26684
* Expanded minimum RSA Keylength to 3072 (#26604)mainboarder2023-08-282-2/+2
| | | | | | | | | | | | | | | German Federal Office for Information Security requests in its technical guideline BSI TR-02102-1 RSA Keylength not shorter than 3000bits starting 2024, in the year 2023 3000bits as a recommendation. Gitea should request longer RSA Keys by default in favor of security and drop old clients which do not support longer keys. https://www.bsi.bund.de/SharedDocs/Downloads/DE/BSI/Publikationen/TechnischeRichtlinien/TR02102/BSI-TR-02102.pdf?__blob=publicationFile&v=9 - Page 19, Table 1.2 --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Use docs.gitea.com instead of docs.gitea.io (#26739)Lunny Xiao2023-08-273-8/+8
|
* Move `modules/mirror` to `services` (#26737)Chongyi Zheng2023-08-273-118/+0
| | | | | To solve the cyclic imports in a better way Closes #20261
* Make web context initialize correctly for different cases (#26726)wxiaoguang2023-08-253-29/+34
| | | | | | | The web context (modules/context.Context) is quite complex, it's difficult for the callers to initialize correctly. This PR introduces a `NewWebContext` function, to make sure the web context have the same behavior for different cases.
* add Upload URL to release API (#26663)Earl Warren2023-08-241-0/+1
| | | | | | | | | | | | - Resolves https://codeberg.org/forgejo/forgejo/issues/580 - Return a `upload_field` to any release API response, which points to the API URL for uploading new assets. - Adds unit test. - Adds integration testing to verify URL is returned correctly and that upload endpoint actually works --------- Co-authored-by: Gusted <postmaster@gusted.xyz>
* Add merge files files to GetCommitFileStatus (#20515)Laurent Cahour2023-08-2422-1/+38
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Hi, We'd like to add merge files files to GetCommitFileStatus fucntions so API returns the list of all the files associated to a merged pull request commit, like GitHub API does. The list of affectedFiles for an API commit is fetched from toCommit() function in routers/api/v1/repo/commits.go, and API was returning no file in case of a pull request with no conflict, or just files associated to the confict resolution, but NOT the full list of merged files. This would lead to situations where a CI polling a repo for changes could miss some file changes due to API returning an empty / partial list in case of such merged pull requests. (Hope this makes sense :) ) NOTE: I'd like to add a unittest in integrations/api_repo_git_commits_test.go but failed to understand how to add my own test bare repo so I can make a test on a merged pull request commit to check for affectedFiles. Is there a merged pull request in there that I could use maybe? Could someone please direct me to the relevant ressources with informations on how to do that please? Thanks for your time, Laurent. --------- Co-authored-by: Thomas Desveaux <desveaux.thomas@gmail.com>
* chore(actions): support cron schedule task (#26655)Lunny Xiao2023-08-241-4/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Replace #22751 1. only support the default branch in the repository setting. 2. autoload schedule data from the schedule table after starting the service. 3. support specific syntax like `@yearly`, `@monthly`, `@weekly`, `@daily`, `@hourly` ## How to use See the [GitHub Actions document](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule) for getting more detailed information. ```yaml on: schedule: - cron: '30 5 * * 1,3' - cron: '30 5 * * 2,4' jobs: test_schedule: runs-on: ubuntu-latest steps: - name: Not on Monday or Wednesday if: github.event.schedule != '30 5 * * 1,3' run: echo "This step will be skipped on Monday and Wednesday" - name: Every time run: echo "This step will always run" ``` Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com> --------- Co-authored-by: Jason Song <i@wolfogre.com> Co-authored-by: techknowlogick <techknowlogick@gitea.io> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* feat(API): update and delete secret for managing organization secrets (#26660)Bo-Yi Wu2023-08-241-0/+9
| | | | | | | | | | | | | | | | | | - Add `UpdateSecret` function to modify org or user repo secret - Add `DeleteSecret` function to delete secret from an organization - Add `UpdateSecretOption` struct for updating secret options - Add `UpdateOrgSecret` function to update a secret in an organization - Add `DeleteOrgSecret` function to delete a secret in an organization GitHub API 1. Update Org Secret: https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28#create-or-update-an-organization-secret 2. Delete Org Secret: https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28#delete-an-organization-secret --------- Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
* Fix counting and filtering on the dashboard page for issues (#26657)Jason Song2023-08-232-3/+51
| | | | | | | | | | | | | | | | | | This PR has multiple parts, and I didn't split them because it's not easy to test them separately since they are all about the dashboard page for issues. 1. Support counting issues via indexer to fix #26361 2. Fix repo selection so it also fixes #26653 3. Keep keywords in filter links. The first two are regressions of #26012. After: https://github.com/go-gitea/gitea/assets/9418365/71dfea7e-d9e2-42b6-851a-cc081435c946 Thanks to @CaiCandong for helping with some tests.
* feat: implement organization secret creation API (#26566)Bo-Yi Wu2023-08-221-1/+13
| | | | | | | | | | | | | - Add a new `CreateSecretOption` struct for creating secrets - Implement a `CreateOrgSecret` function to create a secret in an organization - Add a new route in `api.go` to handle the creation of organization secrets - Update the Swagger template to include the new `CreateOrgSecret` API endpoint --------- Signed-off-by: appleboy <appleboy.tw@gmail.com>