aboutsummaryrefslogtreecommitdiffstats
path: root/routers/api
Commit message (Collapse)AuthorAgeFilesLines
* Updates to the API for archived repos (#27149)JakobDev2023-09-2112-31/+69
|
* Fix organization field being null in POST /orgs/{orgid}/teams (#27150)Dionysios Kakouris2023-09-211-1/+1
| | | | | | | | | | | | | Similarly to the fix in https://github.com/go-gitea/gitea/pull/24694, this addresses the team creation not returning the organization information in the response. This fix is connected to the [issue](https://gitea.com/gitea/terraform-provider-gitea/issues/27) discovered in the terraform provider. Moreover, the [documentation](https://docs.gitea.com/api/1.20/#tag/organization/operation/orgCreateTeam) suggests that the response body should include the `organization` field (currently being `null`).
* Fix token endpoints ignore specified account (#27080)CaiCandong2023-09-182-4/+20
| | | | | | | | | Fix #26234 close #26323 close #27040 --------- Co-authored-by: silverwind <me@silverwind.io>
* Make SSPI auth mockable (#27036)wxiaoguang2023-09-173-30/+4
| | | | | | Before, the SSPI auth is only complied for Windows, it's difficult to test and it breaks a lot. Now, make the SSPI auth mockable and testable.
* Add `RemoteAddress` to mirrors (#26952)KN4CK3R2023-09-161-5/+12
| | | | | This PR adds a new field `RemoteAddress` to both mirror types which contains the sanitized remote address for easier (database) access to that information. Will be used in the audit PR if merged.
* Next round of `db.DefaultContext` refactor (#27089)JakobDev2023-09-1612-38/+38
| | | Part of #27065
* Allow empty Conan files (#27092)KN4CK3R2023-09-151-7/+2
| | | | | | | Fixes #27090 Looks like the Conan upload process has changed since last year. The empty uploads don't occur anymore.
* More refactoring of `db.DefaultContext` (#27083)JakobDev2023-09-1518-30/+31
| | | Next step of #27065
* Reduce usage of `db.DefaultContext` (#27073)JakobDev2023-09-1413-25/+25
| | | | | | | | | | | | | | 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>
* Add missing 404 response to Swagger (#27038)JakobDev2023-09-1345-0/+300
| | | | | Most middleware throw a 404 in case something is not found e.g. a Repo that is not existing. But most API endpoints don't include the 404 response in their documentation. This PR changes this.
* Extract auth middleware from service (#27028)KN4CK3R2023-09-121-2/+103
| | | | | | Related #27027 Extract the router logic from `services/auth/middleware.go` into `routers/web` <-> `routers/common` <-> `routers/api`.
* Move some functions to service layer (#26969)Lunny Xiao2023-09-081-2/+2
|
* Add a new column schedule_id for action_run to track (#26975)Lunny Xiao2023-09-081-1/+7
| | | | | | | | Fix #26971 And the UI now will display it's scheduled but not triggered by a push. <img width="954" alt="图片" src="https://github.com/go-gitea/gitea/assets/81045/d211845c-457e-4c3e-af1f-a0d654d3f365">
* move repository deletion to service layer (#26948)Lunny Xiao2023-09-083-7/+8
| | | Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Replace `util.SliceXxx` with `slices.Xxx` (#26958)CaiCandong2023-09-072-2/+4
|
* Add reverseproxy auth for API back with default disabled (#26703)Lunny Xiao2023-09-071-2/+8
| | | | | | | | | | | | | | | 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-063-5/+4
| | | | Repository creation depends on many models, so moving it to service layer is better.
* Artifacts retention and auto clean up (#26131)FuXiaoHei2023-09-062-5/+25
| | | | | | | | | | | | | | 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.
* Move notification interface to services layer (#26915)Lunny Xiao2023-09-058-21/+21
| | | Extract from #22266
* Remove `Named` interface (#26913)KN4CK3R2023-09-054-0/+8
| | | | `Named` is implemented by every `Method` and future implementations should implement the method too.
* Refactor secrets modification logic (#26873)KN4CK3R2023-09-053-90/+86
| | | | - Share code between web and api - Add some tests
* Add missing `reqToken()` to notifications endpoints (#26914)JakobDev2023-09-051-3/+3
| | | | | | | | They currently throw a Internal Server Error when you use them without a token. Now they correctly return a `token is required` error. This is no security issue. If you use this endpoints with a token that don't have the correct permission, you get the correct error. This is not affected by this PR.
* feat(API): add routes and functions for managing user's secrets (#26909)Bo-Yi Wu2023-09-052-0/+112
| | | | | | | | | | | | | - Add routes for creating or updating a user's actions secrets in `routers/api/v1/api.go` - Add a new file `routers/api/v1/user/action.go` with functions for creating or updating a user's secrets and deleting a user's secret - Modify the `templates/swagger/v1_json.tmpl` file to include the routes for creating or updating a user's secrets and deleting a user's secret --------- Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com> Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
* Allow users with write permissions for issues to add attachments with API ↵Zettat1232023-09-011-1/+1
| | | | | | | | | (#26837) Fixes #24944 Since a user with write permissions for issues can add attachments to an issue via the the web interface, the user should also be able to add attachments via the API
* feat(API): add secret deletion functionality for repository (#26808)Bo-Yi Wu2023-09-013-4/+63
| | | | | | | | | | | | | | | - Modify the `CreateOrUpdateSecret` function in `api.go` to include a `Delete` operation for the secret - Modify the `DeleteOrgSecret` function in `action.go` to include a `DeleteSecret` operation for the organization - Modify the `DeleteSecret` function in `action.go` to include a `DeleteSecret` operation for the repository - Modify the `v1_json.tmpl` template file to update the `operationId` and `summary` for the `deleteSecret` operation in both the organization and repository sections --------- Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
* Move web/api context related testing function into a separate package (#26859)wxiaoguang2023-09-013-17/+17
| | | | | | | | | 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
* Use `Set[Type]` instead of `map[Type]bool/struct{}`. (#26804)KN4CK3R2023-08-301-5/+3
|
* Include the GITHUB_TOKEN/GITEA_TOKEN secret for fork pull requests (#26759)js6pak2023-08-291-8/+5
| | | | | | | | | | | | | | | | | | | | | | | Include `GITHUB_TOKEN`/`GITEA_TOKEN` secrets for actions triggered by pull requests This makes it consistent with the environment variables which you can already access ```shell echo env: $GITHUB_TOKEN echo expression: ${{ secrets.GITHUB_TOKEN }} ``` before ![image](https://github.com/go-gitea/gitea/assets/35262707/b6f750f6-3995-40f0-b8aa-df01e7997c37) after ![image](https://github.com/go-gitea/gitea/assets/35262707/ab74464b-7638-458a-afd5-f39e6101d2cf) --------- Co-authored-by: Jason Song <i@wolfogre.com> Co-authored-by: Giteabot <teabot@gitea.io>
* feat(API): add route and implementation for creating/updating repository ↵Bo-Yi Wu2023-08-293-17/+87
| | | | | | | | | | | | | | | | | | secret (#26766) spec: https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28#create-or-update-a-repository-secret - Add a new route for creating or updating a secret value in a repository - Create a new file `routers/api/v1/repo/action.go` with the implementation of the `CreateOrUpdateSecret` function - Update the Swagger documentation for the `updateRepoSecret` operation in the `v1_json.tmpl` template file --------- Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com> Co-authored-by: Giteabot <teabot@gitea.io>
* Fix some slice append usages (#26778)Chongyi Zheng2023-08-291-9/+7
| | | Co-authored-by: delvh <dev.lh@web.de>
* Add auth-required to config.json for Cargo http registry (#26729)merlleu2023-08-281-1/+3
| | | | | | | | | | | | | | | | | | | | | | | Cargo registry-auth feature requires config.json to have a property auth-required set to true in order to send token to all registry requests. This is ok for git index because you can manually edit the config.json file to add the auth-required, but when using sparse (setting index url to "sparse+https://git.example.com/api/packages/{owner}/cargo/"), the config.json is dynamically rendered, and does not reflect changes to the config.json file in the repo. I see two approaches: - Serve the real config.json file when fetching the config.json on the cargo service. - Automatically detect if the registry requires authorization. (This is what I implemented in this PR). What the PR does: - When a cargo index repository is created, on the config.json, set auth-required to wether or not the repository is private. - When the cargo/config.json endpoint is called, set auth-required to wether or not the request was authorized using an API token.
* refactor(API): refactor secret creation and update functionality (#26751)Bo-Yi Wu2023-08-283-58/+24
| | | | | | | | | | | | | | | | | | | | 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>
* Move `modules/mirror` to `services` (#26737)Chongyi Zheng2023-08-271-2/+1
| | | | | To solve the cyclic imports in a better way Closes #20261
* PATCH branch-protection updates check list even when checks are disabled ↵Infinoid2023-08-241-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | (#26351) Fixes: #26333. Previously, this endpoint only updates the `StatusCheckContexts` field when `EnableStatusCheck==true`, which makes it impossible to clear the array otherwise. This patch uses slice `nil`-ness to decide whether to update the list of checks. The field is ignored when either the client explicitly passes in a null, or just omits the field from the json ([which causes `json.Unmarshal` to leave the struct field unchanged](https://go.dev/play/p/Z2XHOILuB1Q)). I think this is a better measure of intent than whether the `EnableStatusCheck` flag was set, because it matches the semantics of other field types. Also adds a test case. I noticed that [`testAPIEditBranchProtection` only checks the branch name](https://github.com/go-gitea/gitea/blob/c1c83dbaec840871c1247f4bc3f875309b0de6bb/tests/integration/api_branch_test.go#L68) and no other fields, so I added some extra `GET` calls and specific checks to make sure the fields are changing properly. I added those checks the existing integration test; is that the right place for it?
* feat(API): update and delete secret for managing organization secrets (#26660)Bo-Yi Wu2023-08-243-0/+97
| | | | | | | | | | | | | | | | | | - 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>
* feat: implement organization secret creation API (#26566)Bo-Yi Wu2023-08-224-4/+58
| | | | | | | | | | | | | - 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>
* Return empty when searching issues with no repos (#26545)Jason Song2023-08-171-0/+4
|
* Add API route to list org secrets (#26485)Bo-Yi Wu2023-08-153-0/+88
| | | | | | | | | | | | | | | | | | | - Add a new function `CountOrgSecrets` in the file `models/secret/secret.go` - Add a new file `modules/structs/secret.go` - Add a new function `ListActionsSecrets` in the file `routers/api/v1/api.go` - Add a new file `routers/api/v1/org/action.go` - Add a new function `listActionsSecrets` in the file `routers/api/v1/org/action.go` go-sdk: https://gitea.com/gitea/go-sdk/pulls/629 --------- Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: Giteabot <teabot@gitea.io>
* Allow to archive labels (#26478)puni98692023-08-142-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ## Archived labels This adds the structure to allow for archived labels. Archived labels are, just like closed milestones or projects, a medium to hide information without deleting it. It is especially useful if there are outdated labels that should no longer be used without deleting the label entirely. ## Changes 1. UI and API have been equipped with the support to mark a label as archived 2. The time when a label has been archived will be stored in the DB ## Outsourced for the future There's no special handling for archived labels at the moment. This will be done in the future. ## Screenshots ![image](https://github.com/go-gitea/gitea/assets/80308335/208f95cd-42e4-4ed7-9a1f-cd2050a645d4) ![image](https://github.com/go-gitea/gitea/assets/80308335/746428e0-40bb-45b3-b992-85602feb371d) Part of https://github.com/go-gitea/gitea/issues/25237 --------- Co-authored-by: delvh <dev.lh@web.de> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Fix NuGet search endpoints (#25613)KN4CK3R2023-08-142-7/+15
| | | | | | | | | Fixes #25564 Fixes #23191 - Api v2 search endpoint should return only the latest version matching the query - Api v3 search endpoint should return `take` packages not package versions
* Introduce ctx.PathParamRaw to avoid incorrect unescaping (#26392)wxiaoguang2023-08-091-4/+4
| | | | | | Fix #26389 And complete an old TODO: `ctx.Params does un-escaping,..., which is incorrect.`
* fix artifact merging chunks path with correct slash on Windows (#26400)FuXiaoHei2023-08-081-1/+2
| | | | | | | | | | | | | From Discord https://discord.com/channels/322538954119184384/1069795723178160168/1136719889684500480 Artifact chunks merging is break on Windows. ``` Gitea Log: 2023/08/03 20:51:15 ...actions/artifacts.go:271:comfirmUploadArtifact() [E] Error merge chunks: parse content range error: input does not match format ``` Artifact uses wrong slash to parse saved chunks path.
* Refactor and enhance issue indexer to support both searching, filtering and ↵Jason Song2023-07-312-150/+176
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | paging (#26012) Fix #24662. Replace #24822 and #25708 (although it has been merged) ## Background In the past, Gitea supported issue searching with a keyword and conditions in a less efficient way. It worked by searching for issues with the keyword and obtaining limited IDs (as it is heavy to get all) on the indexer (bleve/elasticsearch/meilisearch), and then querying with conditions on the database to find a subset of the found IDs. This is why the results could be incomplete. To solve this issue, we need to store all fields that could be used as conditions in the indexer and support both keyword and additional conditions when searching with the indexer. ## Major changes - Redefine `IndexerData` to include all fields that could be used as filter conditions. - Refactor `Search(ctx context.Context, kw string, repoIDs []int64, limit, start int, state string)` to `Search(ctx context.Context, options *SearchOptions)`, so it supports more conditions now. - Change the data type stored in `issueIndexerQueue`. Use `IndexerMetadata` instead of `IndexerData` in case the data has been updated while it is in the queue. This also reduces the storage size of the queue. - Enhance searching with Bleve/Elasticsearch/Meilisearch, make them fully support `SearchOptions`. Also, update the data versions. - Keep most logic of database indexer, but remove `issues.SearchIssueIDsByKeyword` in `models` to avoid confusion where is the entry point to search issues. - Start a Meilisearch instance to test it in unit tests. - Add unit tests with almost full coverage to test Bleve/Elasticsearch/Meilisearch indexer. --------- Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Fix handling of plenty Nuget package versions (#26075)KN4CK3R2023-07-264-32/+94
| | | | | | Fixes #25953 - Do not load full version information (v3) - Add pagination support (v2)
* Remove "misc" scope check from public API endpoints (#26134)wxiaoguang2023-07-261-2/+2
| | | Fix #26035
* Allow Organisations to have a E-Mail (#25082)JakobDev2023-07-251-1/+11
| | | | | | | | | | | | | | | | | | | | Resolves #25057 This adds a E-Mail field to Organisations. The E-Mail is just shown on the Profile when it is visited by a logged in User. The E-mail is not used for something else. **Screenshots:** ![grafik](https://github.com/go-gitea/gitea/assets/15185051/a8d622b3-7278-4c08-984b-9c5ebfdb5471) ![grafik](https://github.com/go-gitea/gitea/assets/15185051/6dcb1dd7-d04b-49eb-bc96-6582cfe9757b) --------- Co-authored-by: Denys Konovalov <kontakt@denyskon.de> Co-authored-by: Denys Konovalov <privat@denyskon.de> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: Giteabot <teabot@gitea.io>
* Fix handling of Debian files with trailing slash (#26087)KN4CK3R2023-07-241-1/+1
| | | | | | | Fixes #26022 - Fix handling of files with trailing slash - Fix handling of duplicate package file errors - Added test for both
* fix Missing 404 swagger response docs for /admin/users/{username} (#26086)caicandong2023-07-241-0/+2
| | | close #26079
* Reduce unnecessary DB queries for Actions tasks (#25199)sillyguodong2023-07-241-7/+26
| | | | | | | | | | | | | | | | | | | | | | | Close #24544 Changes: - Create `action_tasks_version` table to store the latest version of each scope (global, org and repo). - When a job with the status of `waiting` is created, the tasks version of the scopes it belongs to will increase. - When the status of a job already in the database is updated to `waiting`, the tasks version of the scopes it belongs to will increase. - On Gitea side, in `FeatchTask()`, will try to query the `action_tasks_version` record of the scope of the runner that call `FetchTask()`. If the record does not exist, will insert a row. Then, Gitea will compare the version passed from runner to Gitea with the version in database, if inconsistent, try pick task. Gitea always returns the latest version from database to the runner. Related: - Protocol: https://gitea.com/gitea/actions-proto-def/pulls/10 - Runner: https://gitea.com/gitea/act_runner/pulls/219
* Remove `db.DefaultContext` in `routers/` and `cmd/` (#26076)delvh2023-07-237-116/+107
| | | | | | Now, the only remaining usages of `models.db.DefaultContext` are in - `modules` - `models` - `services`