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 25 kB

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
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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803
  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. "code.gitea.io/gitea/models"
  11. "code.gitea.io/gitea/modules/context"
  12. "code.gitea.io/gitea/modules/git"
  13. "code.gitea.io/gitea/modules/log"
  14. "code.gitea.io/gitea/modules/setting"
  15. api "code.gitea.io/gitea/modules/structs"
  16. "code.gitea.io/gitea/modules/util"
  17. "code.gitea.io/gitea/modules/validation"
  18. "code.gitea.io/gitea/routers/api/v1/utils"
  19. repo_service "code.gitea.io/gitea/services/repository"
  20. )
  21. var searchOrderByMap = map[string]map[string]models.SearchOrderBy{
  22. "asc": {
  23. "alpha": models.SearchOrderByAlphabetically,
  24. "created": models.SearchOrderByOldest,
  25. "updated": models.SearchOrderByLeastUpdated,
  26. "size": models.SearchOrderBySize,
  27. "id": models.SearchOrderByID,
  28. },
  29. "desc": {
  30. "alpha": models.SearchOrderByAlphabeticallyReverse,
  31. "created": models.SearchOrderByNewest,
  32. "updated": models.SearchOrderByRecentUpdated,
  33. "size": models.SearchOrderBySizeReverse,
  34. "id": models.SearchOrderByIDReverse,
  35. },
  36. }
  37. // Search repositories via options
  38. func Search(ctx *context.APIContext) {
  39. // swagger:operation GET /repos/search repository repoSearch
  40. // ---
  41. // summary: Search for repositories
  42. // produces:
  43. // - application/json
  44. // parameters:
  45. // - name: q
  46. // in: query
  47. // description: keyword
  48. // type: string
  49. // - name: topic
  50. // in: query
  51. // description: Limit search to repositories with keyword as topic
  52. // type: boolean
  53. // - name: includeDesc
  54. // in: query
  55. // description: include search of keyword within repository description
  56. // type: boolean
  57. // - name: uid
  58. // in: query
  59. // description: search only for repos that the user with the given id owns or contributes to
  60. // type: integer
  61. // format: int64
  62. // - name: priority_owner_id
  63. // in: query
  64. // description: repo owner to prioritize in the results
  65. // type: integer
  66. // format: int64
  67. // - name: starredBy
  68. // in: query
  69. // description: search only for repos that the user with the given id has starred
  70. // type: integer
  71. // format: int64
  72. // - name: private
  73. // in: query
  74. // description: include private repositories this user has access to (defaults to true)
  75. // type: boolean
  76. // - name: is_private
  77. // in: query
  78. // description: show only pubic, private or all repositories (defaults to all)
  79. // type: boolean
  80. // - name: template
  81. // in: query
  82. // description: include template repositories this user has access to (defaults to true)
  83. // type: boolean
  84. // - name: archived
  85. // in: query
  86. // description: show only archived, non-archived or all repositories (defaults to all)
  87. // type: boolean
  88. // - name: mode
  89. // in: query
  90. // description: type of repository to search for. Supported values are
  91. // "fork", "source", "mirror" and "collaborative"
  92. // type: string
  93. // - name: exclusive
  94. // in: query
  95. // description: if `uid` is given, search only for repos that the user owns
  96. // type: boolean
  97. // - name: sort
  98. // in: query
  99. // description: sort repos by attribute. Supported values are
  100. // "alpha", "created", "updated", "size", and "id".
  101. // Default is "alpha"
  102. // type: string
  103. // - name: order
  104. // in: query
  105. // description: sort order, either "asc" (ascending) or "desc" (descending).
  106. // Default is "asc", ignored if "sort" is not specified.
  107. // type: string
  108. // - name: page
  109. // in: query
  110. // description: page number of results to return (1-based)
  111. // type: integer
  112. // - name: limit
  113. // in: query
  114. // description: page size of results
  115. // type: integer
  116. // responses:
  117. // "200":
  118. // "$ref": "#/responses/SearchResults"
  119. // "422":
  120. // "$ref": "#/responses/validationError"
  121. opts := &models.SearchRepoOptions{
  122. ListOptions: utils.GetListOptions(ctx),
  123. Actor: ctx.User,
  124. Keyword: strings.Trim(ctx.Query("q"), " "),
  125. OwnerID: ctx.QueryInt64("uid"),
  126. PriorityOwnerID: ctx.QueryInt64("priority_owner_id"),
  127. TopicOnly: ctx.QueryBool("topic"),
  128. Collaborate: util.OptionalBoolNone,
  129. Private: ctx.IsSigned && (ctx.Query("private") == "" || ctx.QueryBool("private")),
  130. Template: util.OptionalBoolNone,
  131. StarredByID: ctx.QueryInt64("starredBy"),
  132. IncludeDescription: ctx.QueryBool("includeDesc"),
  133. }
  134. if ctx.Query("template") != "" {
  135. opts.Template = util.OptionalBoolOf(ctx.QueryBool("template"))
  136. }
  137. if ctx.QueryBool("exclusive") {
  138. opts.Collaborate = util.OptionalBoolFalse
  139. }
  140. var mode = ctx.Query("mode")
  141. switch mode {
  142. case "source":
  143. opts.Fork = util.OptionalBoolFalse
  144. opts.Mirror = util.OptionalBoolFalse
  145. case "fork":
  146. opts.Fork = util.OptionalBoolTrue
  147. case "mirror":
  148. opts.Mirror = util.OptionalBoolTrue
  149. case "collaborative":
  150. opts.Mirror = util.OptionalBoolFalse
  151. opts.Collaborate = util.OptionalBoolTrue
  152. case "":
  153. default:
  154. ctx.Error(http.StatusUnprocessableEntity, "", fmt.Errorf("Invalid search mode: \"%s\"", mode))
  155. return
  156. }
  157. if ctx.Query("archived") != "" {
  158. opts.Archived = util.OptionalBoolOf(ctx.QueryBool("archived"))
  159. }
  160. if ctx.Query("is_private") != "" {
  161. opts.IsPrivate = util.OptionalBoolOf(ctx.QueryBool("is_private"))
  162. }
  163. var sortMode = ctx.Query("sort")
  164. if len(sortMode) > 0 {
  165. var sortOrder = ctx.Query("order")
  166. if len(sortOrder) == 0 {
  167. sortOrder = "asc"
  168. }
  169. if searchModeMap, ok := searchOrderByMap[sortOrder]; ok {
  170. if orderBy, ok := searchModeMap[sortMode]; ok {
  171. opts.OrderBy = orderBy
  172. } else {
  173. ctx.Error(http.StatusUnprocessableEntity, "", fmt.Errorf("Invalid sort mode: \"%s\"", sortMode))
  174. return
  175. }
  176. } else {
  177. ctx.Error(http.StatusUnprocessableEntity, "", fmt.Errorf("Invalid sort order: \"%s\"", sortOrder))
  178. return
  179. }
  180. }
  181. var err error
  182. repos, count, err := models.SearchRepository(opts)
  183. if err != nil {
  184. ctx.JSON(http.StatusInternalServerError, api.SearchError{
  185. OK: false,
  186. Error: err.Error(),
  187. })
  188. return
  189. }
  190. results := make([]*api.Repository, len(repos))
  191. for i, repo := range repos {
  192. if err = repo.GetOwner(); err != nil {
  193. ctx.JSON(http.StatusInternalServerError, api.SearchError{
  194. OK: false,
  195. Error: err.Error(),
  196. })
  197. return
  198. }
  199. accessMode, err := models.AccessLevel(ctx.User, repo)
  200. if err != nil {
  201. ctx.JSON(http.StatusInternalServerError, api.SearchError{
  202. OK: false,
  203. Error: err.Error(),
  204. })
  205. }
  206. results[i] = repo.APIFormat(accessMode)
  207. }
  208. ctx.SetLinkHeader(int(count), opts.PageSize)
  209. ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", count))
  210. ctx.Header().Set("Access-Control-Expose-Headers", "X-Total-Count, Link")
  211. ctx.JSON(http.StatusOK, api.SearchResults{
  212. OK: true,
  213. Data: results,
  214. })
  215. }
  216. // CreateUserRepo create a repository for a user
  217. func CreateUserRepo(ctx *context.APIContext, owner *models.User, opt api.CreateRepoOption) {
  218. if opt.AutoInit && opt.Readme == "" {
  219. opt.Readme = "Default"
  220. }
  221. repo, err := repo_service.CreateRepository(ctx.User, owner, models.CreateRepoOptions{
  222. Name: opt.Name,
  223. Description: opt.Description,
  224. IssueLabels: opt.IssueLabels,
  225. Gitignores: opt.Gitignores,
  226. License: opt.License,
  227. Readme: opt.Readme,
  228. IsPrivate: opt.Private,
  229. AutoInit: opt.AutoInit,
  230. DefaultBranch: opt.DefaultBranch,
  231. })
  232. if err != nil {
  233. if models.IsErrRepoAlreadyExist(err) {
  234. ctx.Error(http.StatusConflict, "", "The repository with the same name already exists.")
  235. } else if models.IsErrNameReserved(err) ||
  236. models.IsErrNamePatternNotAllowed(err) {
  237. ctx.Error(http.StatusUnprocessableEntity, "", err)
  238. } else {
  239. ctx.Error(http.StatusInternalServerError, "CreateRepository", err)
  240. }
  241. return
  242. }
  243. ctx.JSON(http.StatusCreated, repo.APIFormat(models.AccessModeOwner))
  244. }
  245. // Create one repository of mine
  246. func Create(ctx *context.APIContext, opt api.CreateRepoOption) {
  247. // swagger:operation POST /user/repos repository user createCurrentUserRepo
  248. // ---
  249. // summary: Create a repository
  250. // consumes:
  251. // - application/json
  252. // produces:
  253. // - application/json
  254. // parameters:
  255. // - name: body
  256. // in: body
  257. // schema:
  258. // "$ref": "#/definitions/CreateRepoOption"
  259. // responses:
  260. // "201":
  261. // "$ref": "#/responses/Repository"
  262. // "409":
  263. // description: The repository with the same name already exists.
  264. // "422":
  265. // "$ref": "#/responses/validationError"
  266. if ctx.User.IsOrganization() {
  267. // Shouldn't reach this condition, but just in case.
  268. ctx.Error(http.StatusUnprocessableEntity, "", "not allowed creating repository for organization")
  269. return
  270. }
  271. CreateUserRepo(ctx, ctx.User, opt)
  272. }
  273. // CreateOrgRepoDeprecated create one repository of the organization
  274. func CreateOrgRepoDeprecated(ctx *context.APIContext, opt api.CreateRepoOption) {
  275. // swagger:operation POST /org/{org}/repos organization createOrgRepoDeprecated
  276. // ---
  277. // summary: Create a repository in an organization
  278. // deprecated: true
  279. // consumes:
  280. // - application/json
  281. // produces:
  282. // - application/json
  283. // parameters:
  284. // - name: org
  285. // in: path
  286. // description: name of organization
  287. // type: string
  288. // required: true
  289. // - name: body
  290. // in: body
  291. // schema:
  292. // "$ref": "#/definitions/CreateRepoOption"
  293. // responses:
  294. // "201":
  295. // "$ref": "#/responses/Repository"
  296. // "422":
  297. // "$ref": "#/responses/validationError"
  298. // "403":
  299. // "$ref": "#/responses/forbidden"
  300. CreateOrgRepo(ctx, opt)
  301. }
  302. // CreateOrgRepo create one repository of the organization
  303. func CreateOrgRepo(ctx *context.APIContext, opt api.CreateRepoOption) {
  304. // swagger:operation POST /orgs/{org}/repos organization createOrgRepo
  305. // ---
  306. // summary: Create a repository in an organization
  307. // consumes:
  308. // - application/json
  309. // produces:
  310. // - application/json
  311. // parameters:
  312. // - name: org
  313. // in: path
  314. // description: name of organization
  315. // type: string
  316. // required: true
  317. // - name: body
  318. // in: body
  319. // schema:
  320. // "$ref": "#/definitions/CreateRepoOption"
  321. // responses:
  322. // "201":
  323. // "$ref": "#/responses/Repository"
  324. // "404":
  325. // "$ref": "#/responses/notFound"
  326. // "403":
  327. // "$ref": "#/responses/forbidden"
  328. org, err := models.GetOrgByName(ctx.Params(":org"))
  329. if err != nil {
  330. if models.IsErrOrgNotExist(err) {
  331. ctx.Error(http.StatusUnprocessableEntity, "", err)
  332. } else {
  333. ctx.Error(http.StatusInternalServerError, "GetOrgByName", err)
  334. }
  335. return
  336. }
  337. if !models.HasOrgVisible(org, ctx.User) {
  338. ctx.NotFound("HasOrgVisible", nil)
  339. return
  340. }
  341. if !ctx.User.IsAdmin {
  342. canCreate, err := org.CanCreateOrgRepo(ctx.User.ID)
  343. if err != nil {
  344. ctx.ServerError("CanCreateOrgRepo", err)
  345. return
  346. } else if !canCreate {
  347. ctx.Error(http.StatusForbidden, "", "Given user is not allowed to create repository in organization.")
  348. return
  349. }
  350. }
  351. CreateUserRepo(ctx, org, opt)
  352. }
  353. // Get one repository
  354. func Get(ctx *context.APIContext) {
  355. // swagger:operation GET /repos/{owner}/{repo} repository repoGet
  356. // ---
  357. // summary: Get a repository
  358. // produces:
  359. // - application/json
  360. // parameters:
  361. // - name: owner
  362. // in: path
  363. // description: owner of the repo
  364. // type: string
  365. // required: true
  366. // - name: repo
  367. // in: path
  368. // description: name of the repo
  369. // type: string
  370. // required: true
  371. // responses:
  372. // "200":
  373. // "$ref": "#/responses/Repository"
  374. ctx.JSON(http.StatusOK, ctx.Repo.Repository.APIFormat(ctx.Repo.AccessMode))
  375. }
  376. // GetByID returns a single Repository
  377. func GetByID(ctx *context.APIContext) {
  378. // swagger:operation GET /repositories/{id} repository repoGetByID
  379. // ---
  380. // summary: Get a repository by id
  381. // produces:
  382. // - application/json
  383. // parameters:
  384. // - name: id
  385. // in: path
  386. // description: id of the repo to get
  387. // type: integer
  388. // format: int64
  389. // required: true
  390. // responses:
  391. // "200":
  392. // "$ref": "#/responses/Repository"
  393. repo, err := models.GetRepositoryByID(ctx.ParamsInt64(":id"))
  394. if err != nil {
  395. if models.IsErrRepoNotExist(err) {
  396. ctx.NotFound()
  397. } else {
  398. ctx.Error(http.StatusInternalServerError, "GetRepositoryByID", err)
  399. }
  400. return
  401. }
  402. perm, err := models.GetUserRepoPermission(repo, ctx.User)
  403. if err != nil {
  404. ctx.Error(http.StatusInternalServerError, "AccessLevel", err)
  405. return
  406. } else if !perm.HasAccess() {
  407. ctx.NotFound()
  408. return
  409. }
  410. ctx.JSON(http.StatusOK, repo.APIFormat(perm.AccessMode))
  411. }
  412. // Edit edit repository properties
  413. func Edit(ctx *context.APIContext, opts api.EditRepoOption) {
  414. // swagger:operation PATCH /repos/{owner}/{repo} repository repoEdit
  415. // ---
  416. // summary: Edit a repository's properties. Only fields that are set will be changed.
  417. // produces:
  418. // - application/json
  419. // parameters:
  420. // - name: owner
  421. // in: path
  422. // description: owner of the repo to edit
  423. // type: string
  424. // required: true
  425. // - name: repo
  426. // in: path
  427. // description: name of the repo to edit
  428. // type: string
  429. // required: true
  430. // required: true
  431. // - name: body
  432. // in: body
  433. // description: "Properties of a repo that you can edit"
  434. // schema:
  435. // "$ref": "#/definitions/EditRepoOption"
  436. // responses:
  437. // "200":
  438. // "$ref": "#/responses/Repository"
  439. // "403":
  440. // "$ref": "#/responses/forbidden"
  441. // "422":
  442. // "$ref": "#/responses/validationError"
  443. if err := updateBasicProperties(ctx, opts); err != nil {
  444. return
  445. }
  446. if err := updateRepoUnits(ctx, opts); err != nil {
  447. return
  448. }
  449. if opts.Archived != nil {
  450. if err := updateRepoArchivedState(ctx, opts); err != nil {
  451. return
  452. }
  453. }
  454. ctx.JSON(http.StatusOK, ctx.Repo.Repository.APIFormat(ctx.Repo.AccessMode))
  455. }
  456. // updateBasicProperties updates the basic properties of a repo: Name, Description, Website and Visibility
  457. func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) error {
  458. owner := ctx.Repo.Owner
  459. repo := ctx.Repo.Repository
  460. newRepoName := repo.Name
  461. if opts.Name != nil {
  462. newRepoName = *opts.Name
  463. }
  464. // Check if repository name has been changed and not just a case change
  465. if repo.LowerName != strings.ToLower(newRepoName) {
  466. if err := repo_service.ChangeRepositoryName(ctx.User, repo, newRepoName); err != nil {
  467. switch {
  468. case models.IsErrRepoAlreadyExist(err):
  469. ctx.Error(http.StatusUnprocessableEntity, fmt.Sprintf("repo name is already taken [name: %s]", newRepoName), err)
  470. case models.IsErrNameReserved(err):
  471. ctx.Error(http.StatusUnprocessableEntity, fmt.Sprintf("repo name is reserved [name: %s]", newRepoName), err)
  472. case models.IsErrNamePatternNotAllowed(err):
  473. ctx.Error(http.StatusUnprocessableEntity, fmt.Sprintf("repo name's pattern is not allowed [name: %s, pattern: %s]", newRepoName, err.(models.ErrNamePatternNotAllowed).Pattern), err)
  474. default:
  475. ctx.Error(http.StatusUnprocessableEntity, "ChangeRepositoryName", err)
  476. }
  477. return err
  478. }
  479. log.Trace("Repository name changed: %s/%s -> %s", ctx.Repo.Owner.Name, repo.Name, newRepoName)
  480. }
  481. // Update the name in the repo object for the response
  482. repo.Name = newRepoName
  483. repo.LowerName = strings.ToLower(newRepoName)
  484. if opts.Description != nil {
  485. repo.Description = *opts.Description
  486. }
  487. if opts.Website != nil {
  488. repo.Website = *opts.Website
  489. }
  490. visibilityChanged := false
  491. if opts.Private != nil {
  492. // Visibility of forked repository is forced sync with base repository.
  493. if repo.IsFork {
  494. *opts.Private = repo.BaseRepo.IsPrivate
  495. }
  496. visibilityChanged = repo.IsPrivate != *opts.Private
  497. // when ForcePrivate enabled, you could change public repo to private, but only admin users can change private to public
  498. if visibilityChanged && setting.Repository.ForcePrivate && !*opts.Private && !ctx.User.IsAdmin {
  499. err := fmt.Errorf("cannot change private repository to public")
  500. ctx.Error(http.StatusUnprocessableEntity, "Force Private enabled", err)
  501. return err
  502. }
  503. repo.IsPrivate = *opts.Private
  504. }
  505. if opts.Template != nil {
  506. repo.IsTemplate = *opts.Template
  507. }
  508. // Default branch only updated if changed and exist
  509. if opts.DefaultBranch != nil && repo.DefaultBranch != *opts.DefaultBranch && ctx.Repo.GitRepo.IsBranchExist(*opts.DefaultBranch) {
  510. if err := ctx.Repo.GitRepo.SetDefaultBranch(*opts.DefaultBranch); err != nil {
  511. if !git.IsErrUnsupportedVersion(err) {
  512. ctx.Error(http.StatusInternalServerError, "SetDefaultBranch", err)
  513. return err
  514. }
  515. }
  516. repo.DefaultBranch = *opts.DefaultBranch
  517. }
  518. if err := models.UpdateRepository(repo, visibilityChanged); err != nil {
  519. ctx.Error(http.StatusInternalServerError, "UpdateRepository", err)
  520. return err
  521. }
  522. log.Trace("Repository basic settings updated: %s/%s", owner.Name, repo.Name)
  523. return nil
  524. }
  525. // updateRepoUnits updates repo units: Issue settings, Wiki settings, PR settings
  526. func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
  527. owner := ctx.Repo.Owner
  528. repo := ctx.Repo.Repository
  529. var units []models.RepoUnit
  530. var deleteUnitTypes []models.UnitType
  531. if opts.HasIssues != nil {
  532. if *opts.HasIssues && opts.ExternalTracker != nil && !models.UnitTypeExternalTracker.UnitGlobalDisabled() {
  533. // Check that values are valid
  534. if !validation.IsValidExternalURL(opts.ExternalTracker.ExternalTrackerURL) {
  535. err := fmt.Errorf("External tracker URL not valid")
  536. ctx.Error(http.StatusUnprocessableEntity, "Invalid external tracker URL", err)
  537. return err
  538. }
  539. if len(opts.ExternalTracker.ExternalTrackerFormat) != 0 && !validation.IsValidExternalTrackerURLFormat(opts.ExternalTracker.ExternalTrackerFormat) {
  540. err := fmt.Errorf("External tracker URL format not valid")
  541. ctx.Error(http.StatusUnprocessableEntity, "Invalid external tracker URL format", err)
  542. return err
  543. }
  544. units = append(units, models.RepoUnit{
  545. RepoID: repo.ID,
  546. Type: models.UnitTypeExternalTracker,
  547. Config: &models.ExternalTrackerConfig{
  548. ExternalTrackerURL: opts.ExternalTracker.ExternalTrackerURL,
  549. ExternalTrackerFormat: opts.ExternalTracker.ExternalTrackerFormat,
  550. ExternalTrackerStyle: opts.ExternalTracker.ExternalTrackerStyle,
  551. },
  552. })
  553. deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeIssues)
  554. } else if *opts.HasIssues && opts.ExternalTracker == nil && !models.UnitTypeIssues.UnitGlobalDisabled() {
  555. // Default to built-in tracker
  556. var config *models.IssuesConfig
  557. if opts.InternalTracker != nil {
  558. config = &models.IssuesConfig{
  559. EnableTimetracker: opts.InternalTracker.EnableTimeTracker,
  560. AllowOnlyContributorsToTrackTime: opts.InternalTracker.AllowOnlyContributorsToTrackTime,
  561. EnableDependencies: opts.InternalTracker.EnableIssueDependencies,
  562. }
  563. } else if unit, err := repo.GetUnit(models.UnitTypeIssues); err != nil {
  564. // Unit type doesn't exist so we make a new config file with default values
  565. config = &models.IssuesConfig{
  566. EnableTimetracker: true,
  567. AllowOnlyContributorsToTrackTime: true,
  568. EnableDependencies: true,
  569. }
  570. } else {
  571. config = unit.IssuesConfig()
  572. }
  573. units = append(units, models.RepoUnit{
  574. RepoID: repo.ID,
  575. Type: models.UnitTypeIssues,
  576. Config: config,
  577. })
  578. deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeExternalTracker)
  579. } else if !*opts.HasIssues {
  580. if !models.UnitTypeExternalTracker.UnitGlobalDisabled() {
  581. deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeExternalTracker)
  582. }
  583. if !models.UnitTypeIssues.UnitGlobalDisabled() {
  584. deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeIssues)
  585. }
  586. }
  587. }
  588. if opts.HasWiki != nil {
  589. if *opts.HasWiki && opts.ExternalWiki != nil && !models.UnitTypeExternalWiki.UnitGlobalDisabled() {
  590. // Check that values are valid
  591. if !validation.IsValidExternalURL(opts.ExternalWiki.ExternalWikiURL) {
  592. err := fmt.Errorf("External wiki URL not valid")
  593. ctx.Error(http.StatusUnprocessableEntity, "", "Invalid external wiki URL")
  594. return err
  595. }
  596. units = append(units, models.RepoUnit{
  597. RepoID: repo.ID,
  598. Type: models.UnitTypeExternalWiki,
  599. Config: &models.ExternalWikiConfig{
  600. ExternalWikiURL: opts.ExternalWiki.ExternalWikiURL,
  601. },
  602. })
  603. deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeWiki)
  604. } else if *opts.HasWiki && opts.ExternalWiki == nil && !models.UnitTypeWiki.UnitGlobalDisabled() {
  605. config := &models.UnitConfig{}
  606. units = append(units, models.RepoUnit{
  607. RepoID: repo.ID,
  608. Type: models.UnitTypeWiki,
  609. Config: config,
  610. })
  611. deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeExternalWiki)
  612. } else if !*opts.HasWiki {
  613. if !models.UnitTypeExternalWiki.UnitGlobalDisabled() {
  614. deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeExternalWiki)
  615. }
  616. if !models.UnitTypeWiki.UnitGlobalDisabled() {
  617. deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeWiki)
  618. }
  619. }
  620. }
  621. if opts.HasPullRequests != nil {
  622. if *opts.HasPullRequests && !models.UnitTypePullRequests.UnitGlobalDisabled() {
  623. // We do allow setting individual PR settings through the API, so
  624. // we get the config settings and then set them
  625. // if those settings were provided in the opts.
  626. unit, err := repo.GetUnit(models.UnitTypePullRequests)
  627. var config *models.PullRequestsConfig
  628. if err != nil {
  629. // Unit type doesn't exist so we make a new config file with default values
  630. config = &models.PullRequestsConfig{
  631. IgnoreWhitespaceConflicts: false,
  632. AllowMerge: true,
  633. AllowRebase: true,
  634. AllowRebaseMerge: true,
  635. AllowSquash: true,
  636. }
  637. } else {
  638. config = unit.PullRequestsConfig()
  639. }
  640. if opts.IgnoreWhitespaceConflicts != nil {
  641. config.IgnoreWhitespaceConflicts = *opts.IgnoreWhitespaceConflicts
  642. }
  643. if opts.AllowMerge != nil {
  644. config.AllowMerge = *opts.AllowMerge
  645. }
  646. if opts.AllowRebase != nil {
  647. config.AllowRebase = *opts.AllowRebase
  648. }
  649. if opts.AllowRebaseMerge != nil {
  650. config.AllowRebaseMerge = *opts.AllowRebaseMerge
  651. }
  652. if opts.AllowSquash != nil {
  653. config.AllowSquash = *opts.AllowSquash
  654. }
  655. units = append(units, models.RepoUnit{
  656. RepoID: repo.ID,
  657. Type: models.UnitTypePullRequests,
  658. Config: config,
  659. })
  660. } else if !*opts.HasPullRequests && !models.UnitTypePullRequests.UnitGlobalDisabled() {
  661. deleteUnitTypes = append(deleteUnitTypes, models.UnitTypePullRequests)
  662. }
  663. }
  664. if err := models.UpdateRepositoryUnits(repo, units, deleteUnitTypes); err != nil {
  665. ctx.Error(http.StatusInternalServerError, "UpdateRepositoryUnits", err)
  666. return err
  667. }
  668. log.Trace("Repository advanced settings updated: %s/%s", owner.Name, repo.Name)
  669. return nil
  670. }
  671. // updateRepoArchivedState updates repo's archive state
  672. func updateRepoArchivedState(ctx *context.APIContext, opts api.EditRepoOption) error {
  673. repo := ctx.Repo.Repository
  674. // archive / un-archive
  675. if opts.Archived != nil {
  676. if repo.IsMirror {
  677. err := fmt.Errorf("repo is a mirror, cannot archive/un-archive")
  678. ctx.Error(http.StatusUnprocessableEntity, err.Error(), err)
  679. return err
  680. }
  681. if *opts.Archived {
  682. if err := repo.SetArchiveRepoState(*opts.Archived); err != nil {
  683. log.Error("Tried to archive a repo: %s", err)
  684. ctx.Error(http.StatusInternalServerError, "ArchiveRepoState", err)
  685. return err
  686. }
  687. log.Trace("Repository was archived: %s/%s", ctx.Repo.Owner.Name, repo.Name)
  688. } else {
  689. if err := repo.SetArchiveRepoState(*opts.Archived); err != nil {
  690. log.Error("Tried to un-archive a repo: %s", err)
  691. ctx.Error(http.StatusInternalServerError, "ArchiveRepoState", err)
  692. return err
  693. }
  694. log.Trace("Repository was un-archived: %s/%s", ctx.Repo.Owner.Name, repo.Name)
  695. }
  696. }
  697. return nil
  698. }
  699. // Delete one repository
  700. func Delete(ctx *context.APIContext) {
  701. // swagger:operation DELETE /repos/{owner}/{repo} repository repoDelete
  702. // ---
  703. // summary: Delete a repository
  704. // produces:
  705. // - application/json
  706. // parameters:
  707. // - name: owner
  708. // in: path
  709. // description: owner of the repo to delete
  710. // type: string
  711. // required: true
  712. // - name: repo
  713. // in: path
  714. // description: name of the repo to delete
  715. // type: string
  716. // required: true
  717. // responses:
  718. // "204":
  719. // "$ref": "#/responses/empty"
  720. // "403":
  721. // "$ref": "#/responses/forbidden"
  722. owner := ctx.Repo.Owner
  723. repo := ctx.Repo.Repository
  724. canDelete, err := repo.CanUserDelete(ctx.User)
  725. if err != nil {
  726. ctx.Error(http.StatusInternalServerError, "CanUserDelete", err)
  727. return
  728. } else if !canDelete {
  729. ctx.Error(http.StatusForbidden, "", "Given user is not owner of organization.")
  730. return
  731. }
  732. if err := repo_service.DeleteRepository(ctx.User, repo); err != nil {
  733. ctx.Error(http.StatusInternalServerError, "DeleteRepository", err)
  734. return
  735. }
  736. log.Trace("Repository deleted: %s/%s", owner.Name, repo.Name)
  737. ctx.Status(http.StatusNoContent)
  738. }