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

3036 lines
88 KiB

10 years ago
10 years ago
10 years ago
Repository avatars (#6986) * Repository avatars - first variant of code from old work for gogs - add migration 87 - add new option in app.ini - add en-US locale string - add new class in repository.less * Add changed index.css, remove unused template name * Update en-us doc about configuration options * Add comments to new functions, add new option to docker app.ini * Add comment for lint * Remove variable, not needed * Fix formatting * Update swagger api template * Check if avatar exists * Fix avatar link/path checks * Typo * TEXT column can't have a default value * Fixes: - remove old avatar file on upload - use ID in name of avatar file - users may upload same files - add simple tests * Fix fmt check * Generate PNG instead of "static" GIF * More informative comment * Fix error message * Update avatar upload checks: - add file size check - add new option - update config docs - add new string to en-us locale * Fixes: - use FileHEader field for check file size - add new test - upload big image * Fix formatting * Update comments * Update log message * Removed wrong style - not needed * Use Sync2 to migrate * Update repos list view - bigger avatar - fix html blocks alignment * A little adjust avatar size * Use small icons for explore/repo list * Use new cool avatar preparation func by @lafriks * Missing changes for new function * Remove unused import, move imports * Missed new option definition in app.ini Add file size check in user/profile avatar upload * Use smaller field length for Avatar * Use session to update repo DB data, update DeleteAvatar - use session too * Fix err variable definition * As suggested @lafriks - return as soon as possible, code readability
5 years ago
Repository avatars (#6986) * Repository avatars - first variant of code from old work for gogs - add migration 87 - add new option in app.ini - add en-US locale string - add new class in repository.less * Add changed index.css, remove unused template name * Update en-us doc about configuration options * Add comments to new functions, add new option to docker app.ini * Add comment for lint * Remove variable, not needed * Fix formatting * Update swagger api template * Check if avatar exists * Fix avatar link/path checks * Typo * TEXT column can't have a default value * Fixes: - remove old avatar file on upload - use ID in name of avatar file - users may upload same files - add simple tests * Fix fmt check * Generate PNG instead of "static" GIF * More informative comment * Fix error message * Update avatar upload checks: - add file size check - add new option - update config docs - add new string to en-us locale * Fixes: - use FileHEader field for check file size - add new test - upload big image * Fix formatting * Update comments * Update log message * Removed wrong style - not needed * Use Sync2 to migrate * Update repos list view - bigger avatar - fix html blocks alignment * A little adjust avatar size * Use small icons for explore/repo list * Use new cool avatar preparation func by @lafriks * Missing changes for new function * Remove unused import, move imports * Missed new option definition in app.ini Add file size check in user/profile avatar upload * Use smaller field length for Avatar * Use session to update repo DB data, update DeleteAvatar - use session too * Fix err variable definition * As suggested @lafriks - return as soon as possible, code readability
5 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
Repository avatars (#6986) * Repository avatars - first variant of code from old work for gogs - add migration 87 - add new option in app.ini - add en-US locale string - add new class in repository.less * Add changed index.css, remove unused template name * Update en-us doc about configuration options * Add comments to new functions, add new option to docker app.ini * Add comment for lint * Remove variable, not needed * Fix formatting * Update swagger api template * Check if avatar exists * Fix avatar link/path checks * Typo * TEXT column can't have a default value * Fixes: - remove old avatar file on upload - use ID in name of avatar file - users may upload same files - add simple tests * Fix fmt check * Generate PNG instead of "static" GIF * More informative comment * Fix error message * Update avatar upload checks: - add file size check - add new option - update config docs - add new string to en-us locale * Fixes: - use FileHEader field for check file size - add new test - upload big image * Fix formatting * Update comments * Update log message * Removed wrong style - not needed * Use Sync2 to migrate * Update repos list view - bigger avatar - fix html blocks alignment * A little adjust avatar size * Use small icons for explore/repo list * Use new cool avatar preparation func by @lafriks * Missing changes for new function * Remove unused import, move imports * Missed new option definition in app.ini Add file size check in user/profile avatar upload * Use smaller field length for Avatar * Use session to update repo DB data, update DeleteAvatar - use session too * Fix err variable definition * As suggested @lafriks - return as soon as possible, code readability
5 years ago
Sign merges, CRUD, Wiki and Repository initialisation with gpg key (#7631) This PR fixes #7598 by providing a configurable way of signing commits across the Gitea instance. Per repository configurability and import/generation of trusted secure keys is not provided by this PR - from a security PoV that's probably impossible to do properly. Similarly web-signing, that is asking the user to sign something, is not implemented - this could be done at a later stage however. ## Features - [x] If commit.gpgsign is set in .gitconfig sign commits and files created through repofiles. (merges should already have been signed.) - [x] Verify commits signed with the default gpg as valid - [x] Signer, Committer and Author can all be different - [x] Allow signer to be arbitrarily different - We still require the key to have an activated email on Gitea. A more complete implementation would be to use a keyserver and mark external-or-unactivated with an "unknown" trust level icon. - [x] Add a signing-key.gpg endpoint to get the default gpg pub key if available - Rather than add a fake web-flow user I've added this as an endpoint on /api/v1/signing-key.gpg - [x] Try to match the default key with a user on gitea - this is done at verification time - [x] Make things configurable? - app.ini configuration done - [x] when checking commits are signed need to check if they're actually verifiable too - [x] Add documentation I have decided that adjusting the docker to create a default gpg key is not the correct thing to do and therefore have not implemented this.
5 years ago
10 years ago
10 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
5 years ago
10 years ago
10 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
5 years ago
10 years ago
10 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
Repository avatars (#6986) * Repository avatars - first variant of code from old work for gogs - add migration 87 - add new option in app.ini - add en-US locale string - add new class in repository.less * Add changed index.css, remove unused template name * Update en-us doc about configuration options * Add comments to new functions, add new option to docker app.ini * Add comment for lint * Remove variable, not needed * Fix formatting * Update swagger api template * Check if avatar exists * Fix avatar link/path checks * Typo * TEXT column can't have a default value * Fixes: - remove old avatar file on upload - use ID in name of avatar file - users may upload same files - add simple tests * Fix fmt check * Generate PNG instead of "static" GIF * More informative comment * Fix error message * Update avatar upload checks: - add file size check - add new option - update config docs - add new string to en-us locale * Fixes: - use FileHEader field for check file size - add new test - upload big image * Fix formatting * Update comments * Update log message * Removed wrong style - not needed * Use Sync2 to migrate * Update repos list view - bigger avatar - fix html blocks alignment * A little adjust avatar size * Use small icons for explore/repo list * Use new cool avatar preparation func by @lafriks * Missing changes for new function * Remove unused import, move imports * Missed new option definition in app.ini Add file size check in user/profile avatar upload * Use smaller field length for Avatar * Use session to update repo DB data, update DeleteAvatar - use session too * Fix err variable definition * As suggested @lafriks - return as soon as possible, code readability
5 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
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
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
5 years ago
Check commit message hashes before making links (#7713) * Check commit message hashes before making links Previously, when formatting commit messages, anything that looked like SHA1 hashes was turned into a link using regex. This meant that certain phrases or numbers such as `777777` or `deadbeef` could be recognized as a commit even if the repository has no commit with those hashes. This change will make it so that anything that looks like a SHA1 hash using regex will then also be checked to ensure that there is a commit in the repository with that hash before making a link. Signed-off-by: Gary Kim <gary@garykim.dev> * Use gogit to check if commit exists This commit modifies the commit hash check in the render for commit messages to use gogit for better performance. Signed-off-by: Gary Kim <gary@garykim.dev> * Make code cleaner Signed-off-by: Gary Kim <gary@garykim.dev> * Use rev-parse to check if commit exists Signed-off-by: Gary Kim <gary@garykim.dev> * Add and modify tests for checking hashes in html link rendering Signed-off-by: Gary Kim <gary@garykim.dev> * Return error in sha1CurrentPatternProcessor Co-Authored-By: mrsdizzie <info@mrsdizzie.com> * Import Gitea log module Signed-off-by: Gary Kim <gary@garykim.dev> * Revert "Return error in sha1CurrentPatternProcessor" This reverts commit 28f561cac46ef7e51aa26aefcbe9aca4671366a6. Signed-off-by: Gary Kim <gary@garykim.dev> * Add debug logging to sha1CurrentPatternProcessor This will log errors by the git command run in sha1CurrentPatternProcessor if the error is one that was unexpected. Signed-off-by: Gary Kim <gary@garykim.dev>
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
9 years ago
10 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
5 years ago
10 years ago
9 years ago
9 years ago
9 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
5 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
5 years ago
9 years ago
9 years ago
Sign merges, CRUD, Wiki and Repository initialisation with gpg key (#7631) This PR fixes #7598 by providing a configurable way of signing commits across the Gitea instance. Per repository configurability and import/generation of trusted secure keys is not provided by this PR - from a security PoV that's probably impossible to do properly. Similarly web-signing, that is asking the user to sign something, is not implemented - this could be done at a later stage however. ## Features - [x] If commit.gpgsign is set in .gitconfig sign commits and files created through repofiles. (merges should already have been signed.) - [x] Verify commits signed with the default gpg as valid - [x] Signer, Committer and Author can all be different - [x] Allow signer to be arbitrarily different - We still require the key to have an activated email on Gitea. A more complete implementation would be to use a keyserver and mark external-or-unactivated with an "unknown" trust level icon. - [x] Add a signing-key.gpg endpoint to get the default gpg pub key if available - Rather than add a fake web-flow user I've added this as an endpoint on /api/v1/signing-key.gpg - [x] Try to match the default key with a user on gitea - this is done at verification time - [x] Make things configurable? - app.ini configuration done - [x] when checking commits are signed need to check if they're actually verifiable too - [x] Add documentation I have decided that adjusting the docker to create a default gpg key is not the correct thing to do and therefore have not implemented this.
5 years ago
10 years ago
9 years ago
Sign merges, CRUD, Wiki and Repository initialisation with gpg key (#7631) This PR fixes #7598 by providing a configurable way of signing commits across the Gitea instance. Per repository configurability and import/generation of trusted secure keys is not provided by this PR - from a security PoV that's probably impossible to do properly. Similarly web-signing, that is asking the user to sign something, is not implemented - this could be done at a later stage however. ## Features - [x] If commit.gpgsign is set in .gitconfig sign commits and files created through repofiles. (merges should already have been signed.) - [x] Verify commits signed with the default gpg as valid - [x] Signer, Committer and Author can all be different - [x] Allow signer to be arbitrarily different - We still require the key to have an activated email on Gitea. A more complete implementation would be to use a keyserver and mark external-or-unactivated with an "unknown" trust level icon. - [x] Add a signing-key.gpg endpoint to get the default gpg pub key if available - Rather than add a fake web-flow user I've added this as an endpoint on /api/v1/signing-key.gpg - [x] Try to match the default key with a user on gitea - this is done at verification time - [x] Make things configurable? - app.ini configuration done - [x] when checking commits are signed need to check if they're actually verifiable too - [x] Add documentation I have decided that adjusting the docker to create a default gpg key is not the correct thing to do and therefore have not implemented this.
5 years ago
9 years ago
Sign merges, CRUD, Wiki and Repository initialisation with gpg key (#7631) This PR fixes #7598 by providing a configurable way of signing commits across the Gitea instance. Per repository configurability and import/generation of trusted secure keys is not provided by this PR - from a security PoV that's probably impossible to do properly. Similarly web-signing, that is asking the user to sign something, is not implemented - this could be done at a later stage however. ## Features - [x] If commit.gpgsign is set in .gitconfig sign commits and files created through repofiles. (merges should already have been signed.) - [x] Verify commits signed with the default gpg as valid - [x] Signer, Committer and Author can all be different - [x] Allow signer to be arbitrarily different - We still require the key to have an activated email on Gitea. A more complete implementation would be to use a keyserver and mark external-or-unactivated with an "unknown" trust level icon. - [x] Add a signing-key.gpg endpoint to get the default gpg pub key if available - Rather than add a fake web-flow user I've added this as an endpoint on /api/v1/signing-key.gpg - [x] Try to match the default key with a user on gitea - this is done at verification time - [x] Make things configurable? - app.ini configuration done - [x] when checking commits are signed need to check if they're actually verifiable too - [x] Add documentation I have decided that adjusting the docker to create a default gpg key is not the correct thing to do and therefore have not implemented this.
5 years ago
9 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
Sign merges, CRUD, Wiki and Repository initialisation with gpg key (#7631) This PR fixes #7598 by providing a configurable way of signing commits across the Gitea instance. Per repository configurability and import/generation of trusted secure keys is not provided by this PR - from a security PoV that's probably impossible to do properly. Similarly web-signing, that is asking the user to sign something, is not implemented - this could be done at a later stage however. ## Features - [x] If commit.gpgsign is set in .gitconfig sign commits and files created through repofiles. (merges should already have been signed.) - [x] Verify commits signed with the default gpg as valid - [x] Signer, Committer and Author can all be different - [x] Allow signer to be arbitrarily different - We still require the key to have an activated email on Gitea. A more complete implementation would be to use a keyserver and mark external-or-unactivated with an "unknown" trust level icon. - [x] Add a signing-key.gpg endpoint to get the default gpg pub key if available - Rather than add a fake web-flow user I've added this as an endpoint on /api/v1/signing-key.gpg - [x] Try to match the default key with a user on gitea - this is done at verification time - [x] Make things configurable? - app.ini configuration done - [x] when checking commits are signed need to check if they're actually verifiable too - [x] Add documentation I have decided that adjusting the docker to create a default gpg key is not the correct thing to do and therefore have not implemented this.
5 years ago
Sign merges, CRUD, Wiki and Repository initialisation with gpg key (#7631) This PR fixes #7598 by providing a configurable way of signing commits across the Gitea instance. Per repository configurability and import/generation of trusted secure keys is not provided by this PR - from a security PoV that's probably impossible to do properly. Similarly web-signing, that is asking the user to sign something, is not implemented - this could be done at a later stage however. ## Features - [x] If commit.gpgsign is set in .gitconfig sign commits and files created through repofiles. (merges should already have been signed.) - [x] Verify commits signed with the default gpg as valid - [x] Signer, Committer and Author can all be different - [x] Allow signer to be arbitrarily different - We still require the key to have an activated email on Gitea. A more complete implementation would be to use a keyserver and mark external-or-unactivated with an "unknown" trust level icon. - [x] Add a signing-key.gpg endpoint to get the default gpg pub key if available - Rather than add a fake web-flow user I've added this as an endpoint on /api/v1/signing-key.gpg - [x] Try to match the default key with a user on gitea - this is done at verification time - [x] Make things configurable? - app.ini configuration done - [x] when checking commits are signed need to check if they're actually verifiable too - [x] Add documentation I have decided that adjusting the docker to create a default gpg key is not the correct thing to do and therefore have not implemented this.
5 years ago
Sign merges, CRUD, Wiki and Repository initialisation with gpg key (#7631) This PR fixes #7598 by providing a configurable way of signing commits across the Gitea instance. Per repository configurability and import/generation of trusted secure keys is not provided by this PR - from a security PoV that's probably impossible to do properly. Similarly web-signing, that is asking the user to sign something, is not implemented - this could be done at a later stage however. ## Features - [x] If commit.gpgsign is set in .gitconfig sign commits and files created through repofiles. (merges should already have been signed.) - [x] Verify commits signed with the default gpg as valid - [x] Signer, Committer and Author can all be different - [x] Allow signer to be arbitrarily different - We still require the key to have an activated email on Gitea. A more complete implementation would be to use a keyserver and mark external-or-unactivated with an "unknown" trust level icon. - [x] Add a signing-key.gpg endpoint to get the default gpg pub key if available - Rather than add a fake web-flow user I've added this as an endpoint on /api/v1/signing-key.gpg - [x] Try to match the default key with a user on gitea - this is done at verification time - [x] Make things configurable? - app.ini configuration done - [x] when checking commits are signed need to check if they're actually verifiable too - [x] Add documentation I have decided that adjusting the docker to create a default gpg key is not the correct thing to do and therefore have not implemented this.
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
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
10 years ago
9 years ago
Sign merges, CRUD, Wiki and Repository initialisation with gpg key (#7631) This PR fixes #7598 by providing a configurable way of signing commits across the Gitea instance. Per repository configurability and import/generation of trusted secure keys is not provided by this PR - from a security PoV that's probably impossible to do properly. Similarly web-signing, that is asking the user to sign something, is not implemented - this could be done at a later stage however. ## Features - [x] If commit.gpgsign is set in .gitconfig sign commits and files created through repofiles. (merges should already have been signed.) - [x] Verify commits signed with the default gpg as valid - [x] Signer, Committer and Author can all be different - [x] Allow signer to be arbitrarily different - We still require the key to have an activated email on Gitea. A more complete implementation would be to use a keyserver and mark external-or-unactivated with an "unknown" trust level icon. - [x] Add a signing-key.gpg endpoint to get the default gpg pub key if available - Rather than add a fake web-flow user I've added this as an endpoint on /api/v1/signing-key.gpg - [x] Try to match the default key with a user on gitea - this is done at verification time - [x] Make things configurable? - app.ini configuration done - [x] when checking commits are signed need to check if they're actually verifiable too - [x] Add documentation I have decided that adjusting the docker to create a default gpg key is not the correct thing to do and therefore have not implemented this.
5 years ago
9 years ago
9 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
Feature: Timetracking (#2211) * Added comment's hashtag to url for mail notifications. * Added explanation to return statement + documentation. * Replacing in-line link generation with HTMLURL. (+gofmt) * Replaced action-based model with nil-based model. (+gofmt) * Replaced mailIssueActionToParticipants with mailIssueCommentToParticipants. * Updating comment for mailIssueCommentToParticipants * Added link to comment in "Dashboard" * Deleting feed entry if a comment is going to be deleted * Added migration * Added improved migration to add a CommentID column to action. * Added improved links to comments in feed entries. * Fixes #1956 by filtering for deleted comments that are referenced in actions. * Introducing "IsDeleted" column to action. * Adding design draft (not functional) * Adding database models for stopwatches and trackedtimes * See go-gitea/gitea#967 * Adding design draft (not functional) * Adding translations and improving design * Implementing stopwatch (for timetracking) * Make UI functional * Add hints in timeline for time tracking events * Implementing timetracking feature * Adding "Add time manual" option * Improved stopwatch * Created report of total spent time by user * Only showing total time spent if theire is something to show. * Adding license headers. * Improved error handling for "Add Time Manual" * Adding @sapks 's changes, refactoring * Adding API for feature tracking * Adding unit test * Adding DISABLE/ENABLE option to Repository settings page * Improving translations * Applying @sapk 's changes * Removing repo_unit and using IssuesSetting for disabling/enabling timetracker * Adding DEFAULT_ENABLE_TIMETRACKER to config, installation and admin menu * Improving documentation * Fixing vendor/ folder * Changing timtracking routes by adding subgroups /times and /times/stopwatch (Proposed by @lafriks ) * Restricting write access to timetracking based on the repo settings (Proposed by @lafriks ) * Fixed minor permissions bug. * Adding CanUseTimetracker and IsTimetrackerEnabled in ctx.Repo * Allow assignees and authors to track there time too. * Fixed some build-time-errors + logical errors. * Removing unused Get...ByID functions * Moving IsTimetrackerEnabled from context.Repository to models.Repository * Adding a seperate file for issue related repo functions * Adding license headers * Fixed GetUserByParams return 404 * Moving /users/:username/times to /repos/:username/:reponame/times/:username for security reasons * Adding /repos/:username/times to get all tracked times of the repo * Updating sdk-dependency * Updating swagger.v1.json * Adding warning if user has already a running stopwatch (auto-timetracker) * Replacing GetTrackedTimesBy... with GetTrackedTimes(options FindTrackedTimesOptions) * Changing code.gitea.io/sdk back to code.gitea.io/sdk * Correcting spelling mistake * Updating vendor.json * Changing GET stopwatch/toggle to POST stopwatch/toggle * Changing GET stopwatch/cancel to POST stopwatch/cancel * Added migration for stopwatches/timetracking * Fixed some access bugs for read-only users * Added default allow only contributors to track time value to config * Fixed migration by chaging x.Iterate to x.Find * Resorted imports * Moved Add Time Manually form to repo_form.go * Removed "Seconds" field from Add Time Manually * Resorted imports * Improved permission checking * Fixed some bugs * Added integration test * gofmt * Adding integration test by @lafriks * Added created_unix to comment fixtures * Using last event instead of a fixed event * Adding another integration test by @lafriks * Fixing bug Timetracker enabled causing error 500 at sidebar.tpl * Fixed a refactoring bug that resulted in hiding "HasUserStopwatch" warning. * Returning TrackedTime instead of AddTimeOption at AddTime. * Updating SDK from go-gitea/go-sdk#69 * Resetting Go-SDK back to default repository * Fixing test-vendor by changing ini back to original repository * Adding "tags" to swagger spec * govendor sync * Removed duplicate * Formatting templates * Adding IsTimetrackingEnabled checks to API * Improving translations / english texts * Improving documentation * Updating swagger spec * Fixing integration test caused be translation-changes * Removed encoding issues in local_en-US.ini. * "Added" copyright line * Moved unit.IssuesConfig().EnableTimetracker into a != nil check * Removed some other encoding issues in local_en-US.ini * Improved javascript by checking if data-context exists * Replaced manual comment creation with CreateComment * Removed unnecessary code * Improved error checking * Small cosmetic changes * Replaced int>string>duration parsing with int>duration parsing * Fixed encoding issues * Removed unused imports Signed-off-by: Jonas Franz <info@jonasfranz.software>
7 years ago
Feature: Timetracking (#2211) * Added comment's hashtag to url for mail notifications. * Added explanation to return statement + documentation. * Replacing in-line link generation with HTMLURL. (+gofmt) * Replaced action-based model with nil-based model. (+gofmt) * Replaced mailIssueActionToParticipants with mailIssueCommentToParticipants. * Updating comment for mailIssueCommentToParticipants * Added link to comment in "Dashboard" * Deleting feed entry if a comment is going to be deleted * Added migration * Added improved migration to add a CommentID column to action. * Added improved links to comments in feed entries. * Fixes #1956 by filtering for deleted comments that are referenced in actions. * Introducing "IsDeleted" column to action. * Adding design draft (not functional) * Adding database models for stopwatches and trackedtimes * See go-gitea/gitea#967 * Adding design draft (not functional) * Adding translations and improving design * Implementing stopwatch (for timetracking) * Make UI functional * Add hints in timeline for time tracking events * Implementing timetracking feature * Adding "Add time manual" option * Improved stopwatch * Created report of total spent time by user * Only showing total time spent if theire is something to show. * Adding license headers. * Improved error handling for "Add Time Manual" * Adding @sapks 's changes, refactoring * Adding API for feature tracking * Adding unit test * Adding DISABLE/ENABLE option to Repository settings page * Improving translations * Applying @sapk 's changes * Removing repo_unit and using IssuesSetting for disabling/enabling timetracker * Adding DEFAULT_ENABLE_TIMETRACKER to config, installation and admin menu * Improving documentation * Fixing vendor/ folder * Changing timtracking routes by adding subgroups /times and /times/stopwatch (Proposed by @lafriks ) * Restricting write access to timetracking based on the repo settings (Proposed by @lafriks ) * Fixed minor permissions bug. * Adding CanUseTimetracker and IsTimetrackerEnabled in ctx.Repo * Allow assignees and authors to track there time too. * Fixed some build-time-errors + logical errors. * Removing unused Get...ByID functions * Moving IsTimetrackerEnabled from context.Repository to models.Repository * Adding a seperate file for issue related repo functions * Adding license headers * Fixed GetUserByParams return 404 * Moving /users/:username/times to /repos/:username/:reponame/times/:username for security reasons * Adding /repos/:username/times to get all tracked times of the repo * Updating sdk-dependency * Updating swagger.v1.json * Adding warning if user has already a running stopwatch (auto-timetracker) * Replacing GetTrackedTimesBy... with GetTrackedTimes(options FindTrackedTimesOptions) * Changing code.gitea.io/sdk back to code.gitea.io/sdk * Correcting spelling mistake * Updating vendor.json * Changing GET stopwatch/toggle to POST stopwatch/toggle * Changing GET stopwatch/cancel to POST stopwatch/cancel * Added migration for stopwatches/timetracking * Fixed some access bugs for read-only users * Added default allow only contributors to track time value to config * Fixed migration by chaging x.Iterate to x.Find * Resorted imports * Moved Add Time Manually form to repo_form.go * Removed "Seconds" field from Add Time Manually * Resorted imports * Improved permission checking * Fixed some bugs * Added integration test * gofmt * Adding integration test by @lafriks * Added created_unix to comment fixtures * Using last event instead of a fixed event * Adding another integration test by @lafriks * Fixing bug Timetracker enabled causing error 500 at sidebar.tpl * Fixed a refactoring bug that resulted in hiding "HasUserStopwatch" warning. * Returning TrackedTime instead of AddTimeOption at AddTime. * Updating SDK from go-gitea/go-sdk#69 * Resetting Go-SDK back to default repository * Fixing test-vendor by changing ini back to original repository * Adding "tags" to swagger spec * govendor sync * Removed duplicate * Formatting templates * Adding IsTimetrackingEnabled checks to API * Improving translations / english texts * Improving documentation * Updating swagger spec * Fixing integration test caused be translation-changes * Removed encoding issues in local_en-US.ini. * "Added" copyright line * Moved unit.IssuesConfig().EnableTimetracker into a != nil check * Removed some other encoding issues in local_en-US.ini * Improved javascript by checking if data-context exists * Replaced manual comment creation with CreateComment * Removed unnecessary code * Improved error checking * Small cosmetic changes * Replaced int>string>duration parsing with int>duration parsing * Fixed encoding issues * Removed unused imports Signed-off-by: Jonas Franz <info@jonasfranz.software>
7 years ago
Feature: Timetracking (#2211) * Added comment's hashtag to url for mail notifications. * Added explanation to return statement + documentation. * Replacing in-line link generation with HTMLURL. (+gofmt) * Replaced action-based model with nil-based model. (+gofmt) * Replaced mailIssueActionToParticipants with mailIssueCommentToParticipants. * Updating comment for mailIssueCommentToParticipants * Added link to comment in "Dashboard" * Deleting feed entry if a comment is going to be deleted * Added migration * Added improved migration to add a CommentID column to action. * Added improved links to comments in feed entries. * Fixes #1956 by filtering for deleted comments that are referenced in actions. * Introducing "IsDeleted" column to action. * Adding design draft (not functional) * Adding database models for stopwatches and trackedtimes * See go-gitea/gitea#967 * Adding design draft (not functional) * Adding translations and improving design * Implementing stopwatch (for timetracking) * Make UI functional * Add hints in timeline for time tracking events * Implementing timetracking feature * Adding "Add time manual" option * Improved stopwatch * Created report of total spent time by user * Only showing total time spent if theire is something to show. * Adding license headers. * Improved error handling for "Add Time Manual" * Adding @sapks 's changes, refactoring * Adding API for feature tracking * Adding unit test * Adding DISABLE/ENABLE option to Repository settings page * Improving translations * Applying @sapk 's changes * Removing repo_unit and using IssuesSetting for disabling/enabling timetracker * Adding DEFAULT_ENABLE_TIMETRACKER to config, installation and admin menu * Improving documentation * Fixing vendor/ folder * Changing timtracking routes by adding subgroups /times and /times/stopwatch (Proposed by @lafriks ) * Restricting write access to timetracking based on the repo settings (Proposed by @lafriks ) * Fixed minor permissions bug. * Adding CanUseTimetracker and IsTimetrackerEnabled in ctx.Repo * Allow assignees and authors to track there time too. * Fixed some build-time-errors + logical errors. * Removing unused Get...ByID functions * Moving IsTimetrackerEnabled from context.Repository to models.Repository * Adding a seperate file for issue related repo functions * Adding license headers * Fixed GetUserByParams return 404 * Moving /users/:username/times to /repos/:username/:reponame/times/:username for security reasons * Adding /repos/:username/times to get all tracked times of the repo * Updating sdk-dependency * Updating swagger.v1.json * Adding warning if user has already a running stopwatch (auto-timetracker) * Replacing GetTrackedTimesBy... with GetTrackedTimes(options FindTrackedTimesOptions) * Changing code.gitea.io/sdk back to code.gitea.io/sdk * Correcting spelling mistake * Updating vendor.json * Changing GET stopwatch/toggle to POST stopwatch/toggle * Changing GET stopwatch/cancel to POST stopwatch/cancel * Added migration for stopwatches/timetracking * Fixed some access bugs for read-only users * Added default allow only contributors to track time value to config * Fixed migration by chaging x.Iterate to x.Find * Resorted imports * Moved Add Time Manually form to repo_form.go * Removed "Seconds" field from Add Time Manually * Resorted imports * Improved permission checking * Fixed some bugs * Added integration test * gofmt * Adding integration test by @lafriks * Added created_unix to comment fixtures * Using last event instead of a fixed event * Adding another integration test by @lafriks * Fixing bug Timetracker enabled causing error 500 at sidebar.tpl * Fixed a refactoring bug that resulted in hiding "HasUserStopwatch" warning. * Returning TrackedTime instead of AddTimeOption at AddTime. * Updating SDK from go-gitea/go-sdk#69 * Resetting Go-SDK back to default repository * Fixing test-vendor by changing ini back to original repository * Adding "tags" to swagger spec * govendor sync * Removed duplicate * Formatting templates * Adding IsTimetrackingEnabled checks to API * Improving translations / english texts * Improving documentation * Updating swagger spec * Fixing integration test caused be translation-changes * Removed encoding issues in local_en-US.ini. * "Added" copyright line * Moved unit.IssuesConfig().EnableTimetracker into a != nil check * Removed some other encoding issues in local_en-US.ini * Improved javascript by checking if data-context exists * Replaced manual comment creation with CreateComment * Removed unnecessary code * Improved error checking * Small cosmetic changes * Replaced int>string>duration parsing with int>duration parsing * Fixed encoding issues * Removed unused imports Signed-off-by: Jonas Franz <info@jonasfranz.software>
7 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
5 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
5 years ago
9 years ago
10 years ago
9 years ago
9 years ago
10 years ago
9 years ago
10 years ago
9 years ago
9 years ago
9 years ago
9 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
5 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
5 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
5 years ago
10 years ago
10 years ago
9 years ago
9 years ago
9 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
Git LFS support v2 (#122) * Import github.com/git-lfs/lfs-test-server as lfs module base Imported commit is 3968aac269a77b73924649b9412ae03f7ccd3198 Removed: Dockerfile CONTRIBUTING.md mgmt* script/ vendor/ kvlogger.go .dockerignore .gitignore README.md * Remove config, add JWT support from github.com/mgit-at/lfs-test-server Imported commit f0cdcc5a01599c5a955dc1bbf683bb4acecdba83 * Add LFS settings * Add LFS meta object model * Add LFS routes and initialization * Import github.com/dgrijalva/jwt-go into vendor/ * Adapt LFS module: handlers, routing, meta store * Move LFS routes to /user/repo/info/lfs/* * Add request header checks to LFS BatchHandler / PostHandler * Implement LFS basic authentication * Rework JWT secret generation / load * Implement LFS SSH token authentication with JWT Specification: https://github.com/github/git-lfs/tree/master/docs/api * Integrate LFS settings into install process * Remove LFS objects when repository is deleted Only removes objects from content store when deleted repo is the only referencing repository * Make LFS module stateless Fixes bug where LFS would not work after installation without restarting Gitea * Change 500 'Internal Server Error' to 400 'Bad Request' * Change sql query to xorm call * Remove unneeded type from LFS module * Change internal imports to code.gitea.io/gitea/ * Add Gitea authors copyright * Change basic auth realm to "gitea-lfs" * Add unique indexes to LFS model * Use xorm count function in LFS check on repository delete * Return io.ReadCloser from content store and close after usage * Add LFS info to runWeb() * Export LFS content store base path * LFS file download from UI * Work around git-lfs client issue with unauthenticated requests Returning a dummy Authorization header for unauthenticated requests lets git-lfs client skip asking for auth credentials See: https://github.com/github/git-lfs/issues/1088 * Fix unauthenticated UI downloads from public repositories * Authentication check order, Finish LFS file view logic * Ignore LFS hooks if installed for current OS user Fixes Gitea UI actions for repositories tracking LFS files. Checks for minimum needed git version by parsing the semantic version string. * Hide LFS metafile diff from commit view, marking as binary * Show LFS notice if file in commit view is tracked * Add notbefore/nbf JWT claim * Correct lint suggestions - comments for structs and functions - Add comments to LFS model - Function comment for GetRandomBytesAsBase64 - LFS server function comments and lint variable suggestion * Move secret generation code out of conditional Ensures no LFS code may run with an empty secret * Do not hand out JWT tokens if LFS server support is disabled
8 years ago
Git LFS support v2 (#122) * Import github.com/git-lfs/lfs-test-server as lfs module base Imported commit is 3968aac269a77b73924649b9412ae03f7ccd3198 Removed: Dockerfile CONTRIBUTING.md mgmt* script/ vendor/ kvlogger.go .dockerignore .gitignore README.md * Remove config, add JWT support from github.com/mgit-at/lfs-test-server Imported commit f0cdcc5a01599c5a955dc1bbf683bb4acecdba83 * Add LFS settings * Add LFS meta object model * Add LFS routes and initialization * Import github.com/dgrijalva/jwt-go into vendor/ * Adapt LFS module: handlers, routing, meta store * Move LFS routes to /user/repo/info/lfs/* * Add request header checks to LFS BatchHandler / PostHandler * Implement LFS basic authentication * Rework JWT secret generation / load * Implement LFS SSH token authentication with JWT Specification: https://github.com/github/git-lfs/tree/master/docs/api * Integrate LFS settings into install process * Remove LFS objects when repository is deleted Only removes objects from content store when deleted repo is the only referencing repository * Make LFS module stateless Fixes bug where LFS would not work after installation without restarting Gitea * Change 500 'Internal Server Error' to 400 'Bad Request' * Change sql query to xorm call * Remove unneeded type from LFS module * Change internal imports to code.gitea.io/gitea/ * Add Gitea authors copyright * Change basic auth realm to "gitea-lfs" * Add unique indexes to LFS model * Use xorm count function in LFS check on repository delete * Return io.ReadCloser from content store and close after usage * Add LFS info to runWeb() * Export LFS content store base path * LFS file download from UI * Work around git-lfs client issue with unauthenticated requests Returning a dummy Authorization header for unauthenticated requests lets git-lfs client skip asking for auth credentials See: https://github.com/github/git-lfs/issues/1088 * Fix unauthenticated UI downloads from public repositories * Authentication check order, Finish LFS file view logic * Ignore LFS hooks if installed for current OS user Fixes Gitea UI actions for repositories tracking LFS files. Checks for minimum needed git version by parsing the semantic version string. * Hide LFS metafile diff from commit view, marking as binary * Show LFS notice if file in commit view is tracked * Add notbefore/nbf JWT claim * Correct lint suggestions - comments for structs and functions - Add comments to LFS model - Function comment for GetRandomBytesAsBase64 - LFS server function comments and lint variable suggestion * Move secret generation code out of conditional Ensures no LFS code may run with an empty secret * Do not hand out JWT tokens if LFS server support is disabled
8 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
5 years ago
Repository avatars (#6986) * Repository avatars - first variant of code from old work for gogs - add migration 87 - add new option in app.ini - add en-US locale string - add new class in repository.less * Add changed index.css, remove unused template name * Update en-us doc about configuration options * Add comments to new functions, add new option to docker app.ini * Add comment for lint * Remove variable, not needed * Fix formatting * Update swagger api template * Check if avatar exists * Fix avatar link/path checks * Typo * TEXT column can't have a default value * Fixes: - remove old avatar file on upload - use ID in name of avatar file - users may upload same files - add simple tests * Fix fmt check * Generate PNG instead of "static" GIF * More informative comment * Fix error message * Update avatar upload checks: - add file size check - add new option - update config docs - add new string to en-us locale * Fixes: - use FileHEader field for check file size - add new test - upload big image * Fix formatting * Update comments * Update log message * Removed wrong style - not needed * Use Sync2 to migrate * Update repos list view - bigger avatar - fix html blocks alignment * A little adjust avatar size * Use small icons for explore/repo list * Use new cool avatar preparation func by @lafriks * Missing changes for new function * Remove unused import, move imports * Missed new option definition in app.ini Add file size check in user/profile avatar upload * Use smaller field length for Avatar * Use session to update repo DB data, update DeleteAvatar - use session too * Fix err variable definition * As suggested @lafriks - return as soon as possible, code readability
5 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
9 years ago
10 years ago
9 years ago
10 years ago
10 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
5 years ago
9 years ago
10 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
5 years ago
10 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
5 years ago
10 years ago
10 years ago
10 years ago
10 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
5 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
5 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
5 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
5 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
5 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
5 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
5 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
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
10 years ago
Git LFS support v2 (#122) * Import github.com/git-lfs/lfs-test-server as lfs module base Imported commit is 3968aac269a77b73924649b9412ae03f7ccd3198 Removed: Dockerfile CONTRIBUTING.md mgmt* script/ vendor/ kvlogger.go .dockerignore .gitignore README.md * Remove config, add JWT support from github.com/mgit-at/lfs-test-server Imported commit f0cdcc5a01599c5a955dc1bbf683bb4acecdba83 * Add LFS settings * Add LFS meta object model * Add LFS routes and initialization * Import github.com/dgrijalva/jwt-go into vendor/ * Adapt LFS module: handlers, routing, meta store * Move LFS routes to /user/repo/info/lfs/* * Add request header checks to LFS BatchHandler / PostHandler * Implement LFS basic authentication * Rework JWT secret generation / load * Implement LFS SSH token authentication with JWT Specification: https://github.com/github/git-lfs/tree/master/docs/api * Integrate LFS settings into install process * Remove LFS objects when repository is deleted Only removes objects from content store when deleted repo is the only referencing repository * Make LFS module stateless Fixes bug where LFS would not work after installation without restarting Gitea * Change 500 'Internal Server Error' to 400 'Bad Request' * Change sql query to xorm call * Remove unneeded type from LFS module * Change internal imports to code.gitea.io/gitea/ * Add Gitea authors copyright * Change basic auth realm to "gitea-lfs" * Add unique indexes to LFS model * Use xorm count function in LFS check on repository delete * Return io.ReadCloser from content store and close after usage * Add LFS info to runWeb() * Export LFS content store base path * LFS file download from UI * Work around git-lfs client issue with unauthenticated requests Returning a dummy Authorization header for unauthenticated requests lets git-lfs client skip asking for auth credentials See: https://github.com/github/git-lfs/issues/1088 * Fix unauthenticated UI downloads from public repositories * Authentication check order, Finish LFS file view logic * Ignore LFS hooks if installed for current OS user Fixes Gitea UI actions for repositories tracking LFS files. Checks for minimum needed git version by parsing the semantic version string. * Hide LFS metafile diff from commit view, marking as binary * Show LFS notice if file in commit view is tracked * Add notbefore/nbf JWT claim * Correct lint suggestions - comments for structs and functions - Add comments to LFS model - Function comment for GetRandomBytesAsBase64 - LFS server function comments and lint variable suggestion * Move secret generation code out of conditional Ensures no LFS code may run with an empty secret * Do not hand out JWT tokens if LFS server support is disabled
8 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
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
Git LFS support v2 (#122) * Import github.com/git-lfs/lfs-test-server as lfs module base Imported commit is 3968aac269a77b73924649b9412ae03f7ccd3198 Removed: Dockerfile CONTRIBUTING.md mgmt* script/ vendor/ kvlogger.go .dockerignore .gitignore README.md * Remove config, add JWT support from github.com/mgit-at/lfs-test-server Imported commit f0cdcc5a01599c5a955dc1bbf683bb4acecdba83 * Add LFS settings * Add LFS meta object model * Add LFS routes and initialization * Import github.com/dgrijalva/jwt-go into vendor/ * Adapt LFS module: handlers, routing, meta store * Move LFS routes to /user/repo/info/lfs/* * Add request header checks to LFS BatchHandler / PostHandler * Implement LFS basic authentication * Rework JWT secret generation / load * Implement LFS SSH token authentication with JWT Specification: https://github.com/github/git-lfs/tree/master/docs/api * Integrate LFS settings into install process * Remove LFS objects when repository is deleted Only removes objects from content store when deleted repo is the only referencing repository * Make LFS module stateless Fixes bug where LFS would not work after installation without restarting Gitea * Change 500 'Internal Server Error' to 400 'Bad Request' * Change sql query to xorm call * Remove unneeded type from LFS module * Change internal imports to code.gitea.io/gitea/ * Add Gitea authors copyright * Change basic auth realm to "gitea-lfs" * Add unique indexes to LFS model * Use xorm count function in LFS check on repository delete * Return io.ReadCloser from content store and close after usage * Add LFS info to runWeb() * Export LFS content store base path * LFS file download from UI * Work around git-lfs client issue with unauthenticated requests Returning a dummy Authorization header for unauthenticated requests lets git-lfs client skip asking for auth credentials See: https://github.com/github/git-lfs/issues/1088 * Fix unauthenticated UI downloads from public repositories * Authentication check order, Finish LFS file view logic * Ignore LFS hooks if installed for current OS user Fixes Gitea UI actions for repositories tracking LFS files. Checks for minimum needed git version by parsing the semantic version string. * Hide LFS metafile diff from commit view, marking as binary * Show LFS notice if file in commit view is tracked * Add notbefore/nbf JWT claim * Correct lint suggestions - comments for structs and functions - Add comments to LFS model - Function comment for GetRandomBytesAsBase64 - LFS server function comments and lint variable suggestion * Move secret generation code out of conditional Ensures no LFS code may run with an empty secret * Do not hand out JWT tokens if LFS server support is disabled
8 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
Git LFS support v2 (#122) * Import github.com/git-lfs/lfs-test-server as lfs module base Imported commit is 3968aac269a77b73924649b9412ae03f7ccd3198 Removed: Dockerfile CONTRIBUTING.md mgmt* script/ vendor/ kvlogger.go .dockerignore .gitignore README.md * Remove config, add JWT support from github.com/mgit-at/lfs-test-server Imported commit f0cdcc5a01599c5a955dc1bbf683bb4acecdba83 * Add LFS settings * Add LFS meta object model * Add LFS routes and initialization * Import github.com/dgrijalva/jwt-go into vendor/ * Adapt LFS module: handlers, routing, meta store * Move LFS routes to /user/repo/info/lfs/* * Add request header checks to LFS BatchHandler / PostHandler * Implement LFS basic authentication * Rework JWT secret generation / load * Implement LFS SSH token authentication with JWT Specification: https://github.com/github/git-lfs/tree/master/docs/api * Integrate LFS settings into install process * Remove LFS objects when repository is deleted Only removes objects from content store when deleted repo is the only referencing repository * Make LFS module stateless Fixes bug where LFS would not work after installation without restarting Gitea * Change 500 'Internal Server Error' to 400 'Bad Request' * Change sql query to xorm call * Remove unneeded type from LFS module * Change internal imports to code.gitea.io/gitea/ * Add Gitea authors copyright * Change basic auth realm to "gitea-lfs" * Add unique indexes to LFS model * Use xorm count function in LFS check on repository delete * Return io.ReadCloser from content store and close after usage * Add LFS info to runWeb() * Export LFS content store base path * LFS file download from UI * Work around git-lfs client issue with unauthenticated requests Returning a dummy Authorization header for unauthenticated requests lets git-lfs client skip asking for auth credentials See: https://github.com/github/git-lfs/issues/1088 * Fix unauthenticated UI downloads from public repositories * Authentication check order, Finish LFS file view logic * Ignore LFS hooks if installed for current OS user Fixes Gitea UI actions for repositories tracking LFS files. Checks for minimum needed git version by parsing the semantic version string. * Hide LFS metafile diff from commit view, marking as binary * Show LFS notice if file in commit view is tracked * Add notbefore/nbf JWT claim * Correct lint suggestions - comments for structs and functions - Add comments to LFS model - Function comment for GetRandomBytesAsBase64 - LFS server function comments and lint variable suggestion * Move secret generation code out of conditional Ensures no LFS code may run with an empty secret * Do not hand out JWT tokens if LFS server support is disabled
8 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
Git LFS support v2 (#122) * Import github.com/git-lfs/lfs-test-server as lfs module base Imported commit is 3968aac269a77b73924649b9412ae03f7ccd3198 Removed: Dockerfile CONTRIBUTING.md mgmt* script/ vendor/ kvlogger.go .dockerignore .gitignore README.md * Remove config, add JWT support from github.com/mgit-at/lfs-test-server Imported commit f0cdcc5a01599c5a955dc1bbf683bb4acecdba83 * Add LFS settings * Add LFS meta object model * Add LFS routes and initialization * Import github.com/dgrijalva/jwt-go into vendor/ * Adapt LFS module: handlers, routing, meta store * Move LFS routes to /user/repo/info/lfs/* * Add request header checks to LFS BatchHandler / PostHandler * Implement LFS basic authentication * Rework JWT secret generation / load * Implement LFS SSH token authentication with JWT Specification: https://github.com/github/git-lfs/tree/master/docs/api * Integrate LFS settings into install process * Remove LFS objects when repository is deleted Only removes objects from content store when deleted repo is the only referencing repository * Make LFS module stateless Fixes bug where LFS would not work after installation without restarting Gitea * Change 500 'Internal Server Error' to 400 'Bad Request' * Change sql query to xorm call * Remove unneeded type from LFS module * Change internal imports to code.gitea.io/gitea/ * Add Gitea authors copyright * Change basic auth realm to "gitea-lfs" * Add unique indexes to LFS model * Use xorm count function in LFS check on repository delete * Return io.ReadCloser from content store and close after usage * Add LFS info to runWeb() * Export LFS content store base path * LFS file download from UI * Work around git-lfs client issue with unauthenticated requests Returning a dummy Authorization header for unauthenticated requests lets git-lfs client skip asking for auth credentials See: https://github.com/github/git-lfs/issues/1088 * Fix unauthenticated UI downloads from public repositories * Authentication check order, Finish LFS file view logic * Ignore LFS hooks if installed for current OS user Fixes Gitea UI actions for repositories tracking LFS files. Checks for minimum needed git version by parsing the semantic version string. * Hide LFS metafile diff from commit view, marking as binary * Show LFS notice if file in commit view is tracked * Add notbefore/nbf JWT claim * Correct lint suggestions - comments for structs and functions - Add comments to LFS model - Function comment for GetRandomBytesAsBase64 - LFS server function comments and lint variable suggestion * Move secret generation code out of conditional Ensures no LFS code may run with an empty secret * Do not hand out JWT tokens if LFS server support is disabled
8 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
Git LFS support v2 (#122) * Import github.com/git-lfs/lfs-test-server as lfs module base Imported commit is 3968aac269a77b73924649b9412ae03f7ccd3198 Removed: Dockerfile CONTRIBUTING.md mgmt* script/ vendor/ kvlogger.go .dockerignore .gitignore README.md * Remove config, add JWT support from github.com/mgit-at/lfs-test-server Imported commit f0cdcc5a01599c5a955dc1bbf683bb4acecdba83 * Add LFS settings * Add LFS meta object model * Add LFS routes and initialization * Import github.com/dgrijalva/jwt-go into vendor/ * Adapt LFS module: handlers, routing, meta store * Move LFS routes to /user/repo/info/lfs/* * Add request header checks to LFS BatchHandler / PostHandler * Implement LFS basic authentication * Rework JWT secret generation / load * Implement LFS SSH token authentication with JWT Specification: https://github.com/github/git-lfs/tree/master/docs/api * Integrate LFS settings into install process * Remove LFS objects when repository is deleted Only removes objects from content store when deleted repo is the only referencing repository * Make LFS module stateless Fixes bug where LFS would not work after installation without restarting Gitea * Change 500 'Internal Server Error' to 400 'Bad Request' * Change sql query to xorm call * Remove unneeded type from LFS module * Change internal imports to code.gitea.io/gitea/ * Add Gitea authors copyright * Change basic auth realm to "gitea-lfs" * Add unique indexes to LFS model * Use xorm count function in LFS check on repository delete * Return io.ReadCloser from content store and close after usage * Add LFS info to runWeb() * Export LFS content store base path * LFS file download from UI * Work around git-lfs client issue with unauthenticated requests Returning a dummy Authorization header for unauthenticated requests lets git-lfs client skip asking for auth credentials See: https://github.com/github/git-lfs/issues/1088 * Fix unauthenticated UI downloads from public repositories * Authentication check order, Finish LFS file view logic * Ignore LFS hooks if installed for current OS user Fixes Gitea UI actions for repositories tracking LFS files. Checks for minimum needed git version by parsing the semantic version string. * Hide LFS metafile diff from commit view, marking as binary * Show LFS notice if file in commit view is tracked * Add notbefore/nbf JWT claim * Correct lint suggestions - comments for structs and functions - Add comments to LFS model - Function comment for GetRandomBytesAsBase64 - LFS server function comments and lint variable suggestion * Move secret generation code out of conditional Ensures no LFS code may run with an empty secret * Do not hand out JWT tokens if LFS server support is disabled
8 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
9 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
8 years ago
Repository avatars (#6986) * Repository avatars - first variant of code from old work for gogs - add migration 87 - add new option in app.ini - add en-US locale string - add new class in repository.less * Add changed index.css, remove unused template name * Update en-us doc about configuration options * Add comments to new functions, add new option to docker app.ini * Add comment for lint * Remove variable, not needed * Fix formatting * Update swagger api template * Check if avatar exists * Fix avatar link/path checks * Typo * TEXT column can't have a default value * Fixes: - remove old avatar file on upload - use ID in name of avatar file - users may upload same files - add simple tests * Fix fmt check * Generate PNG instead of "static" GIF * More informative comment * Fix error message * Update avatar upload checks: - add file size check - add new option - update config docs - add new string to en-us locale * Fixes: - use FileHEader field for check file size - add new test - upload big image * Fix formatting * Update comments * Update log message * Removed wrong style - not needed * Use Sync2 to migrate * Update repos list view - bigger avatar - fix html blocks alignment * A little adjust avatar size * Use small icons for explore/repo list * Use new cool avatar preparation func by @lafriks * Missing changes for new function * Remove unused import, move imports * Missed new option definition in app.ini Add file size check in user/profile avatar upload * Use smaller field length for Avatar * Use session to update repo DB data, update DeleteAvatar - use session too * Fix err variable definition * As suggested @lafriks - return as soon as possible, code readability
5 years ago
Repository avatars (#6986) * Repository avatars - first variant of code from old work for gogs - add migration 87 - add new option in app.ini - add en-US locale string - add new class in repository.less * Add changed index.css, remove unused template name * Update en-us doc about configuration options * Add comments to new functions, add new option to docker app.ini * Add comment for lint * Remove variable, not needed * Fix formatting * Update swagger api template * Check if avatar exists * Fix avatar link/path checks * Typo * TEXT column can't have a default value * Fixes: - remove old avatar file on upload - use ID in name of avatar file - users may upload same files - add simple tests * Fix fmt check * Generate PNG instead of "static" GIF * More informative comment * Fix error message * Update avatar upload checks: - add file size check - add new option - update config docs - add new string to en-us locale * Fixes: - use FileHEader field for check file size - add new test - upload big image * Fix formatting * Update comments * Update log message * Removed wrong style - not needed * Use Sync2 to migrate * Update repos list view - bigger avatar - fix html blocks alignment * A little adjust avatar size * Use small icons for explore/repo list * Use new cool avatar preparation func by @lafriks * Missing changes for new function * Remove unused import, move imports * Missed new option definition in app.ini Add file size check in user/profile avatar upload * Use smaller field length for Avatar * Use session to update repo DB data, update DeleteAvatar - use session too * Fix err variable definition * As suggested @lafriks - return as soon as possible, code readability
5 years ago
Repository avatars (#6986) * Repository avatars - first variant of code from old work for gogs - add migration 87 - add new option in app.ini - add en-US locale string - add new class in repository.less * Add changed index.css, remove unused template name * Update en-us doc about configuration options * Add comments to new functions, add new option to docker app.ini * Add comment for lint * Remove variable, not needed * Fix formatting * Update swagger api template * Check if avatar exists * Fix avatar link/path checks * Typo * TEXT column can't have a default value * Fixes: - remove old avatar file on upload - use ID in name of avatar file - users may upload same files - add simple tests * Fix fmt check * Generate PNG instead of "static" GIF * More informative comment * Fix error message * Update avatar upload checks: - add file size check - add new option - update config docs - add new string to en-us locale * Fixes: - use FileHEader field for check file size - add new test - upload big image * Fix formatting * Update comments * Update log message * Removed wrong style - not needed * Use Sync2 to migrate * Update repos list view - bigger avatar - fix html blocks alignment * A little adjust avatar size * Use small icons for explore/repo list * Use new cool avatar preparation func by @lafriks * Missing changes for new function * Remove unused import, move imports * Missed new option definition in app.ini Add file size check in user/profile avatar upload * Use smaller field length for Avatar * Use session to update repo DB data, update DeleteAvatar - use session too * Fix err variable definition * As suggested @lafriks - return as soon as possible, code readability
5 years ago
Repository avatars (#6986) * Repository avatars - first variant of code from old work for gogs - add migration 87 - add new option in app.ini - add en-US locale string - add new class in repository.less * Add changed index.css, remove unused template name * Update en-us doc about configuration options * Add comments to new functions, add new option to docker app.ini * Add comment for lint * Remove variable, not needed * Fix formatting * Update swagger api template * Check if avatar exists * Fix avatar link/path checks * Typo * TEXT column can't have a default value * Fixes: - remove old avatar file on upload - use ID in name of avatar file - users may upload same files - add simple tests * Fix fmt check * Generate PNG instead of "static" GIF * More informative comment * Fix error message * Update avatar upload checks: - add file size check - add new option - update config docs - add new string to en-us locale * Fixes: - use FileHEader field for check file size - add new test - upload big image * Fix formatting * Update comments * Update log message * Removed wrong style - not needed * Use Sync2 to migrate * Update repos list view - bigger avatar - fix html blocks alignment * A little adjust avatar size * Use small icons for explore/repo list * Use new cool avatar preparation func by @lafriks * Missing changes for new function * Remove unused import, move imports * Missed new option definition in app.ini Add file size check in user/profile avatar upload * Use smaller field length for Avatar * Use session to update repo DB data, update DeleteAvatar - use session too * Fix err variable definition * As suggested @lafriks - return as soon as possible, code readability
5 years ago
Repository avatars (#6986) * Repository avatars - first variant of code from old work for gogs - add migration 87 - add new option in app.ini - add en-US locale string - add new class in repository.less * Add changed index.css, remove unused template name * Update en-us doc about configuration options * Add comments to new functions, add new option to docker app.ini * Add comment for lint * Remove variable, not needed * Fix formatting * Update swagger api template * Check if avatar exists * Fix avatar link/path checks * Typo * TEXT column can't have a default value * Fixes: - remove old avatar file on upload - use ID in name of avatar file - users may upload same files - add simple tests * Fix fmt check * Generate PNG instead of "static" GIF * More informative comment * Fix error message * Update avatar upload checks: - add file size check - add new option - update config docs - add new string to en-us locale * Fixes: - use FileHEader field for check file size - add new test - upload big image * Fix formatting * Update comments * Update log message * Removed wrong style - not needed * Use Sync2 to migrate * Update repos list view - bigger avatar - fix html blocks alignment * A little adjust avatar size * Use small icons for explore/repo list * Use new cool avatar preparation func by @lafriks * Missing changes for new function * Remove unused import, move imports * Missed new option definition in app.ini Add file size check in user/profile avatar upload * Use smaller field length for Avatar * Use session to update repo DB data, update DeleteAvatar - use session too * Fix err variable definition * As suggested @lafriks - return as soon as possible, code readability
5 years ago
Repository avatars (#6986) * Repository avatars - first variant of code from old work for gogs - add migration 87 - add new option in app.ini - add en-US locale string - add new class in repository.less * Add changed index.css, remove unused template name * Update en-us doc about configuration options * Add comments to new functions, add new option to docker app.ini * Add comment for lint * Remove variable, not needed * Fix formatting * Update swagger api template * Check if avatar exists * Fix avatar link/path checks * Typo * TEXT column can't have a default value * Fixes: - remove old avatar file on upload - use ID in name of avatar file - users may upload same files - add simple tests * Fix fmt check * Generate PNG instead of "static" GIF * More informative comment * Fix error message * Update avatar upload checks: - add file size check - add new option - update config docs - add new string to en-us locale * Fixes: - use FileHEader field for check file size - add new test - upload big image * Fix formatting * Update comments * Update log message * Removed wrong style - not needed * Use Sync2 to migrate * Update repos list view - bigger avatar - fix html blocks alignment * A little adjust avatar size * Use small icons for explore/repo list * Use new cool avatar preparation func by @lafriks * Missing changes for new function * Remove unused import, move imports * Missed new option definition in app.ini Add file size check in user/profile avatar upload * Use smaller field length for Avatar * Use session to update repo DB data, update DeleteAvatar - use session too * Fix err variable definition * As suggested @lafriks - return as soon as possible, code readability
5 years ago
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Copyright 2017 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 models
  6. import (
  7. "bytes"
  8. "crypto/md5"
  9. "errors"
  10. "fmt"
  11. "html/template"
  12. // Needed for jpeg support
  13. _ "image/jpeg"
  14. "image/png"
  15. "io/ioutil"
  16. "net/url"
  17. "os"
  18. "path"
  19. "path/filepath"
  20. "sort"
  21. "strconv"
  22. "strings"
  23. "time"
  24. "code.gitea.io/gitea/modules/avatar"
  25. "code.gitea.io/gitea/modules/git"
  26. "code.gitea.io/gitea/modules/log"
  27. "code.gitea.io/gitea/modules/markup"
  28. "code.gitea.io/gitea/modules/options"
  29. "code.gitea.io/gitea/modules/process"
  30. "code.gitea.io/gitea/modules/setting"
  31. "code.gitea.io/gitea/modules/structs"
  32. api "code.gitea.io/gitea/modules/structs"
  33. "code.gitea.io/gitea/modules/sync"
  34. "code.gitea.io/gitea/modules/timeutil"
  35. "code.gitea.io/gitea/modules/util"
  36. "github.com/mcuadros/go-version"
  37. "github.com/unknwon/com"
  38. ini "gopkg.in/ini.v1"
  39. "xorm.io/builder"
  40. "xorm.io/xorm"
  41. )
  42. var repoWorkingPool = sync.NewExclusivePool()
  43. var (
  44. // ErrMirrorNotExist mirror does not exist error
  45. ErrMirrorNotExist = errors.New("Mirror does not exist")
  46. // ErrNameEmpty name is empty error
  47. ErrNameEmpty = errors.New("Name is empty")
  48. )
  49. var (
  50. // Gitignores contains the gitiginore files
  51. Gitignores []string
  52. // Licenses contains the license files
  53. Licenses []string
  54. // Readmes contains the readme files
  55. Readmes []string
  56. // LabelTemplates contains the label template files
  57. LabelTemplates []string
  58. // ItemsPerPage maximum items per page in forks, watchers and stars of a repo
  59. ItemsPerPage = 40
  60. )
  61. // loadRepoConfig loads the repository config
  62. func loadRepoConfig() {
  63. // Load .gitignore and license files and readme templates.
  64. types := []string{"gitignore", "license", "readme", "label"}
  65. typeFiles := make([][]string, 4)
  66. for i, t := range types {
  67. files, err := options.Dir(t)
  68. if err != nil {
  69. log.Fatal("Failed to get %s files: %v", t, err)
  70. }
  71. customPath := path.Join(setting.CustomPath, "options", t)
  72. if com.IsDir(customPath) {
  73. customFiles, err := com.StatDir(customPath)
  74. if err != nil {
  75. log.Fatal("Failed to get custom %s files: %v", t, err)
  76. }
  77. for _, f := range customFiles {
  78. if !com.IsSliceContainsStr(files, f) {
  79. files = append(files, f)
  80. }
  81. }
  82. }
  83. typeFiles[i] = files
  84. }
  85. Gitignores = typeFiles[0]
  86. Licenses = typeFiles[1]
  87. Readmes = typeFiles[2]
  88. LabelTemplates = typeFiles[3]
  89. sort.Strings(Gitignores)
  90. sort.Strings(Licenses)
  91. sort.Strings(Readmes)
  92. sort.Strings(LabelTemplates)
  93. // Filter out invalid names and promote preferred licenses.
  94. sortedLicenses := make([]string, 0, len(Licenses))
  95. for _, name := range setting.Repository.PreferredLicenses {
  96. if com.IsSliceContainsStr(Licenses, name) {
  97. sortedLicenses = append(sortedLicenses, name)
  98. }
  99. }
  100. for _, name := range Licenses {
  101. if !com.IsSliceContainsStr(setting.Repository.PreferredLicenses, name) {
  102. sortedLicenses = append(sortedLicenses, name)
  103. }
  104. }
  105. Licenses = sortedLicenses
  106. }
  107. // NewRepoContext creates a new repository context
  108. func NewRepoContext() {
  109. loadRepoConfig()
  110. RemoveAllWithNotice("Clean up repository temporary data", filepath.Join(setting.AppDataPath, "tmp"))
  111. }
  112. // RepositoryStatus defines the status of repository
  113. type RepositoryStatus int
  114. // all kinds of RepositoryStatus
  115. const (
  116. RepositoryReady RepositoryStatus = iota // a normal repository
  117. RepositoryBeingMigrated // repository is migrating
  118. )
  119. // Repository represents a git repository.
  120. type Repository struct {
  121. ID int64 `xorm:"pk autoincr"`
  122. OwnerID int64 `xorm:"UNIQUE(s) index"`
  123. OwnerName string `xorm:"-"`
  124. Owner *User `xorm:"-"`
  125. LowerName string `xorm:"UNIQUE(s) INDEX NOT NULL"`
  126. Name string `xorm:"INDEX NOT NULL"`
  127. Description string `xorm:"TEXT"`
  128. Website string `xorm:"VARCHAR(2048)"`
  129. OriginalServiceType structs.GitServiceType `xorm:"index"`
  130. OriginalURL string `xorm:"VARCHAR(2048)"`
  131. DefaultBranch string
  132. NumWatches int
  133. NumStars int
  134. NumForks int
  135. NumIssues int
  136. NumClosedIssues int
  137. NumOpenIssues int `xorm:"-"`
  138. NumPulls int
  139. NumClosedPulls int
  140. NumOpenPulls int `xorm:"-"`
  141. NumMilestones int `xorm:"NOT NULL DEFAULT 0"`
  142. NumClosedMilestones int `xorm:"NOT NULL DEFAULT 0"`
  143. NumOpenMilestones int `xorm:"-"`
  144. NumReleases int `xorm:"-"`
  145. IsPrivate bool `xorm:"INDEX"`
  146. IsEmpty bool `xorm:"INDEX"`
  147. IsArchived bool `xorm:"INDEX"`
  148. IsMirror bool `xorm:"INDEX"`
  149. *Mirror `xorm:"-"`
  150. Status RepositoryStatus `xorm:"NOT NULL DEFAULT 0"`
  151. ExternalMetas map[string]string `xorm:"-"`
  152. Units []*RepoUnit `xorm:"-"`
  153. IsFork bool `xorm:"INDEX NOT NULL DEFAULT false"`
  154. ForkID int64 `xorm:"INDEX"`
  155. BaseRepo *Repository `xorm:"-"`
  156. IsTemplate bool `xorm:"INDEX NOT NULL DEFAULT false"`
  157. TemplateID int64 `xorm:"INDEX"`
  158. TemplateRepo *Repository `xorm:"-"`
  159. Size int64 `xorm:"NOT NULL DEFAULT 0"`
  160. IndexerStatus *RepoIndexerStatus `xorm:"-"`
  161. IsFsckEnabled bool `xorm:"NOT NULL DEFAULT true"`
  162. CloseIssuesViaCommitInAnyBranch bool `xorm:"NOT NULL DEFAULT false"`
  163. Topics []string `xorm:"TEXT JSON"`
  164. // Avatar: ID(10-20)-md5(32) - must fit into 64 symbols
  165. Avatar string `xorm:"VARCHAR(64)"`
  166. CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
  167. UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
  168. }
  169. // ColorFormat returns a colored string to represent this repo
  170. func (repo *Repository) ColorFormat(s fmt.State) {
  171. var ownerName interface{}
  172. if repo.OwnerName != "" {
  173. ownerName = repo.OwnerName
  174. } else if repo.Owner != nil {
  175. ownerName = repo.Owner.Name
  176. } else {
  177. ownerName = log.NewColoredIDValue(strconv.FormatInt(repo.OwnerID, 10))
  178. }
  179. log.ColorFprintf(s, "%d:%s/%s",
  180. log.NewColoredIDValue(repo.ID),
  181. ownerName,
  182. repo.Name)
  183. }
  184. // IsBeingMigrated indicates that repository is being migtated
  185. func (repo *Repository) IsBeingMigrated() bool {
  186. return repo.Status == RepositoryBeingMigrated
  187. }
  188. // IsBeingCreated indicates that repository is being migrated or forked
  189. func (repo *Repository) IsBeingCreated() bool {
  190. return repo.IsBeingMigrated()
  191. }
  192. // AfterLoad is invoked from XORM after setting the values of all fields of this object.
  193. func (repo *Repository) AfterLoad() {
  194. // FIXME: use models migration to solve all at once.
  195. if len(repo.DefaultBranch) == 0 {
  196. repo.DefaultBranch = "master"
  197. }
  198. repo.NumOpenIssues = repo.NumIssues - repo.NumClosedIssues
  199. repo.NumOpenPulls = repo.NumPulls - repo.NumClosedPulls
  200. repo.NumOpenMilestones = repo.NumMilestones - repo.NumClosedMilestones
  201. }
  202. // MustOwner always returns a valid *User object to avoid
  203. // conceptually impossible error handling.
  204. // It creates a fake object that contains error details
  205. // when error occurs.
  206. func (repo *Repository) MustOwner() *User {
  207. return repo.mustOwner(x)
  208. }
  209. // MustOwnerName always returns valid owner name to avoid
  210. // conceptually impossible error handling.
  211. // It returns "error" and logs error details when error
  212. // occurs.
  213. func (repo *Repository) MustOwnerName() string {
  214. return repo.mustOwnerName(x)
  215. }
  216. // FullName returns the repository full name
  217. func (repo *Repository) FullName() string {
  218. return repo.MustOwnerName() + "/" + repo.Name
  219. }
  220. // HTMLURL returns the repository HTML URL
  221. func (repo *Repository) HTMLURL() string {
  222. return setting.AppURL + repo.FullName()
  223. }
  224. // APIURL returns the repository API URL
  225. func (repo *Repository) APIURL() string {
  226. return setting.AppURL + path.Join("api/v1/repos", repo.FullName())
  227. }
  228. // APIFormat converts a Repository to api.Repository
  229. func (repo *Repository) APIFormat(mode AccessMode) *api.Repository {
  230. return repo.innerAPIFormat(x, mode, false)
  231. }
  232. // GetCommitsCountCacheKey returns cache key used for commits count caching.
  233. func (repo *Repository) GetCommitsCountCacheKey(contextName string, isRef bool) string {
  234. var prefix string
  235. if isRef {
  236. prefix = "ref"
  237. } else {
  238. prefix = "commit"
  239. }
  240. return fmt.Sprintf("commits-count-%d-%s-%s", repo.ID, prefix, contextName)
  241. }
  242. func (repo *Repository) innerAPIFormat(e Engine, mode AccessMode, isParent bool) *api.Repository {
  243. var parent *api.Repository
  244. cloneLink := repo.cloneLink(e, false)
  245. permission := &api.Permission{
  246. Admin: mode >= AccessModeAdmin,
  247. Push: mode >= AccessModeWrite,
  248. Pull: mode >= AccessModeRead,
  249. }
  250. if !isParent {
  251. err := repo.getBaseRepo(e)
  252. if err != nil {
  253. log.Error("APIFormat: %v", err)
  254. }
  255. if repo.BaseRepo != nil {
  256. parent = repo.BaseRepo.innerAPIFormat(e, mode, true)
  257. }
  258. }
  259. hasIssues := false
  260. var externalTracker *api.ExternalTracker
  261. var internalTracker *api.InternalTracker
  262. if unit, err := repo.getUnit(e, UnitTypeIssues); err == nil {
  263. config := unit.IssuesConfig()
  264. hasIssues = true
  265. internalTracker = &api.InternalTracker{
  266. EnableTimeTracker: config.EnableTimetracker,
  267. AllowOnlyContributorsToTrackTime: config.AllowOnlyContributorsToTrackTime,
  268. EnableIssueDependencies: config.EnableDependencies,
  269. }
  270. } else if unit, err := repo.getUnit(e, UnitTypeExternalTracker); err == nil {
  271. config := unit.ExternalTrackerConfig()
  272. hasIssues = true
  273. externalTracker = &api.ExternalTracker{
  274. ExternalTrackerURL: config.ExternalTrackerURL,
  275. ExternalTrackerFormat: config.ExternalTrackerFormat,
  276. ExternalTrackerStyle: config.ExternalTrackerStyle,
  277. }
  278. }
  279. hasWiki := false
  280. var externalWiki *api.ExternalWiki
  281. if _, err := repo.getUnit(e, UnitTypeWiki); err == nil {
  282. hasWiki = true
  283. } else if unit, err := repo.getUnit(e, UnitTypeExternalWiki); err == nil {
  284. hasWiki = true
  285. config := unit.ExternalWikiConfig()
  286. externalWiki = &api.ExternalWiki{
  287. ExternalWikiURL: config.ExternalWikiURL,
  288. }
  289. }
  290. hasPullRequests := false
  291. ignoreWhitespaceConflicts := false
  292. allowMerge := false
  293. allowRebase := false
  294. allowRebaseMerge := false
  295. allowSquash := false
  296. if unit, err := repo.getUnit(e, UnitTypePullRequests); err == nil {
  297. config := unit.PullRequestsConfig()
  298. hasPullRequests = true
  299. ignoreWhitespaceConflicts = config.IgnoreWhitespaceConflicts
  300. allowMerge = config.AllowMerge
  301. allowRebase = config.AllowRebase
  302. allowRebaseMerge = config.AllowRebaseMerge
  303. allowSquash = config.AllowSquash
  304. }
  305. return &api.Repository{
  306. ID: repo.ID,
  307. Owner: repo.Owner.APIFormat(),
  308. Name: repo.Name,
  309. FullName: repo.FullName(),
  310. Description: repo.Description,
  311. Private: repo.IsPrivate,
  312. Template: repo.IsTemplate,
  313. Empty: repo.IsEmpty,
  314. Archived: repo.IsArchived,
  315. Size: int(repo.Size / 1024),
  316. Fork: repo.IsFork,
  317. Parent: parent,
  318. Mirror: repo.IsMirror,
  319. HTMLURL: repo.HTMLURL(),
  320. SSHURL: cloneLink.SSH,
  321. CloneURL: cloneLink.HTTPS,
  322. Website: repo.Website,
  323. Stars: repo.NumStars,
  324. Forks: repo.NumForks,
  325. Watchers: repo.NumWatches,
  326. OpenIssues: repo.NumOpenIssues,
  327. DefaultBranch: repo.DefaultBranch,
  328. Created: repo.CreatedUnix.AsTime(),
  329. Updated: repo.UpdatedUnix.AsTime(),
  330. Permissions: permission,
  331. HasIssues: hasIssues,
  332. ExternalTracker: externalTracker,
  333. InternalTracker: internalTracker,
  334. HasWiki: hasWiki,
  335. ExternalWiki: externalWiki,
  336. HasPullRequests: hasPullRequests,
  337. IgnoreWhitespaceConflicts: ignoreWhitespaceConflicts,
  338. AllowMerge: allowMerge,
  339. AllowRebase: allowRebase,
  340. AllowRebaseMerge: allowRebaseMerge,
  341. AllowSquash: allowSquash,
  342. AvatarURL: repo.avatarLink(e),
  343. }
  344. }
  345. func (repo *Repository) getUnits(e Engine) (err error) {
  346. if repo.Units != nil {
  347. return nil
  348. }
  349. repo.Units, err = getUnitsByRepoID(e, repo.ID)
  350. return err
  351. }
  352. // CheckUnitUser check whether user could visit the unit of this repository
  353. func (repo *Repository) CheckUnitUser(userID int64, isAdmin bool, unitType UnitType) bool {
  354. return repo.checkUnitUser(x, userID, isAdmin, unitType)
  355. }
  356. func (repo *Repository) checkUnitUser(e Engine, userID int64, isAdmin bool, unitType UnitType) bool {
  357. if isAdmin {
  358. return true
  359. }
  360. user, err := getUserByID(e, userID)
  361. if err != nil {
  362. return false
  363. }
  364. perm, err := getUserRepoPermission(e, repo, user)
  365. if err != nil {
  366. return false
  367. }
  368. return perm.CanRead(unitType)
  369. }
  370. // UnitEnabled if this repository has the given unit enabled
  371. func (repo *Repository) UnitEnabled(tp UnitType) bool {
  372. if err := repo.getUnits(x); err != nil {
  373. log.Warn("Error loading repository (ID: %d) units: %s", repo.ID, err.Error())
  374. }
  375. for _, unit := range repo.Units {
  376. if unit.Type == tp {
  377. return true
  378. }
  379. }
  380. return false
  381. }
  382. // ErrUnitTypeNotExist represents a "UnitTypeNotExist" kind of error.
  383. type ErrUnitTypeNotExist struct {
  384. UT UnitType
  385. }
  386. // IsErrUnitTypeNotExist checks if an error is a ErrUnitNotExist.
  387. func IsErrUnitTypeNotExist(err error) bool {
  388. _, ok := err.(ErrUnitTypeNotExist)
  389. return ok
  390. }
  391. func (err ErrUnitTypeNotExist) Error() string {
  392. return fmt.Sprintf("Unit type does not exist: %s", err.UT.String())
  393. }
  394. // MustGetUnit always returns a RepoUnit object
  395. func (repo *Repository) MustGetUnit(tp UnitType) *RepoUnit {
  396. ru, err := repo.GetUnit(tp)
  397. if err == nil {
  398. return ru
  399. }
  400. if tp == UnitTypeExternalWiki {
  401. return &RepoUnit{
  402. Type: tp,
  403. Config: new(ExternalWikiConfig),
  404. }
  405. } else if tp == UnitTypeExternalTracker {
  406. return &RepoUnit{
  407. Type: tp,
  408. Config: new(ExternalTrackerConfig),
  409. }
  410. } else if tp == UnitTypePullRequests {
  411. return &RepoUnit{
  412. Type: tp,
  413. Config: new(PullRequestsConfig),
  414. }
  415. } else if tp == UnitTypeIssues {
  416. return &RepoUnit{
  417. Type: tp,
  418. Config: new(IssuesConfig),
  419. }
  420. }
  421. return &RepoUnit{
  422. Type: tp,
  423. Config: new(UnitConfig),
  424. }
  425. }
  426. // GetUnit returns a RepoUnit object
  427. func (repo *Repository) GetUnit(tp UnitType) (*RepoUnit, error) {
  428. return repo.getUnit(x, tp)
  429. }
  430. func (repo *Repository) getUnit(e Engine, tp UnitType) (*RepoUnit, error) {
  431. if err := repo.getUnits(e); err != nil {
  432. return nil, err
  433. }
  434. for _, unit := range repo.Units {
  435. if unit.Type == tp {
  436. return unit, nil
  437. }
  438. }
  439. return nil, ErrUnitTypeNotExist{tp}
  440. }
  441. func (repo *Repository) getOwner(e Engine) (err error) {
  442. if repo.Owner != nil {
  443. return nil
  444. }
  445. repo.Owner, err = getUserByID(e, repo.OwnerID)
  446. return err
  447. }
  448. // GetOwner returns the repository owner
  449. func (repo *Repository) GetOwner() error {
  450. return repo.getOwner(x)
  451. }
  452. func (repo *Repository) mustOwner(e Engine) *User {
  453. if err := repo.getOwner(e); err != nil {
  454. return &User{
  455. Name: "error",
  456. FullName: err.Error(),
  457. }
  458. }
  459. return repo.Owner
  460. }
  461. func (repo *Repository) getOwnerName(e Engine) error {
  462. if len(repo.OwnerName) > 0 {
  463. return nil
  464. }
  465. if repo.Owner != nil {
  466. repo.OwnerName = repo.Owner.Name
  467. return nil
  468. }
  469. u := new(User)
  470. has, err := e.ID(repo.OwnerID).Cols("name").Get(u)
  471. if err != nil {
  472. return err
  473. } else if !has {
  474. return ErrUserNotExist{repo.OwnerID, "", 0}
  475. }
  476. repo.OwnerName = u.Name
  477. return nil
  478. }
  479. // GetOwnerName returns the repository owner name
  480. func (repo *Repository) GetOwnerName() error {
  481. return repo.getOwnerName(x)
  482. }
  483. func (repo *Repository) mustOwnerName(e Engine) string {
  484. if err := repo.getOwnerName(e); err != nil {
  485. log.Error("Error loading repository owner name: %v", err)
  486. return "error"
  487. }
  488. return repo.OwnerName
  489. }
  490. // ComposeMetas composes a map of metas for properly rendering issue links and external issue trackers.
  491. func (repo *Repository) ComposeMetas() map[string]string {
  492. if repo.ExternalMetas == nil {
  493. repo.ExternalMetas = map[string]string{
  494. "user": repo.MustOwner().Name,
  495. "repo": repo.Name,
  496. "repoPath": repo.RepoPath(),
  497. }
  498. unit, err := repo.GetUnit(UnitTypeExternalTracker)
  499. if err != nil {
  500. return repo.ExternalMetas
  501. }
  502. repo.ExternalMetas["format"] = unit.ExternalTrackerConfig().ExternalTrackerFormat
  503. switch unit.ExternalTrackerConfig().ExternalTrackerStyle {
  504. case markup.IssueNameStyleAlphanumeric:
  505. repo.ExternalMetas["style"] = markup.IssueNameStyleAlphanumeric
  506. default:
  507. repo.ExternalMetas["style"] = markup.IssueNameStyleNumeric
  508. }
  509. }
  510. return repo.ExternalMetas
  511. }
  512. // DeleteWiki removes the actual and local copy of repository wiki.
  513. func (repo *Repository) DeleteWiki() error {
  514. return repo.deleteWiki(x)
  515. }
  516. func (repo *Repository) deleteWiki(e Engine) error {
  517. wikiPaths := []string{repo.WikiPath()}
  518. for _, wikiPath := range wikiPaths {
  519. removeAllWithNotice(e, "Delete repository wiki", wikiPath)
  520. }
  521. _, err := e.Where("repo_id = ?", repo.ID).And("type = ?", UnitTypeWiki).Delete(new(RepoUnit))
  522. return err
  523. }
  524. func (repo *Repository) getAssignees(e Engine) (_ []*User, err error) {
  525. if err = repo.getOwner(e); err != nil {
  526. return nil, err
  527. }
  528. accesses := make([]*Access, 0, 10)
  529. if err = e.
  530. Where("repo_id = ? AND mode >= ?", repo.ID, AccessModeWrite).
  531. Find(&accesses); err != nil {
  532. return nil, err
  533. }
  534. // Leave a seat for owner itself to append later, but if owner is an organization
  535. // and just waste 1 unit is cheaper than re-allocate memory once.
  536. users := make([]*User, 0, len(accesses)+1)
  537. if len(accesses) > 0 {
  538. userIDs := make([]int64, len(accesses))
  539. for i := 0; i < len(accesses); i++ {
  540. userIDs[i] = accesses[i].UserID
  541. }
  542. if err = e.In("id", userIDs).Find(&users); err != nil {
  543. return nil, err
  544. }
  545. }
  546. if !repo.Owner.IsOrganization() {
  547. users = append(users, repo.Owner)
  548. }
  549. return users, nil
  550. }
  551. // GetAssignees returns all users that have write access and can be assigned to issues
  552. // of the repository,
  553. func (repo *Repository) GetAssignees() (_ []*User, err error) {
  554. return repo.getAssignees(x)
  555. }
  556. // GetMilestoneByID returns the milestone belongs to repository by given ID.
  557. func (repo *Repository) GetMilestoneByID(milestoneID int64) (*Milestone, error) {
  558. return GetMilestoneByRepoID(repo.ID, milestoneID)
  559. }
  560. // IssueStats returns number of open and closed repository issues by given filter mode.
  561. func (repo *Repository) IssueStats(uid int64, filterMode int, isPull bool) (int64, int64) {
  562. return GetRepoIssueStats(repo.ID, uid, filterMode, isPull)
  563. }
  564. // GetMirror sets the repository mirror, returns an error upon failure
  565. func (repo *Repository) GetMirror() (err error) {
  566. repo.Mirror, err = GetMirrorByRepoID(repo.ID)
  567. return err
  568. }
  569. // GetBaseRepo populates repo.BaseRepo for a fork repository and
  570. // returns an error on failure (NOTE: no error is returned for
  571. // non-fork repositories, and BaseRepo will be left untouched)
  572. func (repo *Repository) GetBaseRepo() (err error) {
  573. return repo.getBaseRepo(x)
  574. }
  575. func (repo *Repository) getBaseRepo(e Engine) (err error) {
  576. if !repo.IsFork {
  577. return nil
  578. }
  579. repo.BaseRepo, err = getRepositoryByID(e, repo.ForkID)
  580. return err
  581. }
  582. // IsGenerated returns whether _this_ repository was generated from a template
  583. func (repo *Repository) IsGenerated() bool {
  584. return repo.TemplateID != 0
  585. }
  586. // GetTemplateRepo populates repo.TemplateRepo for a generated repository and
  587. // returns an error on failure (NOTE: no error is returned for
  588. // non-generated repositories, and TemplateRepo will be left untouched)
  589. func (repo *Repository) GetTemplateRepo() (err error) {
  590. return repo.getTemplateRepo(x)
  591. }
  592. func (repo *Repository) getTemplateRepo(e Engine) (err error) {
  593. if !repo.IsGenerated() {
  594. return nil
  595. }
  596. repo.TemplateRepo, err = getRepositoryByID(e, repo.TemplateID)
  597. return err
  598. }
  599. func (repo *Repository) repoPath(e Engine) string {
  600. return RepoPath(repo.mustOwnerName(e), repo.Name)
  601. }
  602. // RepoPath returns the repository path
  603. func (repo *Repository) RepoPath() string {
  604. return repo.repoPath(x)
  605. }
  606. // GitConfigPath returns the path to a repository's git config/ directory
  607. func GitConfigPath(repoPath string) string {
  608. return filepath.Join(repoPath, "config")
  609. }
  610. // GitConfigPath returns the repository git config path
  611. func (repo *Repository) GitConfigPath() string {
  612. return GitConfigPath(repo.RepoPath())
  613. }
  614. // RelLink returns the repository relative link
  615. func (repo *Repository) RelLink() string {
  616. return "/" + repo.FullName()
  617. }
  618. // Link returns the repository link
  619. func (repo *Repository) Link() string {
  620. return setting.AppSubURL + "/" + repo.FullName()
  621. }
  622. // ComposeCompareURL returns the repository comparison URL
  623. func (repo *Repository) ComposeCompareURL(oldCommitID, newCommitID string) string {
  624. return fmt.Sprintf("%s/%s/compare/%s...%s", repo.MustOwner().Name, repo.Name, oldCommitID, newCommitID)
  625. }
  626. // UpdateDefaultBranch updates the default branch
  627. func (repo *Repository) UpdateDefaultBranch() error {
  628. _, err := x.ID(repo.ID).Cols("default_branch").Update(repo)
  629. return err
  630. }
  631. // IsOwnedBy returns true when user owns this repository
  632. func (repo *Repository) IsOwnedBy(userID int64) bool {
  633. return repo.OwnerID == userID
  634. }
  635. func (repo *Repository) updateSize(e Engine) error {
  636. size, err := util.GetDirectorySize(repo.repoPath(e))
  637. if err != nil {
  638. return fmt.Errorf("UpdateSize: %v", err)
  639. }
  640. repo.Size = size
  641. _, err = e.ID(repo.ID).Cols("size").Update(repo)
  642. return err
  643. }
  644. // UpdateSize updates the repository size, calculating it using util.GetDirectorySize
  645. func (repo *Repository) UpdateSize() error {
  646. return repo.updateSize(x)
  647. }
  648. // CanUserFork returns true if specified user can fork repository.
  649. func (repo *Repository) CanUserFork(user *User) (bool, error) {
  650. if user == nil {
  651. return false, nil
  652. }
  653. if repo.OwnerID != user.ID && !user.HasForkedRepo(repo.ID) {
  654. return true, nil
  655. }
  656. if err := user.GetOwnedOrganizations(); err != nil {
  657. return false, err
  658. }
  659. for _, org := range user.OwnedOrgs {
  660. if repo.OwnerID != org.ID && !org.HasForkedRepo(repo.ID) {
  661. return true, nil
  662. }
  663. }
  664. return false, nil
  665. }
  666. // CanUserDelete returns true if user could delete the repository
  667. func (repo *Repository) CanUserDelete(user *User) (bool, error) {
  668. if user.IsAdmin || user.ID == repo.OwnerID {
  669. return true, nil
  670. }
  671. if err := repo.GetOwner(); err != nil {
  672. return false, err
  673. }
  674. if repo.Owner.IsOrganization() {
  675. isOwner, err := repo.Owner.IsOwnedBy(user.ID)
  676. if err != nil {
  677. return false, err
  678. } else if isOwner {
  679. return true, nil
  680. }
  681. }
  682. return false, nil
  683. }
  684. // CanEnablePulls returns true if repository meets the requirements of accepting pulls.
  685. func (repo *Repository) CanEnablePulls() bool {
  686. return !repo.IsMirror && !repo.IsEmpty
  687. }
  688. // AllowsPulls returns true if repository meets the requirements of accepting pulls and has them enabled.
  689. func (repo *Repository) AllowsPulls() bool {
  690. return repo.CanEnablePulls() && repo.UnitEnabled(UnitTypePullRequests)
  691. }
  692. // CanEnableEditor returns true if repository meets the requirements of web editor.
  693. func (repo *Repository) CanEnableEditor() bool {
  694. return !repo.IsMirror
  695. }
  696. // GetReaders returns all users that have explicit read access or higher to the repository.
  697. func (repo *Repository) GetReaders() (_ []*User, err error) {
  698. return repo.getUsersWithAccessMode(x, AccessModeRead)
  699. }
  700. // GetWriters returns all users that have write access to the repository.
  701. func (repo *Repository) GetWriters() (_ []*User, err error) {
  702. return repo.getUsersWithAccessMode(x, AccessModeWrite)
  703. }
  704. // IsReader returns true if user has explicit read access or higher to the repository.
  705. func (repo *Repository) IsReader(userID int64) (bool, error) {
  706. if repo.OwnerID == userID {
  707. return true, nil
  708. }
  709. return x.Where("repo_id = ? AND user_id = ? AND mode >= ?", repo.ID, userID, AccessModeRead).Get(&Access{})
  710. }
  711. // getUsersWithAccessMode returns users that have at least given access mode to the repository.
  712. func (repo *Repository) getUsersWithAccessMode(e Engine, mode AccessMode) (_ []*User, err error) {
  713. if err = repo.getOwner(e); err != nil {
  714. return nil, err
  715. }
  716. accesses := make([]*Access, 0, 10)
  717. if err = e.Where("repo_id = ? AND mode >= ?", repo.ID, mode).Find(&accesses); err != nil {
  718. return nil, err
  719. }
  720. // Leave a seat for owner itself to append later, but if owner is an organization
  721. // and just waste 1 unit is cheaper than re-allocate memory once.
  722. users := make([]*User, 0, len(accesses)+1)
  723. if len(accesses) > 0 {
  724. userIDs := make([]int64, len(accesses))
  725. for i := 0; i < len(accesses); i++ {
  726. userIDs[i] = accesses[i].UserID
  727. }
  728. if err = e.In("id", userIDs).Find(&users); err != nil {
  729. return nil, err
  730. }
  731. }
  732. if !repo.Owner.IsOrganization() {
  733. users = append(users, repo.Owner)
  734. }
  735. return users, nil
  736. }
  737. // DescriptionHTML does special handles to description and return HTML string.
  738. func (repo *Repository) DescriptionHTML() template.HTML {
  739. desc, err := markup.RenderDescriptionHTML([]byte(repo.Description), repo.HTMLURL(), repo.ComposeMetas())
  740. if err != nil {
  741. log.Error("Failed to render description for %s (ID: %d): %v", repo.Name, repo.ID, err)
  742. return template.HTML(markup.Sanitize(repo.Description))
  743. }
  744. return template.HTML(markup.Sanitize(string(desc)))
  745. }
  746. // PatchPath returns corresponding patch file path of repository by given issue ID.
  747. func (repo *Repository) PatchPath(index int64) (string, error) {
  748. return repo.patchPath(x, index)
  749. }
  750. func (repo *Repository) patchPath(e Engine, index int64) (string, error) {
  751. if err := repo.getOwner(e); err != nil {
  752. return "", err
  753. }
  754. return filepath.Join(RepoPath(repo.Owner.Name, repo.Name), "pulls", com.ToStr(index)+".patch"), nil
  755. }
  756. // SavePatch saves patch data to corresponding location by given issue ID.
  757. func (repo *Repository) SavePatch(index int64, patch []byte) error {
  758. return repo.savePatch(x, index, patch)
  759. }
  760. func (repo *Repository) savePatch(e Engine, index int64, patch []byte) error {
  761. patchPath, err := repo.patchPath(e, index)
  762. if err != nil {
  763. return fmt.Errorf("PatchPath: %v", err)
  764. }
  765. dir := filepath.Dir(patchPath)
  766. if err := os.MkdirAll(dir, os.ModePerm); err != nil {
  767. return fmt.Errorf("Failed to create dir %s: %v", dir, err)
  768. }
  769. if err = ioutil.WriteFile(patchPath, patch, 0644); err != nil {
  770. return fmt.Errorf("WriteFile: %v", err)
  771. }
  772. return nil
  773. }
  774. func isRepositoryExist(e Engine, u *User, repoName string) (bool, error) {
  775. has, err := e.Get(&Repository{
  776. OwnerID: u.ID,
  777. LowerName: strings.ToLower(repoName),
  778. })
  779. return has && com.IsDir(RepoPath(u.Name, repoName)), err
  780. }
  781. // IsRepositoryExist returns true if the repository with given name under user has already existed.
  782. func IsRepositoryExist(u *User, repoName string) (bool, error) {
  783. return isRepositoryExist(x, u, repoName)
  784. }
  785. // CloneLink represents different types of clone URLs of repository.
  786. type CloneLink struct {
  787. SSH string
  788. HTTPS string
  789. Git string
  790. }
  791. // ComposeHTTPSCloneURL returns HTTPS clone URL based on given owner and repository name.
  792. func ComposeHTTPSCloneURL(owner, repo string) string {
  793. return fmt.Sprintf("%s%s/%s.git", setting.AppURL, url.PathEscape(owner), url.PathEscape(repo))
  794. }
  795. func (repo *Repository) cloneLink(e Engine, isWiki bool) *CloneLink {
  796. repoName := repo.Name
  797. if isWiki {
  798. repoName += ".wiki"
  799. }
  800. sshUser := setting.RunUser
  801. if setting.SSH.StartBuiltinServer {
  802. sshUser = setting.SSH.BuiltinServerUser
  803. }
  804. repo.Owner = repo.mustOwner(e)
  805. cl := new(CloneLink)
  806. if setting.SSH.Port != 22 {
  807. cl.SSH = fmt.Sprintf("ssh://%s@%s:%d/%s/%s.git", sshUser, setting.SSH.Domain, setting.SSH.Port, repo.Owner.Name, repoName)
  808. } else if setting.Repository.UseCompatSSHURI {
  809. cl.SSH = fmt.Sprintf("ssh://%s@%s/%s/%s.git", sshUser, setting.SSH.Domain, repo.Owner.Name, repoName)
  810. } else {
  811. cl.SSH = fmt.Sprintf("%s@%s:%s/%s.git", sshUser, setting.SSH.Domain, repo.Owner.Name, repoName)
  812. }
  813. cl.HTTPS = ComposeHTTPSCloneURL(repo.Owner.Name, repoName)
  814. return cl
  815. }
  816. // CloneLink returns clone URLs of repository.
  817. func (repo *Repository) CloneLink() (cl *CloneLink) {
  818. return repo.cloneLink(x, false)
  819. }
  820. /*
  821. GitHub, GitLab, Gogs: *.wiki.git
  822. BitBucket: *.git/wiki
  823. */
  824. var commonWikiURLSuffixes = []string{".wiki.git", ".git/wiki"}
  825. // wikiRemoteURL returns accessible repository URL for wiki if exists.
  826. // Otherwise, it returns an empty string.
  827. func wikiRemoteURL(remote string) string {
  828. remote = strings.TrimSuffix(remote, ".git")
  829. for _, suffix := range commonWikiURLSuffixes {
  830. wikiURL := remote + suffix
  831. if git.IsRepoURLAccessible(wikiURL) {
  832. return wikiURL
  833. }
  834. }
  835. return ""
  836. }
  837. // CheckCreateRepository check if could created a repository
  838. func CheckCreateRepository(doer, u *User, name string) error {
  839. if !doer.CanCreateRepo() {
  840. return ErrReachLimitOfRepo{u.MaxRepoCreation}
  841. }
  842. if err := IsUsableRepoName(name); err != nil {
  843. return err
  844. }
  845. has, err := isRepositoryExist(x, u, name)
  846. if err != nil {
  847. return fmt.Errorf("IsRepositoryExist: %v", err)
  848. } else if has {
  849. return ErrRepoAlreadyExist{u.Name, name}
  850. }
  851. return nil
  852. }
  853. // MigrateRepositoryGitData starts migrating git related data after created migrating repository
  854. func MigrateRepositoryGitData(doer, u *User, repo *Repository, opts api.MigrateRepoOption) (*Repository, error) {
  855. repoPath := RepoPath(u.Name, opts.RepoName)
  856. if u.IsOrganization() {
  857. t, err := u.GetOwnerTeam()
  858. if err != nil {
  859. return nil, err
  860. }
  861. repo.NumWatches = t.NumMembers
  862. } else {
  863. repo.NumWatches = 1
  864. }
  865. migrateTimeout := time.Duration(setting.Git.Timeout.Migrate) * time.Second
  866. var err error
  867. if err = os.RemoveAll(repoPath); err != nil {
  868. return repo, fmt.Errorf("Failed to remove %s: %v", repoPath, err)
  869. }
  870. if err = git.Clone(opts.CloneAddr, repoPath, git.CloneRepoOptions{
  871. Mirror: true,
  872. Quiet: true,
  873. Timeout: migrateTimeout,
  874. }); err != nil {
  875. return repo, fmt.Errorf("Clone: %v", err)
  876. }
  877. if opts.Wiki {
  878. wikiPath := WikiPath(u.Name, opts.RepoName)
  879. wikiRemotePath := wikiRemoteURL(opts.CloneAddr)
  880. if len(wikiRemotePath) > 0 {
  881. if err := os.RemoveAll(wikiPath); err != nil {
  882. return repo, fmt.Errorf("Failed to remove %s: %v", wikiPath, err)
  883. }
  884. if err = git.Clone(wikiRemotePath, wikiPath, git.CloneRepoOptions{
  885. Mirror: true,
  886. Quiet: true,
  887. Timeout: migrateTimeout,
  888. Branch: "master",
  889. }); err != nil {
  890. log.Warn("Clone wiki: %v", err)
  891. if err := os.RemoveAll(wikiPath); err != nil {
  892. return repo, fmt.Errorf("Failed to remove %s: %v", wikiPath, err)
  893. }
  894. }
  895. }
  896. }
  897. gitRepo, err := git.OpenRepository(repoPath)
  898. if err != nil {
  899. return repo, fmt.Errorf("OpenRepository: %v", err)
  900. }
  901. defer gitRepo.Close()
  902. repo.IsEmpty, err = gitRepo.IsEmpty()
  903. if err != nil {
  904. return repo, fmt.Errorf("git.IsEmpty: %v", err)
  905. }
  906. if !opts.Releases && !repo.IsEmpty {
  907. // Try to get HEAD branch and set it as default branch.
  908. headBranch, err := gitRepo.GetHEADBranch()
  909. if err != nil {
  910. return repo, fmt.Errorf("GetHEADBranch: %v", err)
  911. }
  912. if headBranch != nil {
  913. repo.DefaultBranch = headBranch.Name
  914. }
  915. if err = SyncReleasesWithTags(repo, gitRepo); err != nil {
  916. log.Error("Failed to synchronize tags to releases for repository: %v", err)
  917. }
  918. }
  919. if err = repo.UpdateSize(); err != nil {
  920. log.Error("Failed to update size for repository: %v", err)
  921. }
  922. if opts.Mirror {
  923. if _, err = x.InsertOne(&Mirror{
  924. RepoID: repo.ID,
  925. Interval: setting.Mirror.DefaultInterval,
  926. EnablePrune: true,
  927. NextUpdateUnix: timeutil.TimeStampNow().AddDuration(setting.Mirror.DefaultInterval),
  928. }); err != nil {
  929. return repo, fmt.Errorf("InsertOne: %v", err)
  930. }
  931. repo.IsMirror = true
  932. err = UpdateRepository(repo, false)
  933. } else {
  934. repo, err = CleanUpMigrateInfo(repo)
  935. }
  936. if err != nil && !repo.IsEmpty {
  937. UpdateRepoIndexer(repo)
  938. }
  939. return repo, err
  940. }
  941. // cleanUpMigrateGitConfig removes mirror info which prevents "push --all".
  942. // This also removes possible user credentials.
  943. func cleanUpMigrateGitConfig(configPath string) error {
  944. cfg, err := ini.Load(configPath)
  945. if err != nil {
  946. return fmt.Errorf("open config file: %v", err)
  947. }
  948. cfg.DeleteSection("remote \"origin\"")
  949. if err = cfg.SaveToIndent(configPath, "\t"); err != nil {
  950. return fmt.Errorf("save config file: %v", err)
  951. }
  952. return nil
  953. }
  954. // createDelegateHooks creates all the hooks scripts for the repo
  955. func createDelegateHooks(repoPath string) (err error) {
  956. var (
  957. hookNames = []string{"pre-receive", "update", "post-receive"}
  958. hookTpls = []string{
  959. fmt.Sprintf("#!/usr/bin/env %s\ndata=$(cat)\nexitcodes=\"\"\nhookname=$(basename $0)\nGIT_DIR=${GIT_DIR:-$(dirname $0)}\n\nfor hook in ${GIT_DIR}/hooks/${hookname}.d/*; do\ntest -x \"${hook}\" || continue\necho \"${data}\" | \"${hook}\"\nexitcodes=\"${exitcodes} $?\"\ndone\n\nfor i in ${exitcodes}; do\n[ ${i} -eq 0 ] || exit ${i}\ndone\n", setting.ScriptType),
  960. fmt.Sprintf("#!/usr/bin/env %s\nexitcodes=\"\"\nhookname=$(basename $0)\nGIT_DIR=${GIT_DIR:-$(dirname $0)}\n\nfor hook in ${GIT_DIR}/hooks/${hookname}.d/*; do\ntest -x \"${hook}\" || continue\n\"${hook}\" $1 $2 $3\nexitcodes=\"${exitcodes} $?\"\ndone\n\nfor i in ${exitcodes}; do\n[ ${i} -eq 0 ] || exit ${i}\ndone\n", setting.ScriptType),
  961. fmt.Sprintf("#!/usr/bin/env %s\ndata=$(cat)\nexitcodes=\"\"\nhookname=$(basename $0)\nGIT_DIR=${GIT_DIR:-$(dirname $0)}\n\nfor hook in ${GIT_DIR}/hooks/${hookname}.d/*; do\ntest -x \"${hook}\" || continue\necho \"${data}\" | \"${hook}\"\nexitcodes=\"${exitcodes} $?\"\ndone\n\nfor i in ${exitcodes}; do\n[ ${i} -eq 0 ] || exit ${i}\ndone\n", setting.ScriptType),
  962. }
  963. giteaHookTpls = []string{
  964. fmt.Sprintf("#!/usr/bin/env %s\n\"%s\" hook --config='%s' pre-receive\n", setting.ScriptType, setting.AppPath, setting.CustomConf),
  965. fmt.Sprintf("#!/usr/bin/env %s\n\"%s\" hook --config='%s' update $1 $2 $3\n", setting.ScriptType, setting.AppPath, setting.CustomConf),
  966. fmt.Sprintf("#!/usr/bin/env %s\n\"%s\" hook --config='%s' post-receive\n", setting.ScriptType, setting.AppPath, setting.CustomConf),
  967. }
  968. )
  969. hookDir := filepath.Join(repoPath, "hooks")
  970. for i, hookName := range hookNames {
  971. oldHookPath := filepath.Join(hookDir, hookName)
  972. newHookPath := filepath.Join(hookDir, hookName+".d", "gitea")
  973. if err := os.MkdirAll(filepath.Join(hookDir, hookName+".d"), os.ModePerm); err != nil {
  974. return fmt.Errorf("create hooks dir '%s': %v", filepath.Join(hookDir, hookName+".d"), err)
  975. }
  976. // WARNING: This will override all old server-side hooks
  977. if err = ioutil.WriteFile(oldHookPath, []byte(hookTpls[i]), 0777); err != nil {
  978. return fmt.Errorf("write old hook file '%s': %v", oldHookPath, err)
  979. }
  980. if err = ioutil.WriteFile(newHookPath, []byte(giteaHookTpls[i]), 0777); err != nil {
  981. return fmt.Errorf("write new hook file '%s': %v", newHookPath, err)
  982. }
  983. }
  984. return nil
  985. }
  986. // CleanUpMigrateInfo finishes migrating repository and/or wiki with things that don't need to be done for mirrors.
  987. func CleanUpMigrateInfo(repo *Repository) (*Repository, error) {
  988. repoPath := repo.RepoPath()
  989. if err := createDelegateHooks(repoPath); err != nil {
  990. return repo, fmt.Errorf("createDelegateHooks: %v", err)
  991. }
  992. if repo.HasWiki() {
  993. if err := createDelegateHooks(repo.WikiPath()); err != nil {
  994. return repo, fmt.Errorf("createDelegateHooks.(wiki): %v", err)
  995. }
  996. }
  997. _, err := git.NewCommand("remote", "rm", "origin").RunInDir(repoPath)
  998. if err != nil && !strings.HasPrefix(err.Error(), "exit status 128 - fatal: No such remote ") {
  999. return repo, fmt.Errorf("CleanUpMigrateInfo: %v", err)
  1000. }
  1001. if repo.HasWiki() {
  1002. if err := cleanUpMigrateGitConfig(path.Join(repo.WikiPath(), "config")); err != nil {
  1003. return repo, fmt.Errorf("cleanUpMigrateGitConfig (wiki): %v", err)
  1004. }
  1005. }
  1006. return repo, UpdateRepository(repo, false)
  1007. }
  1008. // initRepoCommit temporarily changes with work directory.
  1009. func initRepoCommit(tmpPath string, u *User) (err error) {
  1010. commitTimeStr := time.Now().Format(time.RFC3339)
  1011. sig := u.NewGitSig()
  1012. // Because this may call hooks we should pass in the environment
  1013. env := append(os.Environ(),
  1014. "GIT_AUTHOR_NAME="+sig.Name,
  1015. "GIT_AUTHOR_EMAIL="+sig.Email,
  1016. "GIT_AUTHOR_DATE="+commitTimeStr,
  1017. "GIT_COMMITTER_NAME="+sig.Name,
  1018. "GIT_COMMITTER_EMAIL="+sig.Email,
  1019. "GIT_COMMITTER_DATE="+commitTimeStr,
  1020. )
  1021. var stderr string
  1022. if _, stderr, err = process.GetManager().ExecDir(-1,
  1023. tmpPath, fmt.Sprintf("initRepoCommit (git add): %s", tmpPath),
  1024. git.GitExecutable, "add", "--all"); err != nil {
  1025. return fmt.Errorf("git add: %s", stderr)
  1026. }
  1027. binVersion, err := git.BinVersion()
  1028. if err != nil {
  1029. return fmt.Errorf("Unable to get git version: %v", err)
  1030. }
  1031. args := []string{
  1032. "commit", fmt.Sprintf("--author='%s <%s>'", sig.Name, sig.Email),
  1033. "-m", "Initial commit",
  1034. }
  1035. if version.Compare(binVersion, "1.7.9", ">=") {
  1036. sign, keyID := SignInitialCommit(tmpPath, u)
  1037. if sign {
  1038. args = append(args, "-S"+keyID)
  1039. } else if version.Compare(binVersion, "2.0.0", ">=") {
  1040. args = append(args, "--no-gpg-sign")
  1041. }
  1042. }
  1043. if _, stderr, err = process.GetManager().ExecDirEnv(-1,
  1044. tmpPath, fmt.Sprintf("initRepoCommit (git commit): %s", tmpPath),
  1045. env,
  1046. git.GitExecutable, args...); err != nil {
  1047. return fmt.Errorf("git commit: %s", stderr)
  1048. }
  1049. if _, stderr, err = process.GetManager().ExecDir(-1,
  1050. tmpPath, fmt.Sprintf("initRepoCommit (git push): %s", tmpPath),
  1051. git.GitExecutable, "push", "origin", "master"); err != nil {
  1052. return fmt.Errorf("git push: %s", stderr)
  1053. }
  1054. return nil
  1055. }
  1056. // CreateRepoOptions contains the create repository options
  1057. type CreateRepoOptions struct {
  1058. Name string
  1059. Description string
  1060. OriginalURL string
  1061. Gitignores string
  1062. IssueLabels string
  1063. License string
  1064. Readme string
  1065. IsPrivate bool
  1066. IsMirror bool
  1067. AutoInit bool
  1068. Status RepositoryStatus
  1069. }
  1070. // GenerateRepoOptions contains the template units to generate
  1071. type GenerateRepoOptions struct {
  1072. Name string
  1073. Description string
  1074. Private bool
  1075. GitContent bool
  1076. Topics bool
  1077. }
  1078. // IsValid checks whether at least one option is chosen for generation
  1079. func (gro GenerateRepoOptions) IsValid() bool {
  1080. return gro.GitContent || gro.Topics // or other items as they are added
  1081. }
  1082. func getRepoInitFile(tp, name string) ([]byte, error) {
  1083. cleanedName := strings.TrimLeft(path.Clean("/"+name), "/")
  1084. relPath := path.Join("options", tp, cleanedName)
  1085. // Use custom file when available.
  1086. customPath := path.Join(setting.CustomPath, relPath)
  1087. if com.IsFile(customPath) {
  1088. return ioutil.ReadFile(customPath)
  1089. }
  1090. switch tp {
  1091. case "readme":
  1092. return options.Readme(cleanedName)
  1093. case "gitignore":
  1094. return options.Gitignore(cleanedName)
  1095. case "license":
  1096. return options.License(cleanedName)
  1097. case "label":
  1098. return options.Labels(cleanedName)
  1099. default:
  1100. return []byte{}, fmt.Errorf("Invalid init file type")
  1101. }
  1102. }
  1103. func prepareRepoCommit(e Engine, repo *Repository, tmpDir, repoPath string, opts CreateRepoOptions) error {
  1104. commitTimeStr := time.Now().Format(time.RFC3339)
  1105. authorSig := repo.Owner.NewGitSig()
  1106. // Because this may call hooks we should pass in the environment
  1107. env := append(os.Environ(),
  1108. "GIT_AUTHOR_NAME="+authorSig.Name,
  1109. "GIT_AUTHOR_EMAIL="+authorSig.Email,
  1110. "GIT_AUTHOR_DATE="+commitTimeStr,
  1111. "GIT_COMMITTER_NAME="+authorSig.Name,
  1112. "GIT_COMMITTER_EMAIL="+authorSig.Email,
  1113. "GIT_COMMITTER_DATE="+commitTimeStr,
  1114. )
  1115. // Clone to temporary path and do the init commit.
  1116. _, stderr, err := process.GetManager().ExecDirEnv(
  1117. -1, "",
  1118. fmt.Sprintf("initRepository(git clone): %s", repoPath),
  1119. env,
  1120. git.GitExecutable, "clone", repoPath, tmpDir,
  1121. )
  1122. if err != nil {
  1123. return fmt.Errorf("git clone: %v - %s", err, stderr)
  1124. }
  1125. // README
  1126. data, err := getRepoInitFile("readme", opts.Readme)
  1127. if err != nil {
  1128. return fmt.Errorf("getRepoInitFile[%s]: %v", opts.Readme, err)
  1129. }
  1130. cloneLink := repo.cloneLink(e, false)
  1131. match := map[string]string{
  1132. "Name": repo.Name,
  1133. "Description": repo.Description,
  1134. "CloneURL.SSH": cloneLink.SSH,
  1135. "CloneURL.HTTPS": cloneLink.HTTPS,
  1136. }
  1137. if err = ioutil.WriteFile(filepath.Join(tmpDir, "README.md"),
  1138. []byte(com.Expand(string(data), match)), 0644); err != nil {
  1139. return fmt.Errorf("write README.md: %v", err)
  1140. }
  1141. // .gitignore
  1142. if len(opts.Gitignores) > 0 {
  1143. var buf bytes.Buffer
  1144. names := strings.Split(opts.Gitignores, ",")
  1145. for _, name := range names {
  1146. data, err = getRepoInitFile("gitignore", name)
  1147. if err != nil {
  1148. return fmt.Errorf("getRepoInitFile[%s]: %v", name, err)
  1149. }
  1150. buf.WriteString("# ---> " + name + "\n")
  1151. buf.Write(data)
  1152. buf.WriteString("\n")
  1153. }
  1154. if buf.Len() > 0 {
  1155. if err = ioutil.WriteFile(filepath.Join(tmpDir, ".gitignore"), buf.Bytes(), 0644); err != nil {
  1156. return fmt.Errorf("write .gitignore: %v", err)
  1157. }
  1158. }
  1159. }
  1160. // LICENSE
  1161. if len(opts.License) > 0 {
  1162. data, err = getRepoInitFile("license", opts.License)
  1163. if err != nil {
  1164. return fmt.Errorf("getRepoInitFile[%s]: %v", opts.License, err)
  1165. }
  1166. if err = ioutil.WriteFile(filepath.Join(tmpDir, "LICENSE"), data, 0644); err != nil {
  1167. return fmt.Errorf("write LICENSE: %v", err)
  1168. }
  1169. }
  1170. return nil
  1171. }
  1172. func generateRepoCommit(e Engine, repo, templateRepo *Repository, tmpDir string) error {
  1173. commitTimeStr := time.Now().Format(time.RFC3339)
  1174. authorSig := repo.Owner.NewGitSig()
  1175. // Because this may call hooks we should pass in the environment
  1176. env := append(os.Environ(),
  1177. "GIT_AUTHOR_NAME="+authorSig.Name,
  1178. "GIT_AUTHOR_EMAIL="+authorSig.Email,
  1179. "GIT_AUTHOR_DATE="+commitTimeStr,
  1180. "GIT_COMMITTER_NAME="+authorSig.Name,
  1181. "GIT_COMMITTER_EMAIL="+authorSig.Email,
  1182. "GIT_COMMITTER_DATE="+commitTimeStr,
  1183. )
  1184. // Clone to temporary path and do the init commit.
  1185. templateRepoPath := templateRepo.repoPath(e)
  1186. _, stderr, err := process.GetManager().ExecDirEnv(
  1187. -1, "",
  1188. fmt.Sprintf("generateRepoCommit(git clone): %s", templateRepoPath),
  1189. env,
  1190. git.GitExecutable, "clone", "--depth", "1", templateRepoPath, tmpDir,
  1191. )
  1192. if err != nil {
  1193. return fmt.Errorf("git clone: %v - %s", err, stderr)
  1194. }
  1195. if err := os.RemoveAll(path.Join(tmpDir, ".git")); err != nil {
  1196. return fmt.Errorf("remove git dir: %v", err)
  1197. }
  1198. if err := git.InitRepository(tmpDir, false); err != nil {
  1199. return err
  1200. }
  1201. repoPath := repo.repoPath(e)
  1202. _, stderr, err = process.GetManager().ExecDirEnv(
  1203. -1, tmpDir,
  1204. fmt.Sprintf("generateRepoCommit(git remote add): %s", repoPath),
  1205. env,
  1206. git.GitExecutable, "remote", "add", "origin", repoPath,
  1207. )
  1208. if err != nil {
  1209. return fmt.Errorf("git remote add: %v - %s", err, stderr)
  1210. }
  1211. return initRepoCommit(tmpDir, repo.Owner)
  1212. }
  1213. func checkInitRepository(repoPath string) (err error) {
  1214. // Somehow the directory could exist.
  1215. if com.IsExist(repoPath) {
  1216. return fmt.Errorf("initRepository: path already exists: %s", repoPath)
  1217. }
  1218. // Init git bare new repository.
  1219. if err = git.InitRepository(repoPath, true); err != nil {
  1220. return fmt.Errorf("InitRepository: %v", err)
  1221. } else if err = createDelegateHooks(repoPath); err != nil {
  1222. return fmt.Errorf("createDelegateHooks: %v", err)
  1223. }
  1224. return nil
  1225. }
  1226. // InitRepository initializes README and .gitignore if needed.
  1227. func initRepository(e Engine, repoPath string, u *User, repo *Repository, opts CreateRepoOptions) (err error) {
  1228. if err = checkInitRepository(repoPath); err != nil {
  1229. return err
  1230. }
  1231. tmpDir := filepath.Join(os.TempDir(), "gitea-"+repo.Name+"-"+com.ToStr(time.Now().Nanosecond()))
  1232. // Initialize repository according to user's choice.
  1233. if opts.AutoInit {
  1234. if err := os.MkdirAll(tmpDir, os.ModePerm); err != nil {
  1235. return fmt.Errorf("Failed to create dir %s: %v", tmpDir, err)
  1236. }
  1237. defer os.RemoveAll(tmpDir)
  1238. if err = prepareRepoCommit(e, repo, tmpDir, repoPath, opts); err != nil {
  1239. return fmt.Errorf("prepareRepoCommit: %v", err)
  1240. }
  1241. // Apply changes and commit.
  1242. if err = initRepoCommit(tmpDir, u); err != nil {
  1243. return fmt.Errorf("initRepoCommit: %v", err)
  1244. }
  1245. }
  1246. // Re-fetch the repository from database before updating it (else it would
  1247. // override changes that were done earlier with sql)
  1248. if repo, err = getRepositoryByID(e, repo.ID); err != nil {
  1249. return fmt.Errorf("getRepositoryByID: %v", err)
  1250. }
  1251. if !opts.AutoInit {
  1252. repo.IsEmpty = true
  1253. }
  1254. repo.DefaultBranch = "master"
  1255. if err = updateRepository(e, repo, false); err != nil {
  1256. return fmt.Errorf("updateRepository: %v", err)
  1257. }
  1258. return nil
  1259. }
  1260. // generateRepository initializes repository from template
  1261. func generateRepository(e Engine, repo, templateRepo *Repository) (err error) {
  1262. tmpDir := filepath.Join(os.TempDir(), "gitea-"+repo.Name+"-"+com.ToStr(time.Now().Nanosecond()))
  1263. if err := os.MkdirAll(tmpDir, os.ModePerm); err != nil {
  1264. return fmt.Errorf("Failed to create dir %s: %v", tmpDir, err)
  1265. }
  1266. defer func() {
  1267. if err := os.RemoveAll(tmpDir); err != nil {
  1268. log.Error("RemoveAll: %v", err)
  1269. }
  1270. }()
  1271. if err = generateRepoCommit(e, repo, templateRepo, tmpDir); err != nil {
  1272. return fmt.Errorf("generateRepoCommit: %v", err)
  1273. }
  1274. // re-fetch repo
  1275. if repo, err = getRepositoryByID(e, repo.ID); err != nil {
  1276. return fmt.Errorf("getRepositoryByID: %v", err)
  1277. }
  1278. repo.DefaultBranch = "master"
  1279. if err = updateRepository(e, repo, false); err != nil {
  1280. return fmt.Errorf("updateRepository: %v", err)
  1281. }
  1282. return nil
  1283. }
  1284. var (
  1285. reservedRepoNames = []string{".", ".."}
  1286. reservedRepoPatterns = []string{"*.git", "*.wiki"}
  1287. )
  1288. // IsUsableRepoName returns true when repository is usable
  1289. func IsUsableRepoName(name string) error {
  1290. return isUsableName(reservedRepoNames, reservedRepoPatterns, name)
  1291. }
  1292. func createRepository(e *xorm.Session, doer, u *User, repo *Repository) (err error) {
  1293. if err = IsUsableRepoName(repo.Name); err != nil {
  1294. return err
  1295. }
  1296. has, err := isRepositoryExist(e, u, repo.Name)
  1297. if err != nil {
  1298. return fmt.Errorf("IsRepositoryExist: %v", err)
  1299. } else if has {
  1300. return ErrRepoAlreadyExist{u.Name, repo.Name}
  1301. }
  1302. if _, err = e.Insert(repo); err != nil {
  1303. return err
  1304. }
  1305. if err = deleteRepoRedirect(e, u.ID, repo.Name); err != nil {
  1306. return err
  1307. }
  1308. // insert units for repo
  1309. var units = make([]RepoUnit, 0, len(DefaultRepoUnits))
  1310. for _, tp := range DefaultRepoUnits {
  1311. if tp == UnitTypeIssues {
  1312. units = append(units, RepoUnit{
  1313. RepoID: repo.ID,
  1314. Type: tp,
  1315. Config: &IssuesConfig{
  1316. EnableTimetracker: setting.Service.DefaultEnableTimetracking,
  1317. AllowOnlyContributorsToTrackTime: setting.Service.DefaultAllowOnlyContributorsToTrackTime,
  1318. EnableDependencies: setting.Service.DefaultEnableDependencies,
  1319. },
  1320. })
  1321. } else if tp == UnitTypePullRequests {
  1322. units = append(units, RepoUnit{
  1323. RepoID: repo.ID,
  1324. Type: tp,
  1325. Config: &PullRequestsConfig{AllowMerge: true, AllowRebase: true, AllowRebaseMerge: true, AllowSquash: true},
  1326. })
  1327. } else {
  1328. units = append(units, RepoUnit{
  1329. RepoID: repo.ID,
  1330. Type: tp,
  1331. })
  1332. }
  1333. }
  1334. if _, err = e.Insert(&units); err != nil {
  1335. return err
  1336. }
  1337. // Remember visibility preference.
  1338. u.LastRepoVisibility = repo.IsPrivate
  1339. if err = updateUserCols(e, u, "last_repo_visibility"); err != nil {
  1340. return fmt.Errorf("updateUser: %v", err)
  1341. }
  1342. if _, err = e.Incr("num_repos").ID(u.ID).Update(new(User)); err != nil {
  1343. return fmt.Errorf("increment user total_repos: %v", err)
  1344. }
  1345. u.NumRepos++
  1346. // Give access to all members in teams with access to all repositories.
  1347. if u.IsOrganization() {
  1348. if err := u.GetTeams(); err != nil {
  1349. return fmt.Errorf("GetTeams: %v", err)
  1350. }
  1351. for _, t := range u.Teams {
  1352. if t.IncludesAllRepositories {
  1353. if err := t.addRepository(e, repo); err != nil {
  1354. return fmt.Errorf("addRepository: %v", err)
  1355. }
  1356. }
  1357. }
  1358. } else if err = repo.recalculateAccesses(e); err != nil {
  1359. // Organization automatically called this in addRepository method.
  1360. return fmt.Errorf("recalculateAccesses: %v", err)
  1361. }
  1362. if setting.Service.AutoWatchNewRepos {
  1363. if err = watchRepo(e, doer.ID, repo.ID, true); err != nil {
  1364. return fmt.Errorf("watchRepo: %v", err)
  1365. }
  1366. }
  1367. if err = copyDefaultWebhooksToRepo(e, repo.ID); err != nil {
  1368. return fmt.Errorf("copyDefaultWebhooksToRepo: %v", err)
  1369. }
  1370. return nil
  1371. }
  1372. // CreateRepository creates a repository for the user/organization.
  1373. func CreateRepository(doer, u *User, opts CreateRepoOptions) (_ *Repository, err error) {
  1374. if !doer.IsAdmin && !u.CanCreateRepo() {
  1375. return nil, ErrReachLimitOfRepo{u.MaxRepoCreation}
  1376. }
  1377. repo := &Repository{
  1378. OwnerID: u.ID,
  1379. Owner: u,
  1380. Name: opts.Name,
  1381. LowerName: strings.ToLower(opts.Name),
  1382. Description: opts.Description,
  1383. OriginalURL: opts.OriginalURL,
  1384. IsPrivate: opts.IsPrivate,
  1385. IsFsckEnabled: !opts.IsMirror,
  1386. CloseIssuesViaCommitInAnyBranch: setting.Repository.DefaultCloseIssuesViaCommitsInAnyBranch,
  1387. Status: opts.Status,
  1388. IsEmpty: !opts.AutoInit,
  1389. }
  1390. sess := x.NewSession()
  1391. defer sess.Close()
  1392. if err = sess.Begin(); err != nil {
  1393. return nil, err
  1394. }
  1395. if err = createRepository(sess, doer, u, repo); err != nil {
  1396. return nil, err
  1397. }
  1398. // No need for init mirror.
  1399. if !opts.IsMirror {
  1400. repoPath := RepoPath(u.Name, repo.Name)
  1401. if err = initRepository(sess, repoPath, u, repo, opts); err != nil {
  1402. if err2 := os.RemoveAll(repoPath); err2 != nil {
  1403. log.Error("initRepository: %v", err)
  1404. return nil, fmt.Errorf(
  1405. "delete repo directory %s/%s failed(2): %v", u.Name, repo.Name, err2)
  1406. }
  1407. return nil, fmt.Errorf("initRepository: %v", err)
  1408. }
  1409. // Initialize Issue Labels if selected
  1410. if len(opts.IssueLabels) > 0 {
  1411. if err = initalizeLabels(sess, repo.ID, opts.IssueLabels); err != nil {
  1412. return nil, fmt.Errorf("initalizeLabels: %v", err)
  1413. }
  1414. }
  1415. _, stderr, err := process.GetManager().ExecDir(-1,
  1416. repoPath, fmt.Sprintf("CreateRepository(git update-server-info): %s", repoPath),
  1417. git.GitExecutable, "update-server-info")
  1418. if err != nil {
  1419. return nil, errors.New("CreateRepository(git update-server-info): " + stderr)
  1420. }
  1421. }
  1422. if err = sess.Commit(); err != nil {
  1423. return nil, err
  1424. }
  1425. return repo, err
  1426. }
  1427. func countRepositories(userID int64, private bool) int64 {
  1428. sess := x.Where("id > 0")
  1429. if userID > 0 {
  1430. sess.And("owner_id = ?", userID)
  1431. }
  1432. if !private {
  1433. sess.And("is_private=?", false)
  1434. }
  1435. count, err := sess.Count(new(Repository))
  1436. if err != nil {
  1437. log.Error("countRepositories: %v", err)
  1438. }
  1439. return count
  1440. }
  1441. // CountRepositories returns number of repositories.
  1442. // Argument private only takes effect when it is false,
  1443. // set it true to count all repositories.
  1444. func CountRepositories(private bool) int64 {
  1445. return countRepositories(-1, private)
  1446. }
  1447. // CountUserRepositories returns number of repositories user owns.
  1448. // Argument private only takes effect when it is false,
  1449. // set it true to count all repositories.
  1450. func CountUserRepositories(userID int64, private bool) int64 {
  1451. return countRepositories(userID, private)
  1452. }
  1453. // RepoPath returns repository path by given user and repository name.
  1454. func RepoPath(userName, repoName string) string {
  1455. return filepath.Join(UserPath(userName), strings.ToLower(repoName)+".git")
  1456. }
  1457. // TransferOwnership transfers all corresponding setting from old user to new one.
  1458. func TransferOwnership(doer *User, newOwnerName string, repo *Repository) error {
  1459. newOwner, err := GetUserByName(newOwnerName)
  1460. if err != nil {
  1461. return fmt.Errorf("get new owner '%s': %v", newOwnerName, err)
  1462. }
  1463. // Check if new owner has repository with same name.
  1464. has, err := IsRepositoryExist(newOwner, repo.Name)
  1465. if err != nil {
  1466. return fmt.Errorf("IsRepositoryExist: %v", err)
  1467. } else if has {
  1468. return ErrRepoAlreadyExist{newOwnerName, repo.Name}
  1469. }
  1470. sess := x.NewSession()
  1471. defer sess.Close()
  1472. if err = sess.Begin(); err != nil {
  1473. return fmt.Errorf("sess.Begin: %v", err)
  1474. }
  1475. owner := repo.Owner
  1476. // Note: we have to set value here to make sure recalculate accesses is based on
  1477. // new owner.
  1478. repo.OwnerID = newOwner.ID
  1479. repo.Owner = newOwner
  1480. // Update repository.
  1481. if _, err := sess.ID(repo.ID).Update(repo); err != nil {
  1482. return fmt.Errorf("update owner: %v", err)
  1483. }
  1484. // Remove redundant collaborators.
  1485. collaborators, err := repo.getCollaborators(sess)
  1486. if err != nil {
  1487. return fmt.Errorf("getCollaborators: %v", err)
  1488. }
  1489. // Dummy object.
  1490. collaboration := &Collaboration{RepoID: repo.ID}
  1491. for _, c := range collaborators {
  1492. if c.ID != newOwner.ID {
  1493. isMember, err := isOrganizationMember(sess, newOwner.ID, c.ID)
  1494. if err != nil {
  1495. return fmt.Errorf("IsOrgMember: %v", err)
  1496. } else if !isMember {
  1497. continue
  1498. }
  1499. }
  1500. collaboration.UserID = c.ID
  1501. if _, err = sess.Delete(collaboration); err != nil {
  1502. return fmt.Errorf("remove collaborator '%d': %v", c.ID, err)
  1503. }
  1504. }
  1505. // Remove old team-repository relations.
  1506. if owner.IsOrganization() {
  1507. if err = owner.removeOrgRepo(sess, repo.ID); err != nil {
  1508. return fmt.Errorf("removeOrgRepo: %v", err)
  1509. }
  1510. }
  1511. if newOwner.IsOrganization() {
  1512. if err := newOwner.GetTeams(); err != nil {
  1513. return fmt.Errorf("GetTeams: %v", err)
  1514. }
  1515. for _, t := range newOwner.Teams {
  1516. if t.IncludesAllRepositories {
  1517. if err := t.addRepository(sess, repo); err != nil {
  1518. return fmt.Errorf("addRepository: %v", err)
  1519. }
  1520. }
  1521. }
  1522. } else if err = repo.recalculateAccesses(sess); err != nil {
  1523. // Organization called this in addRepository method.
  1524. return fmt.Errorf("recalculateAccesses: %v", err)
  1525. }
  1526. // Update repository count.
  1527. if _, err = sess.Exec("UPDATE `user` SET num_repos=num_repos+1 WHERE id=?", newOwner.ID); err != nil {
  1528. return fmt.Errorf("increase new owner repository count: %v", err)
  1529. } else if _, err = sess.Exec("UPDATE `user` SET num_repos=num_repos-1 WHERE id=?", owner.ID); err != nil {
  1530. return fmt.Errorf("decrease old owner repository count: %v", err)
  1531. }
  1532. if err = watchRepo(sess, doer.ID, repo.ID, true); err != nil {
  1533. return fmt.Errorf("watchRepo: %v", err)
  1534. }
  1535. // Remove watch for organization.
  1536. if owner.IsOrganization() {
  1537. if err = watchRepo(sess, owner.ID, repo.ID, false); err != nil {
  1538. return fmt.Errorf("watchRepo [false]: %v", err)
  1539. }
  1540. }
  1541. // Rename remote repository to new path and delete local copy.
  1542. dir := UserPath(newOwner.Name)
  1543. if err := os.MkdirAll(dir, os.ModePerm); err != nil {
  1544. return fmt.Errorf("Failed to create dir %s: %v", dir, err)
  1545. }
  1546. if err = os.Rename(RepoPath(owner.Name, repo.Name), RepoPath(newOwner.Name, repo.Name)); err != nil {
  1547. return fmt.Errorf("rename repository directory: %v", err)
  1548. }
  1549. // Rename remote wiki repository to new path and delete local copy.
  1550. wikiPath := WikiPath(owner.Name, repo.Name)
  1551. if com.IsExist(wikiPath) {
  1552. if err = os.Rename(wikiPath, WikiPath(newOwner.Name, repo.Name)); err != nil {
  1553. return fmt.Errorf("rename repository wiki: %v", err)
  1554. }
  1555. }
  1556. // If there was previously a redirect at this location, remove it.
  1557. if err = deleteRepoRedirect(sess, newOwner.ID, repo.Name); err != nil {
  1558. return fmt.Errorf("delete repo redirect: %v", err)
  1559. }
  1560. return sess.Commit()
  1561. }
  1562. // ChangeRepositoryName changes all corresponding setting from old repository name to new one.
  1563. func ChangeRepositoryName(doer *User, repo *Repository, newRepoName string) (err error) {
  1564. newRepoName = strings.ToLower(newRepoName)
  1565. if err = IsUsableRepoName(newRepoName); err != nil {
  1566. return err
  1567. }
  1568. if err := repo.GetOwner(); err != nil {
  1569. return err
  1570. }
  1571. has, err := IsRepositoryExist(repo.Owner, newRepoName)
  1572. if err != nil {
  1573. return fmt.Errorf("IsRepositoryExist: %v", err)
  1574. } else if has {
  1575. return ErrRepoAlreadyExist{repo.Owner.Name, newRepoName}
  1576. }
  1577. // Change repository directory name. We must lock the local copy of the
  1578. // repo so that we can atomically rename the repo path and updates the
  1579. // local copy's origin accordingly.
  1580. repoWorkingPool.CheckIn(com.ToStr(repo.ID))
  1581. defer repoWorkingPool.CheckOut(com.ToStr(repo.ID))
  1582. newRepoPath := RepoPath(repo.Owner.Name, newRepoName)
  1583. if err = os.Rename(repo.RepoPath(), newRepoPath); err != nil {
  1584. return fmt.Errorf("rename repository directory: %v", err)
  1585. }
  1586. wikiPath := repo.WikiPath()
  1587. if com.IsExist(wikiPath) {
  1588. if err = os.Rename(wikiPath, WikiPath(repo.Owner.Name, newRepoName)); err != nil {
  1589. return fmt.Errorf("rename repository wiki: %v", err)
  1590. }
  1591. }
  1592. sess := x.NewSession()
  1593. defer sess.Close()
  1594. if err = sess.Begin(); err != nil {
  1595. return fmt.Errorf("sess.Begin: %v", err)
  1596. }
  1597. // If there was previously a redirect at this location, remove it.
  1598. if err = deleteRepoRedirect(sess, repo.OwnerID, newRepoName); err != nil {
  1599. return fmt.Errorf("delete repo redirect: %v", err)
  1600. }
  1601. return sess.Commit()
  1602. }
  1603. func getRepositoriesByForkID(e Engine, forkID int64) ([]*Repository, error) {
  1604. repos := make([]*Repository, 0, 10)
  1605. return repos, e.
  1606. Where("fork_id=?", forkID).
  1607. Find(&repos)
  1608. }
  1609. // GetRepositoriesByForkID returns all repositories with given fork ID.
  1610. func GetRepositoriesByForkID(forkID int64) ([]*Repository, error) {
  1611. return getRepositoriesByForkID(x, forkID)
  1612. }
  1613. func updateRepository(e Engine, repo *Repository, visibilityChanged bool) (err error) {
  1614. repo.LowerName = strings.ToLower(repo.Name)
  1615. if len(repo.Description) > 255 {
  1616. repo.Description = repo.Description[:255]
  1617. }
  1618. if len(repo.Website) > 255 {
  1619. repo.Website = repo.Website[:255]
  1620. }
  1621. if _, err = e.ID(repo.ID).AllCols().Update(repo); err != nil {
  1622. return fmt.Errorf("update: %v", err)
  1623. }
  1624. if visibilityChanged {
  1625. if err = repo.getOwner(e); err != nil {
  1626. return fmt.Errorf("getOwner: %v", err)
  1627. }
  1628. if repo.Owner.IsOrganization() {
  1629. // Organization repository need to recalculate access table when visibility is changed.
  1630. if err = repo.recalculateTeamAccesses(e, 0); err != nil {
  1631. return fmt.Errorf("recalculateTeamAccesses: %v", err)
  1632. }
  1633. }
  1634. // If repo has become private, we need to set its actions to private.
  1635. if repo.IsPrivate {
  1636. _, err = e.Where("repo_id = ?", repo.ID).Cols("is_private").Update(&Action{
  1637. IsPrivate: true,
  1638. })
  1639. if err != nil {
  1640. return err
  1641. }
  1642. }
  1643. // Create/Remove git-daemon-export-ok for git-daemon...
  1644. daemonExportFile := path.Join(repo.repoPath(e), `git-daemon-export-ok`)
  1645. if repo.IsPrivate && com.IsExist(daemonExportFile) {
  1646. if err = os.Remove(daemonExportFile); err != nil {
  1647. log.Error("Failed to remove %s: %v", daemonExportFile, err)
  1648. }
  1649. } else if !repo.IsPrivate && !com.IsExist(daemonExportFile) {
  1650. if f, err := os.Create(daemonExportFile); err != nil {
  1651. log.Error("Failed to create %s: %v", daemonExportFile, err)
  1652. } else {
  1653. f.Close()
  1654. }
  1655. }
  1656. forkRepos, err := getRepositoriesByForkID(e, repo.ID)
  1657. if err != nil {
  1658. return fmt.Errorf("getRepositoriesByForkID: %v", err)
  1659. }
  1660. for i := range forkRepos {
  1661. forkRepos[i].IsPrivate = repo.IsPrivate
  1662. if err = updateRepository(e, forkRepos[i], true); err != nil {
  1663. return fmt.Errorf("updateRepository[%d]: %v", forkRepos[i].ID, err)
  1664. }
  1665. }
  1666. if err = repo.updateSize(e); err != nil {
  1667. log.Error("Failed to update size for repository: %v", err)
  1668. }
  1669. }
  1670. return nil
  1671. }
  1672. // UpdateRepository updates a repository
  1673. func UpdateRepository(repo *Repository, visibilityChanged bool) (err error) {
  1674. sess := x.NewSession()
  1675. defer sess.Close()
  1676. if err = sess.Begin(); err != nil {
  1677. return err
  1678. }
  1679. if err = updateRepository(sess, repo, visibilityChanged); err != nil {
  1680. return fmt.Errorf("updateRepository: %v", err)
  1681. }
  1682. return sess.Commit()
  1683. }
  1684. // UpdateRepositoryUpdatedTime updates a repository's updated time
  1685. func UpdateRepositoryUpdatedTime(repoID int64, updateTime time.Time) error {
  1686. _, err := x.Exec("UPDATE repository SET updated_unix = ? WHERE id = ?", updateTime.Unix(), repoID)
  1687. return err
  1688. }
  1689. // UpdateRepositoryUnits updates a repository's units
  1690. func UpdateRepositoryUnits(repo *Repository, units []RepoUnit) (err error) {
  1691. sess := x.NewSession()
  1692. defer sess.Close()
  1693. if err = sess.Begin(); err != nil {
  1694. return err
  1695. }
  1696. if _, err = sess.Where("repo_id = ?", repo.ID).Delete(new(RepoUnit)); err != nil {
  1697. return err
  1698. }
  1699. if _, err = sess.Insert(units); err != nil {
  1700. return err
  1701. }
  1702. return sess.Commit()
  1703. }
  1704. // DeleteRepository deletes a repository for a user or organization.
  1705. func DeleteRepository(doer *User, uid, repoID int64) error {
  1706. // In case is a organization.
  1707. org, err := GetUserByID(uid)
  1708. if err != nil {
  1709. return err
  1710. }
  1711. if org.IsOrganization() {
  1712. if err = org.GetTeams(); err != nil {
  1713. return err
  1714. }
  1715. }
  1716. sess := x.NewSession()
  1717. defer sess.Close()
  1718. if err = sess.Begin(); err != nil {
  1719. return err
  1720. }
  1721. repo := &Repository{ID: repoID, OwnerID: uid}
  1722. has, err := sess.Get(repo)
  1723. if err != nil {
  1724. return err
  1725. } else if !has {
  1726. return ErrRepoNotExist{repoID, uid, "", ""}
  1727. }
  1728. // Delete Deploy Keys
  1729. deployKeys, err := listDeployKeys(sess, repo.ID)
  1730. if err != nil {
  1731. return fmt.Errorf("listDeployKeys: %v", err)
  1732. }
  1733. for _, dKey := range deployKeys {
  1734. if err := deleteDeployKey(sess, doer, dKey.ID); err != nil {
  1735. return fmt.Errorf("deleteDeployKeys: %v", err)
  1736. }
  1737. }
  1738. if cnt, err := sess.ID(repoID).Delete(&Repository{}); err != nil {
  1739. return err
  1740. } else if cnt != 1 {
  1741. return ErrRepoNotExist{repoID, uid, "", ""}
  1742. }
  1743. if org.IsOrganization() {
  1744. for _, t := range org.Teams {
  1745. if !t.hasRepository(sess, repoID) {
  1746. continue
  1747. } else if err = t.removeRepository(sess, repo, false); err != nil {
  1748. return err
  1749. }
  1750. }
  1751. }
  1752. if err = deleteBeans(sess,
  1753. &Access{RepoID: repo.ID},
  1754. &Action{RepoID: repo.ID},
  1755. &Watch{RepoID: repoID},
  1756. &Star{RepoID: repoID},
  1757. &Mirror{RepoID: repoID},
  1758. &Milestone{RepoID: repoID},
  1759. &Release{RepoID: repoID},
  1760. &Collaboration{RepoID: repoID},
  1761. &PullRequest{BaseRepoID: repoID},
  1762. &RepoUnit{RepoID: repoID},
  1763. &RepoRedirect{RedirectRepoID: repoID},
  1764. &Webhook{RepoID: repoID},
  1765. &HookTask{RepoID: repoID},
  1766. &Notification{RepoID: repoID},
  1767. &CommitStatus{RepoID: repoID},
  1768. &RepoIndexerStatus{RepoID: repoID},
  1769. &Comment{RefRepoID: repoID},
  1770. &Task{RepoID: repoID},
  1771. ); err != nil {
  1772. return fmt.Errorf("deleteBeans: %v", err)
  1773. }
  1774. deleteCond := builder.Select("id").From("issue").Where(builder.Eq{"repo_id": repoID})
  1775. // Delete comments and attachments
  1776. if _, err = sess.In("issue_id", deleteCond).
  1777. Delete(&Comment{}); err != nil {
  1778. return err
  1779. }
  1780. if _, err = sess.In("issue_id", deleteCond).
  1781. Delete(&IssueUser{}); err != nil {
  1782. return err
  1783. }
  1784. if _, err = sess.In("issue_id", deleteCond).
  1785. Delete(&Reaction{}); err != nil {
  1786. return err
  1787. }
  1788. if _, err = sess.In("issue_id", deleteCond).
  1789. Delete(&IssueWatch{}); err != nil {
  1790. return err
  1791. }
  1792. if _, err = sess.In("issue_id", deleteCond).
  1793. Delete(&Stopwatch{}); err != nil {
  1794. return err
  1795. }
  1796. attachmentPaths := make([]string, 0, 20)
  1797. attachments := make([]*Attachment, 0, len(attachmentPaths))
  1798. if err = sess.Join("INNER", "issue", "issue.id = attachment.issue_id").
  1799. Where("issue.repo_id = ?", repoID).
  1800. Find(&attachments); err != nil {
  1801. return err
  1802. }
  1803. for j := range attachments {
  1804. attachmentPaths = append(attachmentPaths, attachments[j].LocalPath())
  1805. }
  1806. if _, err = sess.In("issue_id", deleteCond).
  1807. Delete(&Attachment{}); err != nil {
  1808. return err
  1809. }
  1810. if _, err = sess.Delete(&Issue{RepoID: repoID}); err != nil {
  1811. return err
  1812. }
  1813. if _, err = sess.Where("repo_id = ?", repoID).Delete(new(RepoUnit)); err != nil {
  1814. return err
  1815. }
  1816. if repo.IsFork {
  1817. if _, err = sess.Exec("UPDATE `repository` SET num_forks=num_forks-1 WHERE id=?", repo.ForkID); err != nil {
  1818. return fmt.Errorf("decrease fork count: %v", err)
  1819. }
  1820. }
  1821. if _, err = sess.Exec("UPDATE `user` SET num_repos=num_repos-1 WHERE id=?", uid); err != nil {
  1822. return err
  1823. }
  1824. // FIXME: Remove repository files should be executed after transaction succeed.
  1825. repoPath := repo.repoPath(sess)
  1826. removeAllWithNotice(sess, "Delete repository files", repoPath)
  1827. err = repo.deleteWiki(sess)
  1828. if err != nil {
  1829. return err
  1830. }
  1831. // Remove attachment files.
  1832. for i := range attachmentPaths {
  1833. removeAllWithNotice(sess, "Delete attachment", attachmentPaths[i])
  1834. }
  1835. // Remove LFS objects
  1836. var lfsObjects []*LFSMetaObject
  1837. if err = sess.Where("repository_id=?", repoID).Find(&lfsObjects); err != nil {
  1838. return err
  1839. }
  1840. for _, v := range lfsObjects {
  1841. count, err := sess.Count(&LFSMetaObject{Oid: v.Oid})
  1842. if err != nil {
  1843. return err
  1844. }
  1845. if count > 1 {
  1846. continue
  1847. }
  1848. oidPath := filepath.Join(setting.LFS.ContentPath, v.Oid[0:2], v.Oid[2:4], v.Oid[4:len(v.Oid)])
  1849. removeAllWithNotice(sess, "Delete orphaned LFS file", oidPath)
  1850. }
  1851. if _, err := sess.Delete(&LFSMetaObject{RepositoryID: repoID}); err != nil {
  1852. return err
  1853. }
  1854. if repo.NumForks > 0 {
  1855. if _, err = sess.Exec("UPDATE `repository` SET fork_id=0,is_fork=? WHERE fork_id=?", false, repo.ID); err != nil {
  1856. log.Error("reset 'fork_id' and 'is_fork': %v", err)
  1857. }
  1858. }
  1859. if err = sess.Commit(); err != nil {
  1860. if len(deployKeys) > 0 {
  1861. // We need to rewrite the public keys because the commit failed
  1862. if err2 := RewriteAllPublicKeys(); err2 != nil {
  1863. return fmt.Errorf("Commit: %v SSH Keys: %v", err, err2)
  1864. }
  1865. }
  1866. return fmt.Errorf("Commit: %v", err)
  1867. }
  1868. if len(repo.Avatar) > 0 {
  1869. avatarPath := repo.CustomAvatarPath()
  1870. if com.IsExist(avatarPath) {
  1871. if err := os.Remove(avatarPath); err != nil {
  1872. return fmt.Errorf("Failed to remove %s: %v", avatarPath, err)
  1873. }
  1874. }
  1875. }
  1876. return nil
  1877. }
  1878. // GetRepositoryByOwnerAndName returns the repository by given ownername and reponame.
  1879. func GetRepositoryByOwnerAndName(ownerName, repoName string) (*Repository, error) {
  1880. return getRepositoryByOwnerAndName(x, ownerName, repoName)
  1881. }
  1882. func getRepositoryByOwnerAndName(e Engine, ownerName, repoName string) (*Repository, error) {
  1883. var repo Repository
  1884. has, err := e.Table("repository").Select("repository.*").
  1885. Join("INNER", "`user`", "`user`.id = repository.owner_id").
  1886. Where("repository.lower_name = ?", strings.ToLower(repoName)).
  1887. And("`user`.lower_name = ?", strings.ToLower(ownerName)).
  1888. Get(&repo)
  1889. if err != nil {
  1890. return nil, err
  1891. } else if !has {
  1892. return nil, ErrRepoNotExist{0, 0, ownerName, repoName}
  1893. }
  1894. return &repo, nil
  1895. }
  1896. // GetRepositoryByName returns the repository by given name under user if exists.
  1897. func GetRepositoryByName(ownerID int64, name string) (*Repository, error) {
  1898. repo := &Repository{
  1899. OwnerID: ownerID,
  1900. LowerName: strings.ToLower(name),
  1901. }
  1902. has, err := x.Get(repo)
  1903. if err != nil {
  1904. return nil, err
  1905. } else if !has {
  1906. return nil, ErrRepoNotExist{0, ownerID, "", name}
  1907. }
  1908. return repo, err
  1909. }
  1910. func getRepositoryByID(e Engine, id int64) (*Repository, error) {
  1911. repo := new(Repository)
  1912. has, err := e.ID(id).Get(repo)
  1913. if err != nil {
  1914. return nil, err
  1915. } else if !has {
  1916. return nil, ErrRepoNotExist{id, 0, "", ""}
  1917. }
  1918. return repo, nil
  1919. }
  1920. // GetRepositoryByID returns the repository by given id if exists.
  1921. func GetRepositoryByID(id int64) (*Repository, error) {
  1922. return getRepositoryByID(x, id)
  1923. }
  1924. // GetRepositoriesMapByIDs returns the repositories by given id slice.
  1925. func GetRepositoriesMapByIDs(ids []int64) (map[int64]*Repository, error) {
  1926. var repos = make(map[int64]*Repository, len(ids))
  1927. return repos, x.In("id", ids).Find(&repos)
  1928. }
  1929. // GetUserRepositories returns a list of repositories of given user.
  1930. func GetUserRepositories(userID int64, private bool, page, pageSize int, orderBy string) ([]*Repository, error) {
  1931. if len(orderBy) == 0 {
  1932. orderBy = "updated_unix DESC"
  1933. }
  1934. sess := x.
  1935. Where("owner_id = ?", userID).
  1936. OrderBy(orderBy)
  1937. if !private {
  1938. sess.And("is_private=?", false)
  1939. }
  1940. if page <= 0 {
  1941. page = 1
  1942. }
  1943. sess.Limit(pageSize, (page-1)*pageSize)
  1944. repos := make([]*Repository, 0, pageSize)
  1945. return repos, sess.Find(&repos)
  1946. }
  1947. // GetUserMirrorRepositories returns a list of mirror repositories of given user.
  1948. func GetUserMirrorRepositories(userID int64) ([]*Repository, error) {
  1949. repos := make([]*Repository, 0, 10)
  1950. return repos, x.
  1951. Where("owner_id = ?", userID).
  1952. And("is_mirror = ?", true).
  1953. Find(&repos)
  1954. }
  1955. func getRepositoryCount(e Engine, u *User) (int64, error) {
  1956. return e.Count(&Repository{OwnerID: u.ID})
  1957. }
  1958. func getPublicRepositoryCount(e Engine, u *User) (int64, error) {
  1959. return e.Where("is_private = ?", false).Count(&Repository{OwnerID: u.ID})
  1960. }
  1961. func getPrivateRepositoryCount(e Engine, u *User) (int64, error) {
  1962. return e.Where("is_private = ?", true).Count(&Repository{OwnerID: u.ID})
  1963. }
  1964. // GetRepositoryCount returns the total number of repositories of user.
  1965. func GetRepositoryCount(u *User) (int64, error) {
  1966. return getRepositoryCount(x, u)
  1967. }
  1968. // GetPublicRepositoryCount returns the total number of public repositories of user.
  1969. func GetPublicRepositoryCount(u *User) (int64, error) {
  1970. return getPublicRepositoryCount(x, u)
  1971. }
  1972. // GetPrivateRepositoryCount returns the total number of private repositories of user.
  1973. func GetPrivateRepositoryCount(u *User) (int64, error) {
  1974. return getPrivateRepositoryCount(x, u)
  1975. }
  1976. // DeleteRepositoryArchives deletes all repositories' archives.
  1977. func DeleteRepositoryArchives() error {
  1978. return x.
  1979. Where("id > 0").
  1980. Iterate(new(Repository),
  1981. func(idx int, bean interface{}) error {
  1982. repo := bean.(*Repository)
  1983. return os.RemoveAll(filepath.Join(repo.RepoPath(), "archives"))
  1984. })
  1985. }
  1986. // DeleteOldRepositoryArchives deletes old repository archives.
  1987. func DeleteOldRepositoryArchives() {
  1988. log.Trace("Doing: ArchiveCleanup")
  1989. if err := x.Where("id > 0").Iterate(new(Repository), deleteOldRepositoryArchives); err != nil {
  1990. log.Error("ArchiveClean: %v", err)
  1991. }
  1992. }
  1993. func deleteOldRepositoryArchives(idx int, bean interface{}) error {
  1994. repo := bean.(*Repository)
  1995. basePath := filepath.Join(repo.RepoPath(), "archives")
  1996. for _, ty := range []string{"zip", "targz"} {
  1997. path := filepath.Join(basePath, ty)
  1998. file, err := os.Open(path)
  1999. if err != nil {
  2000. if !os.IsNotExist(err) {
  2001. log.Warn("Unable to open directory %s: %v", path, err)
  2002. return err
  2003. }
  2004. // If the directory doesn't exist, that's okay.
  2005. continue
  2006. }
  2007. files, err := file.Readdir(0)
  2008. file.Close()
  2009. if err != nil {
  2010. log.Warn("Unable to read directory %s: %v", path, err)
  2011. return err
  2012. }
  2013. minimumOldestTime := time.Now().Add(-setting.Cron.ArchiveCleanup.OlderThan)
  2014. for _, info := range files {
  2015. if info.ModTime().Before(minimumOldestTime) && !info.IsDir() {
  2016. toDelete := filepath.Join(path, info.Name())
  2017. // This is a best-effort purge, so we do not check error codes to confirm removal.
  2018. if err = os.Remove(toDelete); err != nil {
  2019. log.Trace("Unable to delete %s, but proceeding: %v", toDelete, err)
  2020. }
  2021. }
  2022. }
  2023. }
  2024. return nil
  2025. }
  2026. func gatherMissingRepoRecords() ([]*Repository, error) {
  2027. repos := make([]*Repository, 0, 10)
  2028. if err := x.
  2029. Where("id > 0").
  2030. Iterate(new(Repository),
  2031. func(idx int, bean interface{}) error {
  2032. repo := bean.(*Repository)
  2033. if !com.IsDir(repo.RepoPath()) {
  2034. repos = append(repos, repo)
  2035. }
  2036. return nil
  2037. }); err != nil {
  2038. if err2 := CreateRepositoryNotice(fmt.Sprintf("gatherMissingRepoRecords: %v", err)); err2 != nil {
  2039. return nil, fmt.Errorf("CreateRepositoryNotice: %v", err)
  2040. }
  2041. }
  2042. return repos, nil
  2043. }
  2044. // DeleteMissingRepositories deletes all repository records that lost Git files.
  2045. func DeleteMissingRepositories(doer *User) error {
  2046. repos, err := gatherMissingRepoRecords()
  2047. if err != nil {
  2048. return fmt.Errorf("gatherMissingRepoRecords: %v", err)
  2049. }
  2050. if len(repos) == 0 {
  2051. return nil
  2052. }
  2053. for _, repo := range repos {
  2054. log.Trace("Deleting %d/%d...", repo.OwnerID, repo.ID)
  2055. if err := DeleteRepository(doer, repo.OwnerID, repo.ID); err != nil {
  2056. if err2 := CreateRepositoryNotice(fmt.Sprintf("DeleteRepository [%d]: %v", repo.ID, err)); err2 != nil {
  2057. return fmt.Errorf("CreateRepositoryNotice: %v", err)
  2058. }
  2059. }
  2060. }
  2061. return nil
  2062. }
  2063. // ReinitMissingRepositories reinitializes all repository records that lost Git files.
  2064. func ReinitMissingRepositories() error {
  2065. repos, err := gatherMissingRepoRecords()
  2066. if err != nil {
  2067. return fmt.Errorf("gatherMissingRepoRecords: %v", err)
  2068. }
  2069. if len(repos) == 0 {
  2070. return nil
  2071. }
  2072. for _, repo := range repos {
  2073. log.Trace("Initializing %d/%d...", repo.OwnerID, repo.ID)
  2074. if err := git.InitRepository(repo.RepoPath(), true); err != nil {
  2075. if err2 := CreateRepositoryNotice(fmt.Sprintf("InitRepository [%d]: %v", repo.ID, err)); err2 != nil {
  2076. return fmt.Errorf("CreateRepositoryNotice: %v", err)
  2077. }
  2078. }
  2079. }
  2080. return nil
  2081. }
  2082. // SyncRepositoryHooks rewrites all repositories' pre-receive, update and post-receive hooks
  2083. // to make sure the binary and custom conf path are up-to-date.
  2084. func SyncRepositoryHooks() error {
  2085. return x.Cols("owner_id", "name").Where("id > 0").Iterate(new(Repository),
  2086. func(idx int, bean interface{}) error {
  2087. if err := createDelegateHooks(bean.(*Repository).RepoPath()); err != nil {
  2088. return fmt.Errorf("SyncRepositoryHook: %v", err)
  2089. }
  2090. if bean.(*Repository).HasWiki() {
  2091. if err := createDelegateHooks(bean.(*Repository).WikiPath()); err != nil {
  2092. return fmt.Errorf("SyncRepositoryHook: %v", err)
  2093. }
  2094. }
  2095. return nil
  2096. })
  2097. }
  2098. // GitFsck calls 'git fsck' to check repository health.
  2099. func GitFsck() {
  2100. log.Trace("Doing: GitFsck")
  2101. if err := x.
  2102. Where("id>0 AND is_fsck_enabled=?", true).BufferSize(setting.Database.IterateBufferSize).
  2103. Iterate(new(Repository),
  2104. func(idx int, bean interface{}) error {
  2105. repo := bean.(*Repository)
  2106. repoPath := repo.RepoPath()
  2107. log.Trace("Running health check on repository %s", repoPath)
  2108. if err := git.Fsck(repoPath, setting.Cron.RepoHealthCheck.Timeout, setting.Cron.RepoHealthCheck.Args...); err != nil {
  2109. desc := fmt.Sprintf("Failed to health check repository (%s): %v", repoPath, err)
  2110. log.Warn(desc)
  2111. if err = CreateRepositoryNotice(desc); err != nil {
  2112. log.Error("CreateRepositoryNotice: %v", err)
  2113. }
  2114. }
  2115. return nil
  2116. }); err != nil {
  2117. log.Error("GitFsck: %v", err)
  2118. }
  2119. log.Trace("Finished: GitFsck")
  2120. }
  2121. // GitGcRepos calls 'git gc' to remove unnecessary files and optimize the local repository
  2122. func GitGcRepos() error {
  2123. args := append([]string{"gc"}, setting.Git.GCArgs...)
  2124. return x.
  2125. Where("id > 0").BufferSize(setting.Database.IterateBufferSize).
  2126. Iterate(new(Repository),
  2127. func(idx int, bean interface{}) error {
  2128. repo := bean.(*Repository)
  2129. if err := repo.GetOwner(); err != nil {
  2130. return err
  2131. }
  2132. _, stderr, err := process.GetManager().ExecDir(
  2133. time.Duration(setting.Git.Timeout.GC)*time.Second,
  2134. RepoPath(repo.Owner.Name, repo.Name), "Repository garbage collection",
  2135. git.GitExecutable, args...)
  2136. if err != nil {
  2137. return fmt.Errorf("%v: %v", err, stderr)
  2138. }
  2139. return nil
  2140. })
  2141. }
  2142. type repoChecker struct {
  2143. querySQL, correctSQL string
  2144. desc string
  2145. }
  2146. func repoStatsCheck(checker *repoChecker) {
  2147. results, err := x.Query(checker.querySQL)
  2148. if err != nil {
  2149. log.Error("Select %s: %v", checker.desc, err)
  2150. return
  2151. }
  2152. for _, result := range results {
  2153. id := com.StrTo(result["id"]).MustInt64()
  2154. log.Trace("Updating %s: %d", checker.desc, id)
  2155. _, err = x.Exec(checker.correctSQL, id, id)
  2156. if err != nil {
  2157. log.Error("Update %s[%d]: %v", checker.desc, id, err)
  2158. }
  2159. }
  2160. }
  2161. // CheckRepoStats checks the repository stats
  2162. func CheckRepoStats() {
  2163. log.Trace("Doing: CheckRepoStats")
  2164. checkers := []*repoChecker{
  2165. // Repository.NumWatches
  2166. {
  2167. "SELECT repo.id FROM `repository` repo WHERE repo.num_watches!=(SELECT COUNT(*) FROM `watch` WHERE repo_id=repo.id AND mode<>2)",
  2168. "UPDATE `repository` SET num_watches=(SELECT COUNT(*) FROM `watch` WHERE repo_id=? AND mode<>2) WHERE id=?",
  2169. "repository count 'num_watches'",
  2170. },
  2171. // Repository.NumStars
  2172. {
  2173. "SELECT repo.id FROM `repository` repo WHERE repo.num_stars!=(SELECT COUNT(*) FROM `star` WHERE repo_id=repo.id)",
  2174. "UPDATE `repository` SET num_stars=(SELECT COUNT(*) FROM `star` WHERE repo_id=?) WHERE id=?",
  2175. "repository count 'num_stars'",
  2176. },
  2177. // Label.NumIssues
  2178. {
  2179. "SELECT label.id FROM `label` WHERE label.num_issues!=(SELECT COUNT(*) FROM `issue_label` WHERE label_id=label.id)",
  2180. "UPDATE `label` SET num_issues=(SELECT COUNT(*) FROM `issue_label` WHERE label_id=?) WHERE id=?",
  2181. "label count 'num_issues'",
  2182. },
  2183. // User.NumRepos
  2184. {
  2185. "SELECT `user`.id FROM `user` WHERE `user`.num_repos!=(SELECT COUNT(*) FROM `repository` WHERE owner_id=`user`.id)",
  2186. "UPDATE `user` SET num_repos=(SELECT COUNT(*) FROM `repository` WHERE owner_id=?) WHERE id=?",
  2187. "user count 'num_repos'",
  2188. },
  2189. // Issue.NumComments
  2190. {
  2191. "SELECT `issue`.id FROM `issue` WHERE `issue`.num_comments!=(SELECT COUNT(*) FROM `comment` WHERE issue_id=`issue`.id AND type=0)",
  2192. "UPDATE `issue` SET num_comments=(SELECT COUNT(*) FROM `comment` WHERE issue_id=? AND type=0) WHERE id=?",
  2193. "issue count 'num_comments'",
  2194. },
  2195. }
  2196. for i := range checkers {
  2197. repoStatsCheck(checkers[i])
  2198. }
  2199. // ***** START: Repository.NumClosedIssues *****
  2200. desc := "repository count 'num_closed_issues'"
  2201. results, err := x.Query("SELECT repo.id FROM `repository` repo WHERE repo.num_closed_issues!=(SELECT COUNT(*) FROM `issue` WHERE repo_id=repo.id AND is_closed=? AND is_pull=?)", true, false)
  2202. if err != nil {
  2203. log.Error("Select %s: %v", desc, err)
  2204. } else {
  2205. for _, result := range results {
  2206. id := com.StrTo(result["id"]).MustInt64()
  2207. log.Trace("Updating %s: %d", desc, id)
  2208. _, err = x.Exec("UPDATE `repository` SET num_closed_issues=(SELECT COUNT(*) FROM `issue` WHERE repo_id=? AND is_closed=? AND is_pull=?) WHERE id=?", id, true, false, id)
  2209. if err != nil {
  2210. log.Error("Update %s[%d]: %v", desc, id, err)
  2211. }
  2212. }
  2213. }
  2214. // ***** END: Repository.NumClosedIssues *****
  2215. // ***** START: Repository.NumClosedPulls *****
  2216. desc = "repository count 'num_closed_pulls'"
  2217. results, err = x.Query("SELECT repo.id FROM `repository` repo WHERE repo.num_closed_pulls!=(SELECT COUNT(*) FROM `issue` WHERE repo_id=repo.id AND is_closed=? AND is_pull=?)", true, true)
  2218. if err != nil {
  2219. log.Error("Select %s: %v", desc, err)
  2220. } else {
  2221. for _, result := range results {
  2222. id := com.StrTo(result["id"]).MustInt64()
  2223. log.Trace("Updating %s: %d", desc, id)
  2224. _, err = x.Exec("UPDATE `repository` SET num_closed_pulls=(SELECT COUNT(*) FROM `issue` WHERE repo_id=? AND is_closed=? AND is_pull=?) WHERE id=?", id, true, true, id)
  2225. if err != nil {
  2226. log.Error("Update %s[%d]: %v", desc, id, err)
  2227. }
  2228. }
  2229. }
  2230. // ***** END: Repository.NumClosedPulls *****
  2231. // FIXME: use checker when stop supporting old fork repo format.
  2232. // ***** START: Repository.NumForks *****
  2233. results, err = x.Query("SELECT repo.id FROM `repository` repo WHERE repo.num_forks!=(SELECT COUNT(*) FROM `repository` WHERE fork_id=repo.id)")
  2234. if err != nil {
  2235. log.Error("Select repository count 'num_forks': %v", err)
  2236. } else {
  2237. for _, result := range results {
  2238. id := com.StrTo(result["id"]).MustInt64()
  2239. log.Trace("Updating repository count 'num_forks': %d", id)
  2240. repo, err := GetRepositoryByID(id)
  2241. if err != nil {
  2242. log.Error("GetRepositoryByID[%d]: %v", id, err)
  2243. continue
  2244. }
  2245. rawResult, err := x.Query("SELECT COUNT(*) FROM `repository` WHERE fork_id=?", repo.ID)
  2246. if err != nil {
  2247. log.Error("Select count of forks[%d]: %v", repo.ID, err)
  2248. continue
  2249. }
  2250. repo.NumForks = int(parseCountResult(rawResult))
  2251. if err = UpdateRepository(repo, false); err != nil {
  2252. log.Error("UpdateRepository[%d]: %v", id, err)
  2253. continue
  2254. }
  2255. }
  2256. }
  2257. // ***** END: Repository.NumForks *****
  2258. }
  2259. // SetArchiveRepoState sets if a repo is archived
  2260. func (repo *Repository) SetArchiveRepoState(isArchived bool) (err error) {
  2261. repo.IsArchived = isArchived
  2262. _, err = x.Where("id = ?", repo.ID).Cols("is_archived").Update(repo)
  2263. return
  2264. }
  2265. // ___________ __
  2266. // \_ _____/__________| | __
  2267. // | __)/ _ \_ __ \ |/ /
  2268. // | \( <_> ) | \/ <
  2269. // \___ / \____/|__| |__|_ \
  2270. // \/ \/
  2271. // HasForkedRepo checks if given user has already forked a repository with given ID.
  2272. func HasForkedRepo(ownerID, repoID int64) (*Repository, bool) {
  2273. repo := new(Repository)
  2274. has, _ := x.
  2275. Where("owner_id=? AND fork_id=?", ownerID, repoID).
  2276. Get(repo)
  2277. return repo, has
  2278. }
  2279. // CopyLFS copies LFS data from one repo to another
  2280. func CopyLFS(newRepo, oldRepo *Repository) error {
  2281. return copyLFS(x, newRepo, oldRepo)
  2282. }
  2283. func copyLFS(e Engine, newRepo, oldRepo *Repository) error {
  2284. var lfsObjects []*LFSMetaObject
  2285. if err := e.Where("repository_id=?", oldRepo.ID).Find(&lfsObjects); err != nil {
  2286. return err
  2287. }
  2288. for _, v := range lfsObjects {
  2289. v.ID = 0
  2290. v.RepositoryID = newRepo.ID
  2291. if _, err := e.Insert(v); err != nil {
  2292. return err
  2293. }
  2294. }
  2295. return nil
  2296. }
  2297. // ForkRepository forks a repository
  2298. func ForkRepository(doer, owner *User, oldRepo *Repository, name, desc string) (_ *Repository, err error) {
  2299. forkedRepo, err := oldRepo.GetUserFork(owner.ID)
  2300. if err != nil {
  2301. return nil, err
  2302. }
  2303. if forkedRepo != nil {
  2304. return nil, ErrForkAlreadyExist{
  2305. Uname: owner.Name,
  2306. RepoName: oldRepo.FullName(),
  2307. ForkName: forkedRepo.FullName(),
  2308. }
  2309. }
  2310. repo := &Repository{
  2311. OwnerID: owner.ID,
  2312. Owner: owner,
  2313. Name: name,
  2314. LowerName: strings.ToLower(name),
  2315. Description: desc,
  2316. DefaultBranch: oldRepo.DefaultBranch,
  2317. IsPrivate: oldRepo.IsPrivate,
  2318. IsEmpty: oldRepo.IsEmpty,
  2319. IsFork: true,
  2320. ForkID: oldRepo.ID,
  2321. }
  2322. sess := x.NewSession()
  2323. defer sess.Close()
  2324. if err = sess.Begin(); err != nil {
  2325. return nil, err
  2326. }
  2327. if err = createRepository(sess, doer, owner, repo); err != nil {
  2328. return nil, err
  2329. }
  2330. if _, err = sess.Exec("UPDATE `repository` SET num_forks=num_forks+1 WHERE id=?", oldRepo.ID); err != nil {
  2331. return nil, err
  2332. }
  2333. repoPath := RepoPath(owner.Name, repo.Name)
  2334. _, stderr, err := process.GetManager().ExecTimeout(10*time.Minute,
  2335. fmt.Sprintf("ForkRepository(git clone): %s/%s", owner.Name, repo.Name),
  2336. git.GitExecutable, "clone", "--bare", oldRepo.repoPath(sess), repoPath)
  2337. if err != nil {
  2338. return nil, fmt.Errorf("git clone: %v", stderr)
  2339. }
  2340. _, stderr, err = process.GetManager().ExecDir(-1,
  2341. repoPath, fmt.Sprintf("ForkRepository(git update-server-info): %s", repoPath),
  2342. git.GitExecutable, "update-server-info")
  2343. if err != nil {
  2344. return nil, fmt.Errorf("git update-server-info: %v", stderr)
  2345. }
  2346. if err = createDelegateHooks(repoPath); err != nil {
  2347. return nil, fmt.Errorf("createDelegateHooks: %v", err)
  2348. }
  2349. //Commit repo to get Fork ID
  2350. err = sess.Commit()
  2351. if err != nil {
  2352. return nil, err
  2353. }
  2354. if err = repo.UpdateSize(); err != nil {
  2355. log.Error("Failed to update size for repository: %v", err)
  2356. }
  2357. return repo, CopyLFS(repo, oldRepo)
  2358. }
  2359. // GenerateRepository generates a repository from a template
  2360. func GenerateRepository(doer, owner *User, templateRepo *Repository, opts GenerateRepoOptions) (_ *Repository, err error) {
  2361. repo := &Repository{
  2362. OwnerID: owner.ID,
  2363. Owner: owner,
  2364. Name: opts.Name,
  2365. LowerName: strings.ToLower(opts.Name),
  2366. Description: opts.Description,
  2367. IsPrivate: opts.Private,
  2368. IsEmpty: !opts.GitContent || templateRepo.IsEmpty,
  2369. IsFsckEnabled: templateRepo.IsFsckEnabled,
  2370. TemplateID: templateRepo.ID,
  2371. }
  2372. createSess := x.NewSession()
  2373. defer createSess.Close()
  2374. if err = createSess.Begin(); err != nil {
  2375. return nil, err
  2376. }
  2377. if err = createRepository(createSess, doer, owner, repo); err != nil {
  2378. return nil, err
  2379. }
  2380. //Commit repo to get created repo ID
  2381. err = createSess.Commit()
  2382. if err != nil {
  2383. return nil, err
  2384. }
  2385. sess := x.NewSession()
  2386. defer sess.Close()
  2387. if err = sess.Begin(); err != nil {
  2388. return repo, err
  2389. }
  2390. repoPath := RepoPath(owner.Name, repo.Name)
  2391. if err = checkInitRepository(repoPath); err != nil {
  2392. return repo, err
  2393. }
  2394. if opts.GitContent && !templateRepo.IsEmpty {
  2395. if err = generateRepository(sess, repo, templateRepo); err != nil {
  2396. return repo, err
  2397. }
  2398. if err = repo.updateSize(sess); err != nil {
  2399. return repo, fmt.Errorf("failed to update size for repository: %v", err)
  2400. }
  2401. if err = copyLFS(sess, repo, templateRepo); err != nil {
  2402. return repo, fmt.Errorf("failed to copy LFS: %v", err)
  2403. }
  2404. }
  2405. if opts.Topics {
  2406. for _, topic := range templateRepo.Topics {
  2407. if _, err = addTopicByNameToRepo(sess, repo.ID, topic); err != nil {
  2408. return repo, err
  2409. }
  2410. }
  2411. }
  2412. return repo, sess.Commit()
  2413. }
  2414. // GetForks returns all the forks of the repository
  2415. func (repo *Repository) GetForks() ([]*Repository, error) {
  2416. forks := make([]*Repository, 0, repo.NumForks)
  2417. return forks, x.Find(&forks, &Repository{ForkID: repo.ID})
  2418. }
  2419. // GetUserFork return user forked repository from this repository, if not forked return nil
  2420. func (repo *Repository) GetUserFork(userID int64) (*Repository, error) {
  2421. var forkedRepo Repository
  2422. has, err := x.Where("fork_id = ?", repo.ID).And("owner_id = ?", userID).Get(&forkedRepo)
  2423. if err != nil {
  2424. return nil, err
  2425. }
  2426. if !has {
  2427. return nil, nil
  2428. }
  2429. return &forkedRepo, nil
  2430. }
  2431. // CustomAvatarPath returns repository custom avatar file path.
  2432. func (repo *Repository) CustomAvatarPath() string {
  2433. // Avatar empty by default
  2434. if len(repo.Avatar) == 0 {
  2435. return ""
  2436. }
  2437. return filepath.Join(setting.RepositoryAvatarUploadPath, repo.Avatar)
  2438. }
  2439. // generateRandomAvatar generates a random avatar for repository.
  2440. func (repo *Repository) generateRandomAvatar(e Engine) error {
  2441. idToString := fmt.Sprintf("%d", repo.ID)
  2442. seed := idToString
  2443. img, err := avatar.RandomImage([]byte(seed))
  2444. if err != nil {
  2445. return fmt.Errorf("RandomImage: %v", err)
  2446. }
  2447. repo.Avatar = idToString
  2448. if err = os.MkdirAll(filepath.Dir(repo.CustomAvatarPath()), os.ModePerm); err != nil {
  2449. return fmt.Errorf("MkdirAll: %v", err)
  2450. }
  2451. fw, err := os.Create(repo.CustomAvatarPath())
  2452. if err != nil {
  2453. return fmt.Errorf("Create: %v", err)
  2454. }
  2455. defer fw.Close()
  2456. if err = png.Encode(fw, img); err != nil {
  2457. return fmt.Errorf("Encode: %v", err)
  2458. }
  2459. log.Info("New random avatar created for repository: %d", repo.ID)
  2460. if _, err := e.ID(repo.ID).Cols("avatar").NoAutoTime().Update(repo); err != nil {
  2461. return err
  2462. }
  2463. return nil
  2464. }
  2465. // RemoveRandomAvatars removes the randomly generated avatars that were created for repositories
  2466. func RemoveRandomAvatars() error {
  2467. return x.
  2468. Where("id > 0").BufferSize(setting.Database.IterateBufferSize).
  2469. Iterate(new(Repository),
  2470. func(idx int, bean interface{}) error {
  2471. repository := bean.(*Repository)
  2472. stringifiedID := strconv.FormatInt(repository.ID, 10)
  2473. if repository.Avatar == stringifiedID {
  2474. return repository.DeleteAvatar()
  2475. }
  2476. return nil
  2477. })
  2478. }
  2479. // RelAvatarLink returns a relative link to the repository's avatar.
  2480. func (repo *Repository) RelAvatarLink() string {
  2481. return repo.relAvatarLink(x)
  2482. }
  2483. func (repo *Repository) relAvatarLink(e Engine) string {
  2484. // If no avatar - path is empty
  2485. avatarPath := repo.CustomAvatarPath()
  2486. if len(avatarPath) == 0 || !com.IsFile(avatarPath) {
  2487. switch mode := setting.RepositoryAvatarFallback; mode {
  2488. case "image":
  2489. return setting.RepositoryAvatarFallbackImage
  2490. case "random":
  2491. if err := repo.generateRandomAvatar(e); err != nil {
  2492. log.Error("generateRandomAvatar: %v", err)
  2493. }
  2494. default:
  2495. // default behaviour: do not display avatar
  2496. return ""
  2497. }
  2498. }
  2499. return setting.AppSubURL + "/repo-avatars/" + repo.Avatar
  2500. }
  2501. // avatarLink returns user avatar absolute link.
  2502. func (repo *Repository) avatarLink(e Engine) string {
  2503. link := repo.relAvatarLink(e)
  2504. // link may be empty!
  2505. if len(link) > 0 {
  2506. if link[0] == '/' && link[1] != '/' {
  2507. return setting.AppURL + strings.TrimPrefix(link, setting.AppSubURL)[1:]
  2508. }
  2509. }
  2510. return link
  2511. }
  2512. // UploadAvatar saves custom avatar for repository.
  2513. // FIXME: split uploads to different subdirs in case we have massive number of repos.
  2514. func (repo *Repository) UploadAvatar(data []byte) error {
  2515. m, err := avatar.Prepare(data)
  2516. if err != nil {
  2517. return err
  2518. }
  2519. sess := x.NewSession()
  2520. defer sess.Close()
  2521. if err = sess.Begin(); err != nil {
  2522. return err
  2523. }
  2524. oldAvatarPath := repo.CustomAvatarPath()
  2525. // Users can upload the same image to other repo - prefix it with ID
  2526. // Then repo will be removed - only it avatar file will be removed
  2527. repo.Avatar = fmt.Sprintf("%d-%x", repo.ID, md5.Sum(data))
  2528. if _, err := sess.ID(repo.ID).Cols("avatar").Update(repo); err != nil {
  2529. return fmt.Errorf("UploadAvatar: Update repository avatar: %v", err)
  2530. }
  2531. if err := os.MkdirAll(setting.RepositoryAvatarUploadPath, os.ModePerm); err != nil {
  2532. return fmt.Errorf("UploadAvatar: Failed to create dir %s: %v", setting.RepositoryAvatarUploadPath, err)
  2533. }
  2534. fw, err := os.Create(repo.CustomAvatarPath())
  2535. if err != nil {
  2536. return fmt.Errorf("UploadAvatar: Create file: %v", err)
  2537. }
  2538. defer fw.Close()
  2539. if err = png.Encode(fw, *m); err != nil {
  2540. return fmt.Errorf("UploadAvatar: Encode png: %v", err)
  2541. }
  2542. if len(oldAvatarPath) > 0 && oldAvatarPath != repo.CustomAvatarPath() {
  2543. if err := os.Remove(oldAvatarPath); err != nil {
  2544. return fmt.Errorf("UploadAvatar: Failed to remove old repo avatar %s: %v", oldAvatarPath, err)
  2545. }
  2546. }
  2547. return sess.Commit()
  2548. }
  2549. // DeleteAvatar deletes the repos's custom avatar.
  2550. func (repo *Repository) DeleteAvatar() error {
  2551. // Avatar not exists
  2552. if len(repo.Avatar) == 0 {
  2553. return nil
  2554. }
  2555. avatarPath := repo.CustomAvatarPath()
  2556. log.Trace("DeleteAvatar[%d]: %s", repo.ID, avatarPath)
  2557. sess := x.NewSession()
  2558. defer sess.Close()
  2559. if err := sess.Begin(); err != nil {
  2560. return err
  2561. }
  2562. repo.Avatar = ""
  2563. if _, err := sess.ID(repo.ID).Cols("avatar").Update(repo); err != nil {
  2564. return fmt.Errorf("DeleteAvatar: Update repository avatar: %v", err)
  2565. }
  2566. if _, err := os.Stat(avatarPath); err == nil {
  2567. if err := os.Remove(avatarPath); err != nil {
  2568. return fmt.Errorf("DeleteAvatar: Failed to remove %s: %v", avatarPath, err)
  2569. }
  2570. } else {
  2571. // // Schrodinger: file may or may not exist. See err for details.
  2572. log.Trace("DeleteAvatar[%d]: %v", err)
  2573. }
  2574. return sess.Commit()
  2575. }
  2576. // GetOriginalURLHostname returns the hostname of a URL or the URL
  2577. func (repo *Repository) GetOriginalURLHostname() string {
  2578. u, err := url.Parse(repo.OriginalURL)
  2579. if err != nil {
  2580. return repo.OriginalURL
  2581. }
  2582. return u.Host
  2583. }
  2584. // GetTreePathLock returns LSF lock for the treePath
  2585. func (repo *Repository) GetTreePathLock(treePath string) (*LFSLock, error) {
  2586. if setting.LFS.StartServer {
  2587. locks, err := GetLFSLockByRepoID(repo.ID)
  2588. if err != nil {
  2589. return nil, err
  2590. }
  2591. for _, lock := range locks {
  2592. if lock.Path == treePath {
  2593. return lock, nil
  2594. }
  2595. }
  2596. }
  2597. return nil, nil
  2598. }
  2599. // UpdateRepositoryCols updates repository's columns
  2600. func UpdateRepositoryCols(repo *Repository, cols ...string) error {
  2601. _, err := x.ID(repo.ID).Cols(cols...).Update(repo)
  2602. return err
  2603. }