You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

repo.go 28 kB

Move macaron to chi (#14293) Use [chi](https://github.com/go-chi/chi) instead of the forked [macaron](https://gitea.com/macaron/macaron). Since macaron and chi have conflicts with session share, this big PR becomes a have-to thing. According my previous idea, we can replace macaron step by step but I'm wrong. :( Below is a list of big changes on this PR. - [x] Define `context.ResponseWriter` interface with an implementation `context.Response`. - [x] Use chi instead of macaron, and also a customize `Route` to wrap chi so that the router usage is similar as before. - [x] Create different routers for `web`, `api`, `internal` and `install` so that the codes will be more clear and no magic . - [x] Use https://github.com/unrolled/render instead of macaron's internal render - [x] Use https://github.com/NYTimes/gziphandler instead of https://gitea.com/macaron/gzip - [x] Use https://gitea.com/go-chi/session which is a modified version of https://gitea.com/macaron/session and removed `nodb` support since it will not be maintained. **BREAK** - [x] Use https://gitea.com/go-chi/captcha which is a modified version of https://gitea.com/macaron/captcha - [x] Use https://gitea.com/go-chi/cache which is a modified version of https://gitea.com/macaron/cache - [x] Use https://gitea.com/go-chi/binding which is a modified version of https://gitea.com/macaron/binding - [x] Use https://github.com/go-chi/cors instead of https://gitea.com/macaron/cors - [x] Dropped https://gitea.com/macaron/i18n and make a new one in `code.gitea.io/gitea/modules/translation` - [x] Move validation form structs from `code.gitea.io/gitea/modules/auth` to `code.gitea.io/gitea/modules/forms` to avoid dependency cycle. - [x] Removed macaron log service because it's not need any more. **BREAK** - [x] All form structs have to be get by `web.GetForm(ctx)` in the route function but not as a function parameter on routes definition. - [x] Move Git HTTP protocol implementation to use routers directly. - [x] Fix the problem that chi routes don't support trailing slash but macaron did. - [x] `/api/v1/swagger` now will be redirect to `/api/swagger` but not render directly so that `APIContext` will not create a html render. Notices: - Chi router don't support request with trailing slash - Integration test `TestUserHeatmap` maybe mysql version related. It's failed on my macOS(mysql 5.7.29 installed via brew) but succeed on CI. Co-authored-by: 6543 <6543@obermui.de>
4 years ago
API add/generalize pagination (#9452) * paginate results * fixed deadlock * prevented breaking change * updated swagger * go fmt * fixed find topic * go mod tidy * go mod vendor with go1.13.5 * fixed repo find topics * fixed unit test * added Limit method to Engine struct; use engine variable when provided; fixed gitignore * use ItemsPerPage for default pagesize; fix GetWatchers, getOrgUsersByOrgID and GetStargazers; fix GetAllCommits headers; reverted some changed behaviors * set Page value on Home route * improved memory allocations * fixed response headers * removed logfiles * fixed import order * import order * improved swagger * added function to get models.ListOptions from context * removed pagesize diff on unit test * fixed imports * removed unnecessary struct field * fixed go fmt * scoped PR * code improvements * code improvements * go mod tidy * fixed import order * fixed commit statuses session * fixed files headers * fixed headers; added pagination for notifications * go mod tidy * go fmt * removed Private from user search options; added setting.UI.IssuePagingNum as default valeu on repo's issues list * Apply suggestions from code review Co-Authored-By: 6543 <6543@obermui.de> Co-Authored-By: zeripath <art27@cantab.net> * fixed build error * CI.restart() * fixed merge conflicts resolve * fixed conflicts resolve * improved FindTrackedTimesOptions.ToOptions() method * added backwards compatibility on ListReleases request; fixed issue tracked time ToSession * fixed build error; fixed swagger template * fixed swagger template * fixed ListReleases backwards compatibility * added page to user search route Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: zeripath <art27@cantab.net>
5 years ago
Template Repositories (#8768) * Start work on templates Signed-off-by: jolheiser <john.olheiser@gmail.com> * Continue work Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix IsTemplate vs IsGenerated Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tabs vs spaces * Tabs vs Spaces * Add templates to API & start adding tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix integration tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Remove unused User Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move template tests to existing repos Signed-off-by: jolheiser <john.olheiser@gmail.com> * Minor re-check updates and cleanup Signed-off-by: jolheiser <john.olheiser@gmail.com> * make fmt Signed-off-by: jolheiser <john.olheiser@gmail.com> * Test cleanup Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix optionalbool Signed-off-by: jolheiser <john.olheiser@gmail.com> * make fmt Signed-off-by: jolheiser <john.olheiser@gmail.com> * Test fixes and icon change Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add new user and repo for tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tests (finally) Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update meta repo with env variables Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move generation to create page Combine with repo create template Modify API search to prioritize owner for repo Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tests and coverage Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix swagger and JS lint Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix API searching for own private repos Signed-off-by: jolheiser <john.olheiser@gmail.com> * Change wording Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix repo search test. User had a private repo that didn't show up Signed-off-by: jolheiser <john.olheiser@gmail.com> * Another search test fix Signed-off-by: jolheiser <john.olheiser@gmail.com> * Clarify git content Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Feedback updates Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add topics WIP Signed-off-by: jolheiser <john.olheiser@gmail.com> * Finish adding topics Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update locale Signed-off-by: jolheiser <john.olheiser@gmail.com>
5 years ago
Template Repositories (#8768) * Start work on templates Signed-off-by: jolheiser <john.olheiser@gmail.com> * Continue work Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix IsTemplate vs IsGenerated Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tabs vs spaces * Tabs vs Spaces * Add templates to API & start adding tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix integration tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Remove unused User Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move template tests to existing repos Signed-off-by: jolheiser <john.olheiser@gmail.com> * Minor re-check updates and cleanup Signed-off-by: jolheiser <john.olheiser@gmail.com> * make fmt Signed-off-by: jolheiser <john.olheiser@gmail.com> * Test cleanup Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix optionalbool Signed-off-by: jolheiser <john.olheiser@gmail.com> * make fmt Signed-off-by: jolheiser <john.olheiser@gmail.com> * Test fixes and icon change Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add new user and repo for tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tests (finally) Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update meta repo with env variables Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move generation to create page Combine with repo create template Modify API search to prioritize owner for repo Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tests and coverage Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix swagger and JS lint Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix API searching for own private repos Signed-off-by: jolheiser <john.olheiser@gmail.com> * Change wording Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix repo search test. User had a private repo that didn't show up Signed-off-by: jolheiser <john.olheiser@gmail.com> * Another search test fix Signed-off-by: jolheiser <john.olheiser@gmail.com> * Clarify git content Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Feedback updates Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add topics WIP Signed-off-by: jolheiser <john.olheiser@gmail.com> * Finish adding topics Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update locale Signed-off-by: jolheiser <john.olheiser@gmail.com>
5 years ago
API add/generalize pagination (#9452) * paginate results * fixed deadlock * prevented breaking change * updated swagger * go fmt * fixed find topic * go mod tidy * go mod vendor with go1.13.5 * fixed repo find topics * fixed unit test * added Limit method to Engine struct; use engine variable when provided; fixed gitignore * use ItemsPerPage for default pagesize; fix GetWatchers, getOrgUsersByOrgID and GetStargazers; fix GetAllCommits headers; reverted some changed behaviors * set Page value on Home route * improved memory allocations * fixed response headers * removed logfiles * fixed import order * import order * improved swagger * added function to get models.ListOptions from context * removed pagesize diff on unit test * fixed imports * removed unnecessary struct field * fixed go fmt * scoped PR * code improvements * code improvements * go mod tidy * fixed import order * fixed commit statuses session * fixed files headers * fixed headers; added pagination for notifications * go mod tidy * go fmt * removed Private from user search options; added setting.UI.IssuePagingNum as default valeu on repo's issues list * Apply suggestions from code review Co-Authored-By: 6543 <6543@obermui.de> Co-Authored-By: zeripath <art27@cantab.net> * fixed build error * CI.restart() * fixed merge conflicts resolve * fixed conflicts resolve * improved FindTrackedTimesOptions.ToOptions() method * added backwards compatibility on ListReleases request; fixed issue tracked time ToSession * fixed build error; fixed swagger template * fixed swagger template * fixed ListReleases backwards compatibility * added page to user search route Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: zeripath <art27@cantab.net>
5 years ago
API add/generalize pagination (#9452) * paginate results * fixed deadlock * prevented breaking change * updated swagger * go fmt * fixed find topic * go mod tidy * go mod vendor with go1.13.5 * fixed repo find topics * fixed unit test * added Limit method to Engine struct; use engine variable when provided; fixed gitignore * use ItemsPerPage for default pagesize; fix GetWatchers, getOrgUsersByOrgID and GetStargazers; fix GetAllCommits headers; reverted some changed behaviors * set Page value on Home route * improved memory allocations * fixed response headers * removed logfiles * fixed import order * import order * improved swagger * added function to get models.ListOptions from context * removed pagesize diff on unit test * fixed imports * removed unnecessary struct field * fixed go fmt * scoped PR * code improvements * code improvements * go mod tidy * fixed import order * fixed commit statuses session * fixed files headers * fixed headers; added pagination for notifications * go mod tidy * go fmt * removed Private from user search options; added setting.UI.IssuePagingNum as default valeu on repo's issues list * Apply suggestions from code review Co-Authored-By: 6543 <6543@obermui.de> Co-Authored-By: zeripath <art27@cantab.net> * fixed build error * CI.restart() * fixed merge conflicts resolve * fixed conflicts resolve * improved FindTrackedTimesOptions.ToOptions() method * added backwards compatibility on ListReleases request; fixed issue tracked time ToSession * fixed build error; fixed swagger template * fixed swagger template * fixed ListReleases backwards compatibility * added page to user search route Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: zeripath <art27@cantab.net>
5 years ago
API add/generalize pagination (#9452) * paginate results * fixed deadlock * prevented breaking change * updated swagger * go fmt * fixed find topic * go mod tidy * go mod vendor with go1.13.5 * fixed repo find topics * fixed unit test * added Limit method to Engine struct; use engine variable when provided; fixed gitignore * use ItemsPerPage for default pagesize; fix GetWatchers, getOrgUsersByOrgID and GetStargazers; fix GetAllCommits headers; reverted some changed behaviors * set Page value on Home route * improved memory allocations * fixed response headers * removed logfiles * fixed import order * import order * improved swagger * added function to get models.ListOptions from context * removed pagesize diff on unit test * fixed imports * removed unnecessary struct field * fixed go fmt * scoped PR * code improvements * code improvements * go mod tidy * fixed import order * fixed commit statuses session * fixed files headers * fixed headers; added pagination for notifications * go mod tidy * go fmt * removed Private from user search options; added setting.UI.IssuePagingNum as default valeu on repo's issues list * Apply suggestions from code review Co-Authored-By: 6543 <6543@obermui.de> Co-Authored-By: zeripath <art27@cantab.net> * fixed build error * CI.restart() * fixed merge conflicts resolve * fixed conflicts resolve * improved FindTrackedTimesOptions.ToOptions() method * added backwards compatibility on ListReleases request; fixed issue tracked time ToSession * fixed build error; fixed swagger template * fixed swagger template * fixed ListReleases backwards compatibility * added page to user search route Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: zeripath <art27@cantab.net>
5 years ago
Restricted users (#6274) * Restricted users (#4334): initial implementation * Add User.IsRestricted & UI to edit it * Pass user object instead of user id to places where IsRestricted flag matters * Restricted users: maintain access rows for all referenced repos (incl public) * Take logged in user & IsRestricted flag into account in org/repo listings, searches and accesses * Add basic repo access tests for restricted users Signed-off-by: Manush Dodunekov <manush@stendahls.se> * Mention restricted users in the faq Signed-off-by: Manush Dodunekov <manush@stendahls.se> * Revert unnecessary change `.isUserPartOfOrg` -> `.IsUserPartOfOrg` Signed-off-by: Manush Dodunekov <manush@stendahls.se> * Remove unnecessary `org.IsOrganization()` call Signed-off-by: Manush Dodunekov <manush@stendahls.se> * Revert to an `int64` keyed `accessMap` * Add type `userAccess` * Add convenience func updateUserAccess() * Turn accessMap into a `map[int64]userAccess` Signed-off-by: Manush Dodunekov <manush@stendahls.se> * or even better: `map[int64]*userAccess` * updateUserAccess(): use tighter syntax as suggested by lafriks * even tighter * Avoid extra loop * Don't disclose limited orgs to unauthenticated users * Don't assume block only applies to orgs * Use an array of `VisibleType` for filtering * fix yet another thinko * Ok - no need for u * Revert "Ok - no need for u" This reverts commit 5c3e886aabd5acd997a3b35687d322439732c200. Co-authored-by: Antoine GIRARD <sapk@users.noreply.github.com> Co-authored-by: Lauris BH <lauris@nix.lv>
5 years ago
Template Repositories (#8768) * Start work on templates Signed-off-by: jolheiser <john.olheiser@gmail.com> * Continue work Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix IsTemplate vs IsGenerated Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tabs vs spaces * Tabs vs Spaces * Add templates to API & start adding tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix integration tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Remove unused User Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move template tests to existing repos Signed-off-by: jolheiser <john.olheiser@gmail.com> * Minor re-check updates and cleanup Signed-off-by: jolheiser <john.olheiser@gmail.com> * make fmt Signed-off-by: jolheiser <john.olheiser@gmail.com> * Test cleanup Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix optionalbool Signed-off-by: jolheiser <john.olheiser@gmail.com> * make fmt Signed-off-by: jolheiser <john.olheiser@gmail.com> * Test fixes and icon change Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add new user and repo for tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tests (finally) Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update meta repo with env variables Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move generation to create page Combine with repo create template Modify API search to prioritize owner for repo Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tests and coverage Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix swagger and JS lint Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix API searching for own private repos Signed-off-by: jolheiser <john.olheiser@gmail.com> * Change wording Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix repo search test. User had a private repo that didn't show up Signed-off-by: jolheiser <john.olheiser@gmail.com> * Another search test fix Signed-off-by: jolheiser <john.olheiser@gmail.com> * Clarify git content Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Feedback updates Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add topics WIP Signed-off-by: jolheiser <john.olheiser@gmail.com> * Finish adding topics Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update locale Signed-off-by: jolheiser <john.olheiser@gmail.com>
5 years ago
Template Repositories (#8768) * Start work on templates Signed-off-by: jolheiser <john.olheiser@gmail.com> * Continue work Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix IsTemplate vs IsGenerated Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tabs vs spaces * Tabs vs Spaces * Add templates to API & start adding tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix integration tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Remove unused User Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move template tests to existing repos Signed-off-by: jolheiser <john.olheiser@gmail.com> * Minor re-check updates and cleanup Signed-off-by: jolheiser <john.olheiser@gmail.com> * make fmt Signed-off-by: jolheiser <john.olheiser@gmail.com> * Test cleanup Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix optionalbool Signed-off-by: jolheiser <john.olheiser@gmail.com> * make fmt Signed-off-by: jolheiser <john.olheiser@gmail.com> * Test fixes and icon change Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add new user and repo for tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tests (finally) Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update meta repo with env variables Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move generation to create page Combine with repo create template Modify API search to prioritize owner for repo Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tests and coverage Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix swagger and JS lint Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix API searching for own private repos Signed-off-by: jolheiser <john.olheiser@gmail.com> * Change wording Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix repo search test. User had a private repo that didn't show up Signed-off-by: jolheiser <john.olheiser@gmail.com> * Another search test fix Signed-off-by: jolheiser <john.olheiser@gmail.com> * Clarify git content Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Feedback updates Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add topics WIP Signed-off-by: jolheiser <john.olheiser@gmail.com> * Finish adding topics Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update locale Signed-off-by: jolheiser <john.olheiser@gmail.com>
5 years ago
Template Repositories (#8768) * Start work on templates Signed-off-by: jolheiser <john.olheiser@gmail.com> * Continue work Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix IsTemplate vs IsGenerated Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tabs vs spaces * Tabs vs Spaces * Add templates to API & start adding tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix integration tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Remove unused User Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move template tests to existing repos Signed-off-by: jolheiser <john.olheiser@gmail.com> * Minor re-check updates and cleanup Signed-off-by: jolheiser <john.olheiser@gmail.com> * make fmt Signed-off-by: jolheiser <john.olheiser@gmail.com> * Test cleanup Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix optionalbool Signed-off-by: jolheiser <john.olheiser@gmail.com> * make fmt Signed-off-by: jolheiser <john.olheiser@gmail.com> * Test fixes and icon change Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add new user and repo for tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tests (finally) Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update meta repo with env variables Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move generation to create page Combine with repo create template Modify API search to prioritize owner for repo Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tests and coverage Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix swagger and JS lint Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix API searching for own private repos Signed-off-by: jolheiser <john.olheiser@gmail.com> * Change wording Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix repo search test. User had a private repo that didn't show up Signed-off-by: jolheiser <john.olheiser@gmail.com> * Another search test fix Signed-off-by: jolheiser <john.olheiser@gmail.com> * Clarify git content Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Feedback updates Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add topics WIP Signed-off-by: jolheiser <john.olheiser@gmail.com> * Finish adding topics Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update locale Signed-off-by: jolheiser <john.olheiser@gmail.com>
5 years ago
API add/generalize pagination (#9452) * paginate results * fixed deadlock * prevented breaking change * updated swagger * go fmt * fixed find topic * go mod tidy * go mod vendor with go1.13.5 * fixed repo find topics * fixed unit test * added Limit method to Engine struct; use engine variable when provided; fixed gitignore * use ItemsPerPage for default pagesize; fix GetWatchers, getOrgUsersByOrgID and GetStargazers; fix GetAllCommits headers; reverted some changed behaviors * set Page value on Home route * improved memory allocations * fixed response headers * removed logfiles * fixed import order * import order * improved swagger * added function to get models.ListOptions from context * removed pagesize diff on unit test * fixed imports * removed unnecessary struct field * fixed go fmt * scoped PR * code improvements * code improvements * go mod tidy * fixed import order * fixed commit statuses session * fixed files headers * fixed headers; added pagination for notifications * go mod tidy * go fmt * removed Private from user search options; added setting.UI.IssuePagingNum as default valeu on repo's issues list * Apply suggestions from code review Co-Authored-By: 6543 <6543@obermui.de> Co-Authored-By: zeripath <art27@cantab.net> * fixed build error * CI.restart() * fixed merge conflicts resolve * fixed conflicts resolve * improved FindTrackedTimesOptions.ToOptions() method * added backwards compatibility on ListReleases request; fixed issue tracked time ToSession * fixed build error; fixed swagger template * fixed swagger template * fixed ListReleases backwards compatibility * added page to user search route Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: zeripath <art27@cantab.net>
5 years ago
10 years ago
Add configurable Trust Models (#11712) * Add configurable Trust Models Gitea's default signature verification model differs from GitHub. GitHub uses signatures to verify that the committer is who they say they are - meaning that when GitHub makes a signed commit it must be the committer. The GitHub model prevents re-publishing of commits after revocation of a key and prevents re-signing of other people's commits to create a completely trusted repository signed by one key or a set of trusted keys. The default behaviour of Gitea in contrast is to always display the avatar and information related to a signature. This allows signatures to be decoupled from the committer. That being said, allowing arbitary users to present other peoples commits as theirs is not necessarily desired therefore we have a trust model whereby signatures from collaborators are marked trusted, signatures matching the commit line are marked untrusted and signatures that match a user in the db but not the committer line are marked unmatched. The problem with this model is that this conflicts with Github therefore we need to provide an option to allow users to choose the Github model should they wish to. Signed-off-by: Andrew Thornton <art27@cantab.net> * Adjust locale strings Signed-off-by: Andrew Thornton <art27@cantab.net> * as per @6543 Co-authored-by: 6543 <6543@obermui.de> * Update models/gpg_key.go * Add migration for repository Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
4 years ago
Move macaron to chi (#14293) Use [chi](https://github.com/go-chi/chi) instead of the forked [macaron](https://gitea.com/macaron/macaron). Since macaron and chi have conflicts with session share, this big PR becomes a have-to thing. According my previous idea, we can replace macaron step by step but I'm wrong. :( Below is a list of big changes on this PR. - [x] Define `context.ResponseWriter` interface with an implementation `context.Response`. - [x] Use chi instead of macaron, and also a customize `Route` to wrap chi so that the router usage is similar as before. - [x] Create different routers for `web`, `api`, `internal` and `install` so that the codes will be more clear and no magic . - [x] Use https://github.com/unrolled/render instead of macaron's internal render - [x] Use https://github.com/NYTimes/gziphandler instead of https://gitea.com/macaron/gzip - [x] Use https://gitea.com/go-chi/session which is a modified version of https://gitea.com/macaron/session and removed `nodb` support since it will not be maintained. **BREAK** - [x] Use https://gitea.com/go-chi/captcha which is a modified version of https://gitea.com/macaron/captcha - [x] Use https://gitea.com/go-chi/cache which is a modified version of https://gitea.com/macaron/cache - [x] Use https://gitea.com/go-chi/binding which is a modified version of https://gitea.com/macaron/binding - [x] Use https://github.com/go-chi/cors instead of https://gitea.com/macaron/cors - [x] Dropped https://gitea.com/macaron/i18n and make a new one in `code.gitea.io/gitea/modules/translation` - [x] Move validation form structs from `code.gitea.io/gitea/modules/auth` to `code.gitea.io/gitea/modules/forms` to avoid dependency cycle. - [x] Removed macaron log service because it's not need any more. **BREAK** - [x] All form structs have to be get by `web.GetForm(ctx)` in the route function but not as a function parameter on routes definition. - [x] Move Git HTTP protocol implementation to use routers directly. - [x] Fix the problem that chi routes don't support trailing slash but macaron did. - [x] `/api/v1/swagger` now will be redirect to `/api/swagger` but not render directly so that `APIContext` will not create a html render. Notices: - Chi router don't support request with trailing slash - Integration test `TestUserHeatmap` maybe mysql version related. It's failed on my macOS(mysql 5.7.29 installed via brew) but succeed on CI. Co-authored-by: 6543 <6543@obermui.de>
4 years ago
Move macaron to chi (#14293) Use [chi](https://github.com/go-chi/chi) instead of the forked [macaron](https://gitea.com/macaron/macaron). Since macaron and chi have conflicts with session share, this big PR becomes a have-to thing. According my previous idea, we can replace macaron step by step but I'm wrong. :( Below is a list of big changes on this PR. - [x] Define `context.ResponseWriter` interface with an implementation `context.Response`. - [x] Use chi instead of macaron, and also a customize `Route` to wrap chi so that the router usage is similar as before. - [x] Create different routers for `web`, `api`, `internal` and `install` so that the codes will be more clear and no magic . - [x] Use https://github.com/unrolled/render instead of macaron's internal render - [x] Use https://github.com/NYTimes/gziphandler instead of https://gitea.com/macaron/gzip - [x] Use https://gitea.com/go-chi/session which is a modified version of https://gitea.com/macaron/session and removed `nodb` support since it will not be maintained. **BREAK** - [x] Use https://gitea.com/go-chi/captcha which is a modified version of https://gitea.com/macaron/captcha - [x] Use https://gitea.com/go-chi/cache which is a modified version of https://gitea.com/macaron/cache - [x] Use https://gitea.com/go-chi/binding which is a modified version of https://gitea.com/macaron/binding - [x] Use https://github.com/go-chi/cors instead of https://gitea.com/macaron/cors - [x] Dropped https://gitea.com/macaron/i18n and make a new one in `code.gitea.io/gitea/modules/translation` - [x] Move validation form structs from `code.gitea.io/gitea/modules/auth` to `code.gitea.io/gitea/modules/forms` to avoid dependency cycle. - [x] Removed macaron log service because it's not need any more. **BREAK** - [x] All form structs have to be get by `web.GetForm(ctx)` in the route function but not as a function parameter on routes definition. - [x] Move Git HTTP protocol implementation to use routers directly. - [x] Fix the problem that chi routes don't support trailing slash but macaron did. - [x] `/api/v1/swagger` now will be redirect to `/api/swagger` but not render directly so that `APIContext` will not create a html render. Notices: - Chi router don't support request with trailing slash - Integration test `TestUserHeatmap` maybe mysql version related. It's failed on my macOS(mysql 5.7.29 installed via brew) but succeed on CI. Co-authored-by: 6543 <6543@obermui.de>
4 years ago
Move macaron to chi (#14293) Use [chi](https://github.com/go-chi/chi) instead of the forked [macaron](https://gitea.com/macaron/macaron). Since macaron and chi have conflicts with session share, this big PR becomes a have-to thing. According my previous idea, we can replace macaron step by step but I'm wrong. :( Below is a list of big changes on this PR. - [x] Define `context.ResponseWriter` interface with an implementation `context.Response`. - [x] Use chi instead of macaron, and also a customize `Route` to wrap chi so that the router usage is similar as before. - [x] Create different routers for `web`, `api`, `internal` and `install` so that the codes will be more clear and no magic . - [x] Use https://github.com/unrolled/render instead of macaron's internal render - [x] Use https://github.com/NYTimes/gziphandler instead of https://gitea.com/macaron/gzip - [x] Use https://gitea.com/go-chi/session which is a modified version of https://gitea.com/macaron/session and removed `nodb` support since it will not be maintained. **BREAK** - [x] Use https://gitea.com/go-chi/captcha which is a modified version of https://gitea.com/macaron/captcha - [x] Use https://gitea.com/go-chi/cache which is a modified version of https://gitea.com/macaron/cache - [x] Use https://gitea.com/go-chi/binding which is a modified version of https://gitea.com/macaron/binding - [x] Use https://github.com/go-chi/cors instead of https://gitea.com/macaron/cors - [x] Dropped https://gitea.com/macaron/i18n and make a new one in `code.gitea.io/gitea/modules/translation` - [x] Move validation form structs from `code.gitea.io/gitea/modules/auth` to `code.gitea.io/gitea/modules/forms` to avoid dependency cycle. - [x] Removed macaron log service because it's not need any more. **BREAK** - [x] All form structs have to be get by `web.GetForm(ctx)` in the route function but not as a function parameter on routes definition. - [x] Move Git HTTP protocol implementation to use routers directly. - [x] Fix the problem that chi routes don't support trailing slash but macaron did. - [x] `/api/v1/swagger` now will be redirect to `/api/swagger` but not render directly so that `APIContext` will not create a html render. Notices: - Chi router don't support request with trailing slash - Integration test `TestUserHeatmap` maybe mysql version related. It's failed on my macOS(mysql 5.7.29 installed via brew) but succeed on CI. Co-authored-by: 6543 <6543@obermui.de>
4 years ago
Move macaron to chi (#14293) Use [chi](https://github.com/go-chi/chi) instead of the forked [macaron](https://gitea.com/macaron/macaron). Since macaron and chi have conflicts with session share, this big PR becomes a have-to thing. According my previous idea, we can replace macaron step by step but I'm wrong. :( Below is a list of big changes on this PR. - [x] Define `context.ResponseWriter` interface with an implementation `context.Response`. - [x] Use chi instead of macaron, and also a customize `Route` to wrap chi so that the router usage is similar as before. - [x] Create different routers for `web`, `api`, `internal` and `install` so that the codes will be more clear and no magic . - [x] Use https://github.com/unrolled/render instead of macaron's internal render - [x] Use https://github.com/NYTimes/gziphandler instead of https://gitea.com/macaron/gzip - [x] Use https://gitea.com/go-chi/session which is a modified version of https://gitea.com/macaron/session and removed `nodb` support since it will not be maintained. **BREAK** - [x] Use https://gitea.com/go-chi/captcha which is a modified version of https://gitea.com/macaron/captcha - [x] Use https://gitea.com/go-chi/cache which is a modified version of https://gitea.com/macaron/cache - [x] Use https://gitea.com/go-chi/binding which is a modified version of https://gitea.com/macaron/binding - [x] Use https://github.com/go-chi/cors instead of https://gitea.com/macaron/cors - [x] Dropped https://gitea.com/macaron/i18n and make a new one in `code.gitea.io/gitea/modules/translation` - [x] Move validation form structs from `code.gitea.io/gitea/modules/auth` to `code.gitea.io/gitea/modules/forms` to avoid dependency cycle. - [x] Removed macaron log service because it's not need any more. **BREAK** - [x] All form structs have to be get by `web.GetForm(ctx)` in the route function but not as a function parameter on routes definition. - [x] Move Git HTTP protocol implementation to use routers directly. - [x] Fix the problem that chi routes don't support trailing slash but macaron did. - [x] `/api/v1/swagger` now will be redirect to `/api/swagger` but not render directly so that `APIContext` will not create a html render. Notices: - Chi router don't support request with trailing slash - Integration test `TestUserHeatmap` maybe mysql version related. It's failed on my macOS(mysql 5.7.29 installed via brew) but succeed on CI. Co-authored-by: 6543 <6543@obermui.de>
4 years ago
Move macaron to chi (#14293) Use [chi](https://github.com/go-chi/chi) instead of the forked [macaron](https://gitea.com/macaron/macaron). Since macaron and chi have conflicts with session share, this big PR becomes a have-to thing. According my previous idea, we can replace macaron step by step but I'm wrong. :( Below is a list of big changes on this PR. - [x] Define `context.ResponseWriter` interface with an implementation `context.Response`. - [x] Use chi instead of macaron, and also a customize `Route` to wrap chi so that the router usage is similar as before. - [x] Create different routers for `web`, `api`, `internal` and `install` so that the codes will be more clear and no magic . - [x] Use https://github.com/unrolled/render instead of macaron's internal render - [x] Use https://github.com/NYTimes/gziphandler instead of https://gitea.com/macaron/gzip - [x] Use https://gitea.com/go-chi/session which is a modified version of https://gitea.com/macaron/session and removed `nodb` support since it will not be maintained. **BREAK** - [x] Use https://gitea.com/go-chi/captcha which is a modified version of https://gitea.com/macaron/captcha - [x] Use https://gitea.com/go-chi/cache which is a modified version of https://gitea.com/macaron/cache - [x] Use https://gitea.com/go-chi/binding which is a modified version of https://gitea.com/macaron/binding - [x] Use https://github.com/go-chi/cors instead of https://gitea.com/macaron/cors - [x] Dropped https://gitea.com/macaron/i18n and make a new one in `code.gitea.io/gitea/modules/translation` - [x] Move validation form structs from `code.gitea.io/gitea/modules/auth` to `code.gitea.io/gitea/modules/forms` to avoid dependency cycle. - [x] Removed macaron log service because it's not need any more. **BREAK** - [x] All form structs have to be get by `web.GetForm(ctx)` in the route function but not as a function parameter on routes definition. - [x] Move Git HTTP protocol implementation to use routers directly. - [x] Fix the problem that chi routes don't support trailing slash but macaron did. - [x] `/api/v1/swagger` now will be redirect to `/api/swagger` but not render directly so that `APIContext` will not create a html render. Notices: - Chi router don't support request with trailing slash - Integration test `TestUserHeatmap` maybe mysql version related. It's failed on my macOS(mysql 5.7.29 installed via brew) but succeed on CI. Co-authored-by: 6543 <6543@obermui.de>
4 years ago
Move macaron to chi (#14293) Use [chi](https://github.com/go-chi/chi) instead of the forked [macaron](https://gitea.com/macaron/macaron). Since macaron and chi have conflicts with session share, this big PR becomes a have-to thing. According my previous idea, we can replace macaron step by step but I'm wrong. :( Below is a list of big changes on this PR. - [x] Define `context.ResponseWriter` interface with an implementation `context.Response`. - [x] Use chi instead of macaron, and also a customize `Route` to wrap chi so that the router usage is similar as before. - [x] Create different routers for `web`, `api`, `internal` and `install` so that the codes will be more clear and no magic . - [x] Use https://github.com/unrolled/render instead of macaron's internal render - [x] Use https://github.com/NYTimes/gziphandler instead of https://gitea.com/macaron/gzip - [x] Use https://gitea.com/go-chi/session which is a modified version of https://gitea.com/macaron/session and removed `nodb` support since it will not be maintained. **BREAK** - [x] Use https://gitea.com/go-chi/captcha which is a modified version of https://gitea.com/macaron/captcha - [x] Use https://gitea.com/go-chi/cache which is a modified version of https://gitea.com/macaron/cache - [x] Use https://gitea.com/go-chi/binding which is a modified version of https://gitea.com/macaron/binding - [x] Use https://github.com/go-chi/cors instead of https://gitea.com/macaron/cors - [x] Dropped https://gitea.com/macaron/i18n and make a new one in `code.gitea.io/gitea/modules/translation` - [x] Move validation form structs from `code.gitea.io/gitea/modules/auth` to `code.gitea.io/gitea/modules/forms` to avoid dependency cycle. - [x] Removed macaron log service because it's not need any more. **BREAK** - [x] All form structs have to be get by `web.GetForm(ctx)` in the route function but not as a function parameter on routes definition. - [x] Move Git HTTP protocol implementation to use routers directly. - [x] Fix the problem that chi routes don't support trailing slash but macaron did. - [x] `/api/v1/swagger` now will be redirect to `/api/swagger` but not render directly so that `APIContext` will not create a html render. Notices: - Chi router don't support request with trailing slash - Integration test `TestUserHeatmap` maybe mysql version related. It's failed on my macOS(mysql 5.7.29 installed via brew) but succeed on CI. Co-authored-by: 6543 <6543@obermui.de>
4 years ago
Move macaron to chi (#14293) Use [chi](https://github.com/go-chi/chi) instead of the forked [macaron](https://gitea.com/macaron/macaron). Since macaron and chi have conflicts with session share, this big PR becomes a have-to thing. According my previous idea, we can replace macaron step by step but I'm wrong. :( Below is a list of big changes on this PR. - [x] Define `context.ResponseWriter` interface with an implementation `context.Response`. - [x] Use chi instead of macaron, and also a customize `Route` to wrap chi so that the router usage is similar as before. - [x] Create different routers for `web`, `api`, `internal` and `install` so that the codes will be more clear and no magic . - [x] Use https://github.com/unrolled/render instead of macaron's internal render - [x] Use https://github.com/NYTimes/gziphandler instead of https://gitea.com/macaron/gzip - [x] Use https://gitea.com/go-chi/session which is a modified version of https://gitea.com/macaron/session and removed `nodb` support since it will not be maintained. **BREAK** - [x] Use https://gitea.com/go-chi/captcha which is a modified version of https://gitea.com/macaron/captcha - [x] Use https://gitea.com/go-chi/cache which is a modified version of https://gitea.com/macaron/cache - [x] Use https://gitea.com/go-chi/binding which is a modified version of https://gitea.com/macaron/binding - [x] Use https://github.com/go-chi/cors instead of https://gitea.com/macaron/cors - [x] Dropped https://gitea.com/macaron/i18n and make a new one in `code.gitea.io/gitea/modules/translation` - [x] Move validation form structs from `code.gitea.io/gitea/modules/auth` to `code.gitea.io/gitea/modules/forms` to avoid dependency cycle. - [x] Removed macaron log service because it's not need any more. **BREAK** - [x] All form structs have to be get by `web.GetForm(ctx)` in the route function but not as a function parameter on routes definition. - [x] Move Git HTTP protocol implementation to use routers directly. - [x] Fix the problem that chi routes don't support trailing slash but macaron did. - [x] `/api/v1/swagger` now will be redirect to `/api/swagger` but not render directly so that `APIContext` will not create a html render. Notices: - Chi router don't support request with trailing slash - Integration test `TestUserHeatmap` maybe mysql version related. It's failed on my macOS(mysql 5.7.29 installed via brew) but succeed on CI. Co-authored-by: 6543 <6543@obermui.de>
4 years ago
Move macaron to chi (#14293) Use [chi](https://github.com/go-chi/chi) instead of the forked [macaron](https://gitea.com/macaron/macaron). Since macaron and chi have conflicts with session share, this big PR becomes a have-to thing. According my previous idea, we can replace macaron step by step but I'm wrong. :( Below is a list of big changes on this PR. - [x] Define `context.ResponseWriter` interface with an implementation `context.Response`. - [x] Use chi instead of macaron, and also a customize `Route` to wrap chi so that the router usage is similar as before. - [x] Create different routers for `web`, `api`, `internal` and `install` so that the codes will be more clear and no magic . - [x] Use https://github.com/unrolled/render instead of macaron's internal render - [x] Use https://github.com/NYTimes/gziphandler instead of https://gitea.com/macaron/gzip - [x] Use https://gitea.com/go-chi/session which is a modified version of https://gitea.com/macaron/session and removed `nodb` support since it will not be maintained. **BREAK** - [x] Use https://gitea.com/go-chi/captcha which is a modified version of https://gitea.com/macaron/captcha - [x] Use https://gitea.com/go-chi/cache which is a modified version of https://gitea.com/macaron/cache - [x] Use https://gitea.com/go-chi/binding which is a modified version of https://gitea.com/macaron/binding - [x] Use https://github.com/go-chi/cors instead of https://gitea.com/macaron/cors - [x] Dropped https://gitea.com/macaron/i18n and make a new one in `code.gitea.io/gitea/modules/translation` - [x] Move validation form structs from `code.gitea.io/gitea/modules/auth` to `code.gitea.io/gitea/modules/forms` to avoid dependency cycle. - [x] Removed macaron log service because it's not need any more. **BREAK** - [x] All form structs have to be get by `web.GetForm(ctx)` in the route function but not as a function parameter on routes definition. - [x] Move Git HTTP protocol implementation to use routers directly. - [x] Fix the problem that chi routes don't support trailing slash but macaron did. - [x] `/api/v1/swagger` now will be redirect to `/api/swagger` but not render directly so that `APIContext` will not create a html render. Notices: - Chi router don't support request with trailing slash - Integration test `TestUserHeatmap` maybe mysql version related. It's failed on my macOS(mysql 5.7.29 installed via brew) but succeed on CI. Co-authored-by: 6543 <6543@obermui.de>
4 years ago
Move macaron to chi (#14293) Use [chi](https://github.com/go-chi/chi) instead of the forked [macaron](https://gitea.com/macaron/macaron). Since macaron and chi have conflicts with session share, this big PR becomes a have-to thing. According my previous idea, we can replace macaron step by step but I'm wrong. :( Below is a list of big changes on this PR. - [x] Define `context.ResponseWriter` interface with an implementation `context.Response`. - [x] Use chi instead of macaron, and also a customize `Route` to wrap chi so that the router usage is similar as before. - [x] Create different routers for `web`, `api`, `internal` and `install` so that the codes will be more clear and no magic . - [x] Use https://github.com/unrolled/render instead of macaron's internal render - [x] Use https://github.com/NYTimes/gziphandler instead of https://gitea.com/macaron/gzip - [x] Use https://gitea.com/go-chi/session which is a modified version of https://gitea.com/macaron/session and removed `nodb` support since it will not be maintained. **BREAK** - [x] Use https://gitea.com/go-chi/captcha which is a modified version of https://gitea.com/macaron/captcha - [x] Use https://gitea.com/go-chi/cache which is a modified version of https://gitea.com/macaron/cache - [x] Use https://gitea.com/go-chi/binding which is a modified version of https://gitea.com/macaron/binding - [x] Use https://github.com/go-chi/cors instead of https://gitea.com/macaron/cors - [x] Dropped https://gitea.com/macaron/i18n and make a new one in `code.gitea.io/gitea/modules/translation` - [x] Move validation form structs from `code.gitea.io/gitea/modules/auth` to `code.gitea.io/gitea/modules/forms` to avoid dependency cycle. - [x] Removed macaron log service because it's not need any more. **BREAK** - [x] All form structs have to be get by `web.GetForm(ctx)` in the route function but not as a function parameter on routes definition. - [x] Move Git HTTP protocol implementation to use routers directly. - [x] Fix the problem that chi routes don't support trailing slash but macaron did. - [x] `/api/v1/swagger` now will be redirect to `/api/swagger` but not render directly so that `APIContext` will not create a html render. Notices: - Chi router don't support request with trailing slash - Integration test `TestUserHeatmap` maybe mysql version related. It's failed on my macOS(mysql 5.7.29 installed via brew) but succeed on CI. Co-authored-by: 6543 <6543@obermui.de>
4 years ago
Move macaron to chi (#14293) Use [chi](https://github.com/go-chi/chi) instead of the forked [macaron](https://gitea.com/macaron/macaron). Since macaron and chi have conflicts with session share, this big PR becomes a have-to thing. According my previous idea, we can replace macaron step by step but I'm wrong. :( Below is a list of big changes on this PR. - [x] Define `context.ResponseWriter` interface with an implementation `context.Response`. - [x] Use chi instead of macaron, and also a customize `Route` to wrap chi so that the router usage is similar as before. - [x] Create different routers for `web`, `api`, `internal` and `install` so that the codes will be more clear and no magic . - [x] Use https://github.com/unrolled/render instead of macaron's internal render - [x] Use https://github.com/NYTimes/gziphandler instead of https://gitea.com/macaron/gzip - [x] Use https://gitea.com/go-chi/session which is a modified version of https://gitea.com/macaron/session and removed `nodb` support since it will not be maintained. **BREAK** - [x] Use https://gitea.com/go-chi/captcha which is a modified version of https://gitea.com/macaron/captcha - [x] Use https://gitea.com/go-chi/cache which is a modified version of https://gitea.com/macaron/cache - [x] Use https://gitea.com/go-chi/binding which is a modified version of https://gitea.com/macaron/binding - [x] Use https://github.com/go-chi/cors instead of https://gitea.com/macaron/cors - [x] Dropped https://gitea.com/macaron/i18n and make a new one in `code.gitea.io/gitea/modules/translation` - [x] Move validation form structs from `code.gitea.io/gitea/modules/auth` to `code.gitea.io/gitea/modules/forms` to avoid dependency cycle. - [x] Removed macaron log service because it's not need any more. **BREAK** - [x] All form structs have to be get by `web.GetForm(ctx)` in the route function but not as a function parameter on routes definition. - [x] Move Git HTTP protocol implementation to use routers directly. - [x] Fix the problem that chi routes don't support trailing slash but macaron did. - [x] `/api/v1/swagger` now will be redirect to `/api/swagger` but not render directly so that `APIContext` will not create a html render. Notices: - Chi router don't support request with trailing slash - Integration test `TestUserHeatmap` maybe mysql version related. It's failed on my macOS(mysql 5.7.29 installed via brew) but succeed on CI. Co-authored-by: 6543 <6543@obermui.de>
4 years ago
Template Repositories (#8768) * Start work on templates Signed-off-by: jolheiser <john.olheiser@gmail.com> * Continue work Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix IsTemplate vs IsGenerated Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tabs vs spaces * Tabs vs Spaces * Add templates to API & start adding tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix integration tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Remove unused User Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move template tests to existing repos Signed-off-by: jolheiser <john.olheiser@gmail.com> * Minor re-check updates and cleanup Signed-off-by: jolheiser <john.olheiser@gmail.com> * make fmt Signed-off-by: jolheiser <john.olheiser@gmail.com> * Test cleanup Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix optionalbool Signed-off-by: jolheiser <john.olheiser@gmail.com> * make fmt Signed-off-by: jolheiser <john.olheiser@gmail.com> * Test fixes and icon change Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add new user and repo for tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tests (finally) Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update meta repo with env variables Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move generation to create page Combine with repo create template Modify API search to prioritize owner for repo Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tests and coverage Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix swagger and JS lint Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix API searching for own private repos Signed-off-by: jolheiser <john.olheiser@gmail.com> * Change wording Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix repo search test. User had a private repo that didn't show up Signed-off-by: jolheiser <john.olheiser@gmail.com> * Another search test fix Signed-off-by: jolheiser <john.olheiser@gmail.com> * Clarify git content Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Feedback updates Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add topics WIP Signed-off-by: jolheiser <john.olheiser@gmail.com> * Finish adding topics Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update locale Signed-off-by: jolheiser <john.olheiser@gmail.com>
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Copyright 2018 The Gitea Authors. All rights reserved.
  3. // Use of this source code is governed by a MIT-style
  4. // license that can be found in the LICENSE file.
  5. package repo
  6. import (
  7. "fmt"
  8. "net/http"
  9. "strings"
  10. "time"
  11. "code.gitea.io/gitea/models"
  12. "code.gitea.io/gitea/modules/context"
  13. "code.gitea.io/gitea/modules/convert"
  14. "code.gitea.io/gitea/modules/git"
  15. "code.gitea.io/gitea/modules/log"
  16. "code.gitea.io/gitea/modules/setting"
  17. api "code.gitea.io/gitea/modules/structs"
  18. "code.gitea.io/gitea/modules/util"
  19. "code.gitea.io/gitea/modules/validation"
  20. "code.gitea.io/gitea/modules/web"
  21. "code.gitea.io/gitea/routers/api/v1/utils"
  22. repo_service "code.gitea.io/gitea/services/repository"
  23. )
  24. var searchOrderByMap = map[string]map[string]models.SearchOrderBy{
  25. "asc": {
  26. "alpha": models.SearchOrderByAlphabetically,
  27. "created": models.SearchOrderByOldest,
  28. "updated": models.SearchOrderByLeastUpdated,
  29. "size": models.SearchOrderBySize,
  30. "id": models.SearchOrderByID,
  31. },
  32. "desc": {
  33. "alpha": models.SearchOrderByAlphabeticallyReverse,
  34. "created": models.SearchOrderByNewest,
  35. "updated": models.SearchOrderByRecentUpdated,
  36. "size": models.SearchOrderBySizeReverse,
  37. "id": models.SearchOrderByIDReverse,
  38. },
  39. }
  40. // Search repositories via options
  41. func Search(ctx *context.APIContext) {
  42. // swagger:operation GET /repos/search repository repoSearch
  43. // ---
  44. // summary: Search for repositories
  45. // produces:
  46. // - application/json
  47. // parameters:
  48. // - name: q
  49. // in: query
  50. // description: keyword
  51. // type: string
  52. // - name: topic
  53. // in: query
  54. // description: Limit search to repositories with keyword as topic
  55. // type: boolean
  56. // - name: includeDesc
  57. // in: query
  58. // description: include search of keyword within repository description
  59. // type: boolean
  60. // - name: uid
  61. // in: query
  62. // description: search only for repos that the user with the given id owns or contributes to
  63. // type: integer
  64. // format: int64
  65. // - name: priority_owner_id
  66. // in: query
  67. // description: repo owner to prioritize in the results
  68. // type: integer
  69. // format: int64
  70. // - name: team_id
  71. // in: query
  72. // description: search only for repos that belong to the given team id
  73. // type: integer
  74. // format: int64
  75. // - name: starredBy
  76. // in: query
  77. // description: search only for repos that the user with the given id has starred
  78. // type: integer
  79. // format: int64
  80. // - name: private
  81. // in: query
  82. // description: include private repositories this user has access to (defaults to true)
  83. // type: boolean
  84. // - name: is_private
  85. // in: query
  86. // description: show only pubic, private or all repositories (defaults to all)
  87. // type: boolean
  88. // - name: template
  89. // in: query
  90. // description: include template repositories this user has access to (defaults to true)
  91. // type: boolean
  92. // - name: archived
  93. // in: query
  94. // description: show only archived, non-archived or all repositories (defaults to all)
  95. // type: boolean
  96. // - name: mode
  97. // in: query
  98. // description: type of repository to search for. Supported values are
  99. // "fork", "source", "mirror" and "collaborative"
  100. // type: string
  101. // - name: exclusive
  102. // in: query
  103. // description: if `uid` is given, search only for repos that the user owns
  104. // type: boolean
  105. // - name: sort
  106. // in: query
  107. // description: sort repos by attribute. Supported values are
  108. // "alpha", "created", "updated", "size", and "id".
  109. // Default is "alpha"
  110. // type: string
  111. // - name: order
  112. // in: query
  113. // description: sort order, either "asc" (ascending) or "desc" (descending).
  114. // Default is "asc", ignored if "sort" is not specified.
  115. // type: string
  116. // - name: page
  117. // in: query
  118. // description: page number of results to return (1-based)
  119. // type: integer
  120. // - name: limit
  121. // in: query
  122. // description: page size of results
  123. // type: integer
  124. // responses:
  125. // "200":
  126. // "$ref": "#/responses/SearchResults"
  127. // "422":
  128. // "$ref": "#/responses/validationError"
  129. opts := &models.SearchRepoOptions{
  130. ListOptions: utils.GetListOptions(ctx),
  131. Actor: ctx.User,
  132. Keyword: strings.Trim(ctx.Query("q"), " "),
  133. OwnerID: ctx.QueryInt64("uid"),
  134. PriorityOwnerID: ctx.QueryInt64("priority_owner_id"),
  135. TeamID: ctx.QueryInt64("team_id"),
  136. TopicOnly: ctx.QueryBool("topic"),
  137. Collaborate: util.OptionalBoolNone,
  138. Private: ctx.IsSigned && (ctx.Query("private") == "" || ctx.QueryBool("private")),
  139. Template: util.OptionalBoolNone,
  140. StarredByID: ctx.QueryInt64("starredBy"),
  141. IncludeDescription: ctx.QueryBool("includeDesc"),
  142. }
  143. if ctx.Query("template") != "" {
  144. opts.Template = util.OptionalBoolOf(ctx.QueryBool("template"))
  145. }
  146. if ctx.QueryBool("exclusive") {
  147. opts.Collaborate = util.OptionalBoolFalse
  148. }
  149. var mode = ctx.Query("mode")
  150. switch mode {
  151. case "source":
  152. opts.Fork = util.OptionalBoolFalse
  153. opts.Mirror = util.OptionalBoolFalse
  154. case "fork":
  155. opts.Fork = util.OptionalBoolTrue
  156. case "mirror":
  157. opts.Mirror = util.OptionalBoolTrue
  158. case "collaborative":
  159. opts.Mirror = util.OptionalBoolFalse
  160. opts.Collaborate = util.OptionalBoolTrue
  161. case "":
  162. default:
  163. ctx.Error(http.StatusUnprocessableEntity, "", fmt.Errorf("Invalid search mode: \"%s\"", mode))
  164. return
  165. }
  166. if ctx.Query("archived") != "" {
  167. opts.Archived = util.OptionalBoolOf(ctx.QueryBool("archived"))
  168. }
  169. if ctx.Query("is_private") != "" {
  170. opts.IsPrivate = util.OptionalBoolOf(ctx.QueryBool("is_private"))
  171. }
  172. var sortMode = ctx.Query("sort")
  173. if len(sortMode) > 0 {
  174. var sortOrder = ctx.Query("order")
  175. if len(sortOrder) == 0 {
  176. sortOrder = "asc"
  177. }
  178. if searchModeMap, ok := searchOrderByMap[sortOrder]; ok {
  179. if orderBy, ok := searchModeMap[sortMode]; ok {
  180. opts.OrderBy = orderBy
  181. } else {
  182. ctx.Error(http.StatusUnprocessableEntity, "", fmt.Errorf("Invalid sort mode: \"%s\"", sortMode))
  183. return
  184. }
  185. } else {
  186. ctx.Error(http.StatusUnprocessableEntity, "", fmt.Errorf("Invalid sort order: \"%s\"", sortOrder))
  187. return
  188. }
  189. }
  190. var err error
  191. repos, count, err := models.SearchRepository(opts)
  192. if err != nil {
  193. ctx.JSON(http.StatusInternalServerError, api.SearchError{
  194. OK: false,
  195. Error: err.Error(),
  196. })
  197. return
  198. }
  199. results := make([]*api.Repository, len(repos))
  200. for i, repo := range repos {
  201. if err = repo.GetOwner(); err != nil {
  202. ctx.JSON(http.StatusInternalServerError, api.SearchError{
  203. OK: false,
  204. Error: err.Error(),
  205. })
  206. return
  207. }
  208. accessMode, err := models.AccessLevel(ctx.User, repo)
  209. if err != nil {
  210. ctx.JSON(http.StatusInternalServerError, api.SearchError{
  211. OK: false,
  212. Error: err.Error(),
  213. })
  214. }
  215. results[i] = convert.ToRepo(repo, accessMode)
  216. }
  217. ctx.SetLinkHeader(int(count), opts.PageSize)
  218. ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", count))
  219. ctx.Header().Set("Access-Control-Expose-Headers", "X-Total-Count, Link")
  220. ctx.JSON(http.StatusOK, api.SearchResults{
  221. OK: true,
  222. Data: results,
  223. })
  224. }
  225. // CreateUserRepo create a repository for a user
  226. func CreateUserRepo(ctx *context.APIContext, owner *models.User, opt api.CreateRepoOption) {
  227. if opt.AutoInit && opt.Readme == "" {
  228. opt.Readme = "Default"
  229. }
  230. repo, err := repo_service.CreateRepository(ctx.User, owner, models.CreateRepoOptions{
  231. Name: opt.Name,
  232. Description: opt.Description,
  233. IssueLabels: opt.IssueLabels,
  234. Gitignores: opt.Gitignores,
  235. License: opt.License,
  236. Readme: opt.Readme,
  237. IsPrivate: opt.Private,
  238. AutoInit: opt.AutoInit,
  239. DefaultBranch: opt.DefaultBranch,
  240. TrustModel: models.ToTrustModel(opt.TrustModel),
  241. IsTemplate: opt.Template,
  242. })
  243. if err != nil {
  244. if models.IsErrRepoAlreadyExist(err) {
  245. ctx.Error(http.StatusConflict, "", "The repository with the same name already exists.")
  246. } else if models.IsErrNameReserved(err) ||
  247. models.IsErrNamePatternNotAllowed(err) {
  248. ctx.Error(http.StatusUnprocessableEntity, "", err)
  249. } else {
  250. ctx.Error(http.StatusInternalServerError, "CreateRepository", err)
  251. }
  252. return
  253. }
  254. // reload repo from db to get a real state after creation
  255. repo, err = models.GetRepositoryByID(repo.ID)
  256. if err != nil {
  257. ctx.Error(http.StatusInternalServerError, "GetRepositoryByID", err)
  258. }
  259. ctx.JSON(http.StatusCreated, convert.ToRepo(repo, models.AccessModeOwner))
  260. }
  261. // Create one repository of mine
  262. func Create(ctx *context.APIContext) {
  263. // swagger:operation POST /user/repos repository user createCurrentUserRepo
  264. // ---
  265. // summary: Create a repository
  266. // consumes:
  267. // - application/json
  268. // produces:
  269. // - application/json
  270. // parameters:
  271. // - name: body
  272. // in: body
  273. // schema:
  274. // "$ref": "#/definitions/CreateRepoOption"
  275. // responses:
  276. // "201":
  277. // "$ref": "#/responses/Repository"
  278. // "409":
  279. // description: The repository with the same name already exists.
  280. // "422":
  281. // "$ref": "#/responses/validationError"
  282. opt := web.GetForm(ctx).(*api.CreateRepoOption)
  283. if ctx.User.IsOrganization() {
  284. // Shouldn't reach this condition, but just in case.
  285. ctx.Error(http.StatusUnprocessableEntity, "", "not allowed creating repository for organization")
  286. return
  287. }
  288. CreateUserRepo(ctx, ctx.User, *opt)
  289. }
  290. // CreateOrgRepoDeprecated create one repository of the organization
  291. func CreateOrgRepoDeprecated(ctx *context.APIContext) {
  292. // swagger:operation POST /org/{org}/repos organization createOrgRepoDeprecated
  293. // ---
  294. // summary: Create a repository in an organization
  295. // deprecated: true
  296. // consumes:
  297. // - application/json
  298. // produces:
  299. // - application/json
  300. // parameters:
  301. // - name: org
  302. // in: path
  303. // description: name of organization
  304. // type: string
  305. // required: true
  306. // - name: body
  307. // in: body
  308. // schema:
  309. // "$ref": "#/definitions/CreateRepoOption"
  310. // responses:
  311. // "201":
  312. // "$ref": "#/responses/Repository"
  313. // "422":
  314. // "$ref": "#/responses/validationError"
  315. // "403":
  316. // "$ref": "#/responses/forbidden"
  317. CreateOrgRepo(ctx)
  318. }
  319. // CreateOrgRepo create one repository of the organization
  320. func CreateOrgRepo(ctx *context.APIContext) {
  321. // swagger:operation POST /orgs/{org}/repos organization createOrgRepo
  322. // ---
  323. // summary: Create a repository in an organization
  324. // consumes:
  325. // - application/json
  326. // produces:
  327. // - application/json
  328. // parameters:
  329. // - name: org
  330. // in: path
  331. // description: name of organization
  332. // type: string
  333. // required: true
  334. // - name: body
  335. // in: body
  336. // schema:
  337. // "$ref": "#/definitions/CreateRepoOption"
  338. // responses:
  339. // "201":
  340. // "$ref": "#/responses/Repository"
  341. // "404":
  342. // "$ref": "#/responses/notFound"
  343. // "403":
  344. // "$ref": "#/responses/forbidden"
  345. opt := web.GetForm(ctx).(*api.CreateRepoOption)
  346. org, err := models.GetOrgByName(ctx.Params(":org"))
  347. if err != nil {
  348. if models.IsErrOrgNotExist(err) {
  349. ctx.Error(http.StatusUnprocessableEntity, "", err)
  350. } else {
  351. ctx.Error(http.StatusInternalServerError, "GetOrgByName", err)
  352. }
  353. return
  354. }
  355. if !models.HasOrgVisible(org, ctx.User) {
  356. ctx.NotFound("HasOrgVisible", nil)
  357. return
  358. }
  359. if !ctx.User.IsAdmin {
  360. canCreate, err := org.CanCreateOrgRepo(ctx.User.ID)
  361. if err != nil {
  362. ctx.Error(http.StatusInternalServerError, "CanCreateOrgRepo", err)
  363. return
  364. } else if !canCreate {
  365. ctx.Error(http.StatusForbidden, "", "Given user is not allowed to create repository in organization.")
  366. return
  367. }
  368. }
  369. CreateUserRepo(ctx, org, *opt)
  370. }
  371. // Get one repository
  372. func Get(ctx *context.APIContext) {
  373. // swagger:operation GET /repos/{owner}/{repo} repository repoGet
  374. // ---
  375. // summary: Get a repository
  376. // produces:
  377. // - application/json
  378. // parameters:
  379. // - name: owner
  380. // in: path
  381. // description: owner of the repo
  382. // type: string
  383. // required: true
  384. // - name: repo
  385. // in: path
  386. // description: name of the repo
  387. // type: string
  388. // required: true
  389. // responses:
  390. // "200":
  391. // "$ref": "#/responses/Repository"
  392. ctx.JSON(http.StatusOK, convert.ToRepo(ctx.Repo.Repository, ctx.Repo.AccessMode))
  393. }
  394. // GetByID returns a single Repository
  395. func GetByID(ctx *context.APIContext) {
  396. // swagger:operation GET /repositories/{id} repository repoGetByID
  397. // ---
  398. // summary: Get a repository by id
  399. // produces:
  400. // - application/json
  401. // parameters:
  402. // - name: id
  403. // in: path
  404. // description: id of the repo to get
  405. // type: integer
  406. // format: int64
  407. // required: true
  408. // responses:
  409. // "200":
  410. // "$ref": "#/responses/Repository"
  411. repo, err := models.GetRepositoryByID(ctx.ParamsInt64(":id"))
  412. if err != nil {
  413. if models.IsErrRepoNotExist(err) {
  414. ctx.NotFound()
  415. } else {
  416. ctx.Error(http.StatusInternalServerError, "GetRepositoryByID", err)
  417. }
  418. return
  419. }
  420. perm, err := models.GetUserRepoPermission(repo, ctx.User)
  421. if err != nil {
  422. ctx.Error(http.StatusInternalServerError, "AccessLevel", err)
  423. return
  424. } else if !perm.HasAccess() {
  425. ctx.NotFound()
  426. return
  427. }
  428. ctx.JSON(http.StatusOK, convert.ToRepo(repo, perm.AccessMode))
  429. }
  430. // Edit edit repository properties
  431. func Edit(ctx *context.APIContext) {
  432. // swagger:operation PATCH /repos/{owner}/{repo} repository repoEdit
  433. // ---
  434. // summary: Edit a repository's properties. Only fields that are set will be changed.
  435. // produces:
  436. // - application/json
  437. // parameters:
  438. // - name: owner
  439. // in: path
  440. // description: owner of the repo to edit
  441. // type: string
  442. // required: true
  443. // - name: repo
  444. // in: path
  445. // description: name of the repo to edit
  446. // type: string
  447. // required: true
  448. // required: true
  449. // - name: body
  450. // in: body
  451. // description: "Properties of a repo that you can edit"
  452. // schema:
  453. // "$ref": "#/definitions/EditRepoOption"
  454. // responses:
  455. // "200":
  456. // "$ref": "#/responses/Repository"
  457. // "403":
  458. // "$ref": "#/responses/forbidden"
  459. // "422":
  460. // "$ref": "#/responses/validationError"
  461. opts := *web.GetForm(ctx).(*api.EditRepoOption)
  462. if err := updateBasicProperties(ctx, opts); err != nil {
  463. return
  464. }
  465. if err := updateRepoUnits(ctx, opts); err != nil {
  466. return
  467. }
  468. if opts.Archived != nil {
  469. if err := updateRepoArchivedState(ctx, opts); err != nil {
  470. return
  471. }
  472. }
  473. if opts.MirrorInterval != nil {
  474. if err := updateMirrorInterval(ctx, opts); err != nil {
  475. return
  476. }
  477. }
  478. ctx.JSON(http.StatusOK, convert.ToRepo(ctx.Repo.Repository, ctx.Repo.AccessMode))
  479. }
  480. // updateBasicProperties updates the basic properties of a repo: Name, Description, Website and Visibility
  481. func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) error {
  482. owner := ctx.Repo.Owner
  483. repo := ctx.Repo.Repository
  484. newRepoName := repo.Name
  485. if opts.Name != nil {
  486. newRepoName = *opts.Name
  487. }
  488. // Check if repository name has been changed and not just a case change
  489. if repo.LowerName != strings.ToLower(newRepoName) {
  490. if err := repo_service.ChangeRepositoryName(ctx.User, repo, newRepoName); err != nil {
  491. switch {
  492. case models.IsErrRepoAlreadyExist(err):
  493. ctx.Error(http.StatusUnprocessableEntity, fmt.Sprintf("repo name is already taken [name: %s]", newRepoName), err)
  494. case models.IsErrNameReserved(err):
  495. ctx.Error(http.StatusUnprocessableEntity, fmt.Sprintf("repo name is reserved [name: %s]", newRepoName), err)
  496. case models.IsErrNamePatternNotAllowed(err):
  497. ctx.Error(http.StatusUnprocessableEntity, fmt.Sprintf("repo name's pattern is not allowed [name: %s, pattern: %s]", newRepoName, err.(models.ErrNamePatternNotAllowed).Pattern), err)
  498. default:
  499. ctx.Error(http.StatusUnprocessableEntity, "ChangeRepositoryName", err)
  500. }
  501. return err
  502. }
  503. log.Trace("Repository name changed: %s/%s -> %s", ctx.Repo.Owner.Name, repo.Name, newRepoName)
  504. }
  505. // Update the name in the repo object for the response
  506. repo.Name = newRepoName
  507. repo.LowerName = strings.ToLower(newRepoName)
  508. if opts.Description != nil {
  509. repo.Description = *opts.Description
  510. }
  511. if opts.Website != nil {
  512. repo.Website = *opts.Website
  513. }
  514. visibilityChanged := false
  515. if opts.Private != nil {
  516. // Visibility of forked repository is forced sync with base repository.
  517. if repo.IsFork {
  518. *opts.Private = repo.BaseRepo.IsPrivate
  519. }
  520. visibilityChanged = repo.IsPrivate != *opts.Private
  521. // when ForcePrivate enabled, you could change public repo to private, but only admin users can change private to public
  522. if visibilityChanged && setting.Repository.ForcePrivate && !*opts.Private && !ctx.User.IsAdmin {
  523. err := fmt.Errorf("cannot change private repository to public")
  524. ctx.Error(http.StatusUnprocessableEntity, "Force Private enabled", err)
  525. return err
  526. }
  527. repo.IsPrivate = *opts.Private
  528. }
  529. if opts.Template != nil {
  530. repo.IsTemplate = *opts.Template
  531. }
  532. if ctx.Repo.GitRepo == nil {
  533. var err error
  534. ctx.Repo.GitRepo, err = git.OpenRepository(ctx.Repo.Repository.RepoPath())
  535. if err != nil {
  536. ctx.Error(http.StatusInternalServerError, "Unable to OpenRepository", err)
  537. return err
  538. }
  539. defer ctx.Repo.GitRepo.Close()
  540. }
  541. // Default branch only updated if changed and exist or the repository is empty
  542. if opts.DefaultBranch != nil &&
  543. repo.DefaultBranch != *opts.DefaultBranch &&
  544. (ctx.Repo.Repository.IsEmpty || ctx.Repo.GitRepo.IsBranchExist(*opts.DefaultBranch)) {
  545. if err := ctx.Repo.GitRepo.SetDefaultBranch(*opts.DefaultBranch); err != nil {
  546. if !git.IsErrUnsupportedVersion(err) {
  547. ctx.Error(http.StatusInternalServerError, "SetDefaultBranch", err)
  548. return err
  549. }
  550. }
  551. repo.DefaultBranch = *opts.DefaultBranch
  552. }
  553. if err := models.UpdateRepository(repo, visibilityChanged); err != nil {
  554. ctx.Error(http.StatusInternalServerError, "UpdateRepository", err)
  555. return err
  556. }
  557. log.Trace("Repository basic settings updated: %s/%s", owner.Name, repo.Name)
  558. return nil
  559. }
  560. // updateRepoUnits updates repo units: Issue settings, Wiki settings, PR settings
  561. func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
  562. owner := ctx.Repo.Owner
  563. repo := ctx.Repo.Repository
  564. var units []models.RepoUnit
  565. var deleteUnitTypes []models.UnitType
  566. if opts.HasIssues != nil {
  567. if *opts.HasIssues && opts.ExternalTracker != nil && !models.UnitTypeExternalTracker.UnitGlobalDisabled() {
  568. // Check that values are valid
  569. if !validation.IsValidExternalURL(opts.ExternalTracker.ExternalTrackerURL) {
  570. err := fmt.Errorf("External tracker URL not valid")
  571. ctx.Error(http.StatusUnprocessableEntity, "Invalid external tracker URL", err)
  572. return err
  573. }
  574. if len(opts.ExternalTracker.ExternalTrackerFormat) != 0 && !validation.IsValidExternalTrackerURLFormat(opts.ExternalTracker.ExternalTrackerFormat) {
  575. err := fmt.Errorf("External tracker URL format not valid")
  576. ctx.Error(http.StatusUnprocessableEntity, "Invalid external tracker URL format", err)
  577. return err
  578. }
  579. units = append(units, models.RepoUnit{
  580. RepoID: repo.ID,
  581. Type: models.UnitTypeExternalTracker,
  582. Config: &models.ExternalTrackerConfig{
  583. ExternalTrackerURL: opts.ExternalTracker.ExternalTrackerURL,
  584. ExternalTrackerFormat: opts.ExternalTracker.ExternalTrackerFormat,
  585. ExternalTrackerStyle: opts.ExternalTracker.ExternalTrackerStyle,
  586. },
  587. })
  588. deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeIssues)
  589. } else if *opts.HasIssues && opts.ExternalTracker == nil && !models.UnitTypeIssues.UnitGlobalDisabled() {
  590. // Default to built-in tracker
  591. var config *models.IssuesConfig
  592. if opts.InternalTracker != nil {
  593. config = &models.IssuesConfig{
  594. EnableTimetracker: opts.InternalTracker.EnableTimeTracker,
  595. AllowOnlyContributorsToTrackTime: opts.InternalTracker.AllowOnlyContributorsToTrackTime,
  596. EnableDependencies: opts.InternalTracker.EnableIssueDependencies,
  597. }
  598. } else if unit, err := repo.GetUnit(models.UnitTypeIssues); err != nil {
  599. // Unit type doesn't exist so we make a new config file with default values
  600. config = &models.IssuesConfig{
  601. EnableTimetracker: true,
  602. AllowOnlyContributorsToTrackTime: true,
  603. EnableDependencies: true,
  604. }
  605. } else {
  606. config = unit.IssuesConfig()
  607. }
  608. units = append(units, models.RepoUnit{
  609. RepoID: repo.ID,
  610. Type: models.UnitTypeIssues,
  611. Config: config,
  612. })
  613. deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeExternalTracker)
  614. } else if !*opts.HasIssues {
  615. if !models.UnitTypeExternalTracker.UnitGlobalDisabled() {
  616. deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeExternalTracker)
  617. }
  618. if !models.UnitTypeIssues.UnitGlobalDisabled() {
  619. deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeIssues)
  620. }
  621. }
  622. }
  623. if opts.HasWiki != nil {
  624. if *opts.HasWiki && opts.ExternalWiki != nil && !models.UnitTypeExternalWiki.UnitGlobalDisabled() {
  625. // Check that values are valid
  626. if !validation.IsValidExternalURL(opts.ExternalWiki.ExternalWikiURL) {
  627. err := fmt.Errorf("External wiki URL not valid")
  628. ctx.Error(http.StatusUnprocessableEntity, "", "Invalid external wiki URL")
  629. return err
  630. }
  631. units = append(units, models.RepoUnit{
  632. RepoID: repo.ID,
  633. Type: models.UnitTypeExternalWiki,
  634. Config: &models.ExternalWikiConfig{
  635. ExternalWikiURL: opts.ExternalWiki.ExternalWikiURL,
  636. },
  637. })
  638. deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeWiki)
  639. } else if *opts.HasWiki && opts.ExternalWiki == nil && !models.UnitTypeWiki.UnitGlobalDisabled() {
  640. config := &models.UnitConfig{}
  641. units = append(units, models.RepoUnit{
  642. RepoID: repo.ID,
  643. Type: models.UnitTypeWiki,
  644. Config: config,
  645. })
  646. deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeExternalWiki)
  647. } else if !*opts.HasWiki {
  648. if !models.UnitTypeExternalWiki.UnitGlobalDisabled() {
  649. deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeExternalWiki)
  650. }
  651. if !models.UnitTypeWiki.UnitGlobalDisabled() {
  652. deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeWiki)
  653. }
  654. }
  655. }
  656. if opts.HasPullRequests != nil {
  657. if *opts.HasPullRequests && !models.UnitTypePullRequests.UnitGlobalDisabled() {
  658. // We do allow setting individual PR settings through the API, so
  659. // we get the config settings and then set them
  660. // if those settings were provided in the opts.
  661. unit, err := repo.GetUnit(models.UnitTypePullRequests)
  662. var config *models.PullRequestsConfig
  663. if err != nil {
  664. // Unit type doesn't exist so we make a new config file with default values
  665. config = &models.PullRequestsConfig{
  666. IgnoreWhitespaceConflicts: false,
  667. AllowMerge: true,
  668. AllowRebase: true,
  669. AllowRebaseMerge: true,
  670. AllowSquash: true,
  671. AllowManualMerge: true,
  672. AutodetectManualMerge: false,
  673. }
  674. } else {
  675. config = unit.PullRequestsConfig()
  676. }
  677. if opts.IgnoreWhitespaceConflicts != nil {
  678. config.IgnoreWhitespaceConflicts = *opts.IgnoreWhitespaceConflicts
  679. }
  680. if opts.AllowMerge != nil {
  681. config.AllowMerge = *opts.AllowMerge
  682. }
  683. if opts.AllowRebase != nil {
  684. config.AllowRebase = *opts.AllowRebase
  685. }
  686. if opts.AllowRebaseMerge != nil {
  687. config.AllowRebaseMerge = *opts.AllowRebaseMerge
  688. }
  689. if opts.AllowSquash != nil {
  690. config.AllowSquash = *opts.AllowSquash
  691. }
  692. if opts.AllowManualMerge != nil {
  693. config.AllowManualMerge = *opts.AllowManualMerge
  694. }
  695. if opts.AutodetectManualMerge != nil {
  696. config.AutodetectManualMerge = *opts.AutodetectManualMerge
  697. }
  698. units = append(units, models.RepoUnit{
  699. RepoID: repo.ID,
  700. Type: models.UnitTypePullRequests,
  701. Config: config,
  702. })
  703. } else if !*opts.HasPullRequests && !models.UnitTypePullRequests.UnitGlobalDisabled() {
  704. deleteUnitTypes = append(deleteUnitTypes, models.UnitTypePullRequests)
  705. }
  706. }
  707. if opts.HasProjects != nil && !models.UnitTypeProjects.UnitGlobalDisabled() {
  708. if *opts.HasProjects {
  709. units = append(units, models.RepoUnit{
  710. RepoID: repo.ID,
  711. Type: models.UnitTypeProjects,
  712. })
  713. } else {
  714. deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeProjects)
  715. }
  716. }
  717. if err := models.UpdateRepositoryUnits(repo, units, deleteUnitTypes); err != nil {
  718. ctx.Error(http.StatusInternalServerError, "UpdateRepositoryUnits", err)
  719. return err
  720. }
  721. log.Trace("Repository advanced settings updated: %s/%s", owner.Name, repo.Name)
  722. return nil
  723. }
  724. // updateRepoArchivedState updates repo's archive state
  725. func updateRepoArchivedState(ctx *context.APIContext, opts api.EditRepoOption) error {
  726. repo := ctx.Repo.Repository
  727. // archive / un-archive
  728. if opts.Archived != nil {
  729. if repo.IsMirror {
  730. err := fmt.Errorf("repo is a mirror, cannot archive/un-archive")
  731. ctx.Error(http.StatusUnprocessableEntity, err.Error(), err)
  732. return err
  733. }
  734. if *opts.Archived {
  735. if err := repo.SetArchiveRepoState(*opts.Archived); err != nil {
  736. log.Error("Tried to archive a repo: %s", err)
  737. ctx.Error(http.StatusInternalServerError, "ArchiveRepoState", err)
  738. return err
  739. }
  740. log.Trace("Repository was archived: %s/%s", ctx.Repo.Owner.Name, repo.Name)
  741. } else {
  742. if err := repo.SetArchiveRepoState(*opts.Archived); err != nil {
  743. log.Error("Tried to un-archive a repo: %s", err)
  744. ctx.Error(http.StatusInternalServerError, "ArchiveRepoState", err)
  745. return err
  746. }
  747. log.Trace("Repository was un-archived: %s/%s", ctx.Repo.Owner.Name, repo.Name)
  748. }
  749. }
  750. return nil
  751. }
  752. // updateMirrorInterval updates the repo's mirror Interval
  753. func updateMirrorInterval(ctx *context.APIContext, opts api.EditRepoOption) error {
  754. repo := ctx.Repo.Repository
  755. if opts.MirrorInterval != nil {
  756. if !repo.IsMirror {
  757. err := fmt.Errorf("repo is not a mirror, can not change mirror interval")
  758. ctx.Error(http.StatusUnprocessableEntity, err.Error(), err)
  759. return err
  760. }
  761. if err := repo.GetMirror(); err != nil {
  762. log.Error("Failed to get mirror: %s", err)
  763. ctx.Error(http.StatusInternalServerError, "MirrorInterval", err)
  764. return err
  765. }
  766. if interval, err := time.ParseDuration(*opts.MirrorInterval); err == nil {
  767. repo.Mirror.Interval = interval
  768. if err := models.UpdateMirror(repo.Mirror); err != nil {
  769. log.Error("Failed to Set Mirror Interval: %s", err)
  770. ctx.Error(http.StatusUnprocessableEntity, "MirrorInterval", err)
  771. return err
  772. }
  773. log.Trace("Repository %s/%s Mirror Interval was Updated to %s", ctx.Repo.Owner.Name, repo.Name, interval)
  774. } else {
  775. log.Error("Wrong format for MirrorInternal Sent: %s", err)
  776. ctx.Error(http.StatusUnprocessableEntity, "MirrorInterval", err)
  777. return err
  778. }
  779. }
  780. return nil
  781. }
  782. // Delete one repository
  783. func Delete(ctx *context.APIContext) {
  784. // swagger:operation DELETE /repos/{owner}/{repo} repository repoDelete
  785. // ---
  786. // summary: Delete a repository
  787. // produces:
  788. // - application/json
  789. // parameters:
  790. // - name: owner
  791. // in: path
  792. // description: owner of the repo to delete
  793. // type: string
  794. // required: true
  795. // - name: repo
  796. // in: path
  797. // description: name of the repo to delete
  798. // type: string
  799. // required: true
  800. // responses:
  801. // "204":
  802. // "$ref": "#/responses/empty"
  803. // "403":
  804. // "$ref": "#/responses/forbidden"
  805. owner := ctx.Repo.Owner
  806. repo := ctx.Repo.Repository
  807. canDelete, err := repo.CanUserDelete(ctx.User)
  808. if err != nil {
  809. ctx.Error(http.StatusInternalServerError, "CanUserDelete", err)
  810. return
  811. } else if !canDelete {
  812. ctx.Error(http.StatusForbidden, "", "Given user is not owner of organization.")
  813. return
  814. }
  815. if err := repo_service.DeleteRepository(ctx.User, repo); err != nil {
  816. ctx.Error(http.StatusInternalServerError, "DeleteRepository", err)
  817. return
  818. }
  819. log.Trace("Repository deleted: %s/%s", owner.Name, repo.Name)
  820. ctx.Status(http.StatusNoContent)
  821. }
  822. // GetIssueTemplates returns the issue templates for a repository
  823. func GetIssueTemplates(ctx *context.APIContext) {
  824. // swagger:operation GET /repos/{owner}/{repo}/issue_templates repository repoGetIssueTemplates
  825. // ---
  826. // summary: Get available issue templates for a repository
  827. // produces:
  828. // - application/json
  829. // parameters:
  830. // - name: owner
  831. // in: path
  832. // description: owner of the repo
  833. // type: string
  834. // required: true
  835. // - name: repo
  836. // in: path
  837. // description: name of the repo
  838. // type: string
  839. // required: true
  840. // responses:
  841. // "200":
  842. // "$ref": "#/responses/IssueTemplates"
  843. ctx.JSON(http.StatusOK, ctx.IssueTemplatesFromDefaultBranch())
  844. }