Commit Graph
38 Commits
Author SHA1 Message Date
Lunny XiaoandGitHub 4a57c9ea17 Fix some lints (#17337)
Fix some linting problems.
2021-10-17 20:47:12 +01:00
bb39359668 Add a simple way to rename branch like gh (#15870)
- Update default branch if needed
- Update protected branch if needed
- Update all not merged pull request base branch name
- Rename git branch
- Record this rename work and auto redirect for old branch on ui

Signed-off-by: a1012112796 <[email protected]>
Co-authored-by: delvh <[email protected]>
2021-10-08 19:03:04 +02:00
zeripathandGitHub 9302eba971 DBContext is just a Context (#17100)
* DBContext is just a Context

This PR removes some of the specialness from the DBContext and makes it context
This allows us to simplify the GetEngine code to wrap around any context in future
and means that we can change our loadRepo(e Engine) functions to simply take contexts.

Signed-off-by: Andrew Thornton <[email protected]>

* fix unit tests

Signed-off-by: Andrew Thornton <[email protected]>

* another place that needs to set the initial context

Signed-off-by: Andrew Thornton <[email protected]>

* avoid race

Signed-off-by: Andrew Thornton <[email protected]>

* change attachment error

Signed-off-by: Andrew Thornton <[email protected]>
2021-09-23 23:45:36 +08:00
a4bfef265d Move db related basic functions to models/db (#17075)
* Move db related basic functions to models/db

* Fix lint

* Fix lint

* Fix test

* Fix lint

* Fix lint

* revert unnecessary change

* Fix test

* Fix wrong replace string

* Use *Context

* Correct committer spelling and fix wrong replaced words

Co-authored-by: zeripath <[email protected]>
2021-09-19 19:49:59 +08:00
Kyle EvansandGitHub cad70599a6 Refactor the fork service slightly to take ForkRepoOptions (#16744)
* Refactor the fork service slightly to take ForkRepoOptions

This reduces the number of places we need to change if we want to add other
options during fork time.

Signed-off-by: Kyle Evans <[email protected]>

* Fix integrations and tests after ForkRepository refactor

Signed-off-by: Kyle Evans <[email protected]>

* Update OldRepo -> BaseRepo

Signed-off-by: Kyle Evans <[email protected]>

* gofmt pass

Signed-off-by: Kyle Evans <[email protected]>
2021-08-28 16:37:14 +08:00
d9ef43a712 Replace list.List with slices (#16311)
* Replaced list with slice.

* Fixed usage of pointer to temporary variable.

* Replaced LIFO list with slice.

* Lint

* Removed type check.

* Removed duplicated code.

* Lint

* Fixed merge.

Co-authored-by: 6543 <[email protected]>
2021-08-09 14:08:51 -04:00
KN4CK3RandGitHub aac663e0da Implemented head_commit for webhooks (#16282)
* Removed Len field.

* Added head_commit webhook field.

* Added comment for returns.
2021-06-29 15:34:03 +02:00
KN4CK3RandGitHub e673e42f7e Fixed issues not updated by commits (#16254)
`UpdateIssuesCommit` may get called with fewer commits because of `FeedMaxCommitNum` and therefore may miss some commands.
2021-06-26 10:13:51 +01:00
383ffcfa34 Small refactoring of modules/private (#15947)
* Use correct variable name.

* doer is never nil here.

* Use status code constants.

* Replaced generic map with concrete struct.

* Fixed windows lint.

* Removed unused method.

* Changed error codes.

Co-authored-by: techknowlogick <[email protected]>
2021-06-23 15:38:19 -04:00
f374789fe2 Fix private repo permission problem (#16142)
* Change user access permission

* Add string 'transfer_notices_3'

* Add 3rd transfer note to transfer dialog

* Add test

Co-authored-by: Lunny Xiao <[email protected]>
Co-authored-by: techknowlogick <[email protected]>
2021-06-14 14:30:35 -04:00
0909695204 Merge all deleteBranch as one function and also fix bug when delete branch don't close related PRs (#16067)
* Fix bug when delete branch don't close related PRs

* Merge all deletebranch as one method

* Add missed branch.go

* fix comment

Co-authored-by: Lauris BH <[email protected]>
2021-06-07 22:52:59 +08:00
51775f65bc Make commit info cancelable (#16032)
* Make modules/context.Context a context.Context

Signed-off-by: Andrew Thornton <[email protected]>

* Simplify context calls

Signed-off-by: Andrew Thornton <[email protected]>

* Set the base context for requests to the HammerContext

Signed-off-by: Andrew Thornton <[email protected]>

* pass context into get-last-commit

Signed-off-by: Andrew Thornton <[email protected]>

* Make commit_info cancellable

Signed-off-by: Andrew Thornton <[email protected]>

* use context as context

Signed-off-by: Andrew Thornton <[email protected]>

Co-authored-by: 6543 <[email protected]>
2021-06-06 19:44:58 -04:00
b27a9d43a5 add permission check for `GenerateRepository` (#15946)
Signed-off-by: a1012112796 <[email protected]>

Co-authored-by: techknowlogick <[email protected]>
Co-authored-by: Lunny Xiao <[email protected]>
2021-05-27 12:08:46 -04:00
6543andGitHub a4148c0f12 Repository transfer has to be confirmed, if user can not create repo for new owner (#14792)
* make repo as "pending transfer" if on transfer start doer has no right to create repo in new destination

* if new pending transfer ocured, create UI & Mail notifications
2021-03-01 01:47:30 +01:00
6543andGitHub a19447aed1 migrate from com.* to alternatives (#14103)
* remove github.com/unknwon/com from models

* dont use "com.ToStr()"

* replace "com.ToStr" with "fmt.Sprint" where its easy to do

* more refactor

* fix test

* just "proxy" Copy func for now

* as per @lunny
2020-12-25 11:59:32 +02:00
66379ba7ae Send push event when tag is created or deleted (#13999)
Co-authored-by: zeripath <[email protected]>
Co-authored-by: Lunny Xiao <[email protected]>
2020-12-16 14:41:21 +02:00
zeripathandGitHub f2f99a7d0c Ensure that pusher is not nil preventing panic in push (#13945)
PR #13381 refactored notification actions to call NotifyCreateRef and
NotifyDeleteRef in a slightly different manner. This leads to the pusher
not being set before the call.

This PR ensures that the pusher is updated before the call.

Fix #13940

Signed-off-by: Andrew Thornton <[email protected]>
2020-12-11 18:27:00 +01:00
Lunny XiaoandGitHub ab22ab4a37 Refactor push update (#13381)
* Refactor Push update

* Remove the push_test since the function has been removed.

* Use default branch setting instead master
2020-12-08 03:23:18 +01:00
Lunny XiaoandGitHub a420beda2a Fix a bug on refactoring (#13373) 2020-10-31 23:42:54 +08:00
4df2ed29f2 Refactor: Move PushUpdateOptions (#13363)
Co-authored-by: Antoine GIRARD <[email protected]>
2020-10-30 22:59:02 +01:00
2d75d6f664 Move update-server-info to hooks (#12826)
Signed-off-by: Andrew Thornton <[email protected]>

Co-authored-by: techknowlogick <[email protected]>
2020-10-14 00:24:06 +08:00
9b81193166 Cache last commit when pushing for big repository (#10109)
* Cache last commit when pushing for big repository

* Fix bug

* detect force push

* Refactor cache push

* Finish cache last commit info when push

* Some improvements

* Fix lint

* Remove unused changes

* Move pull request test before cache

* Fix test mysql

Co-authored-by: techknowlogick <[email protected]>
Co-authored-by: Lauris BH <[email protected]>
2020-10-09 01:17:23 +03:00
James LakinandGitHub 6fc129fe62 Fix repository create/delete event webhooks (#13008)
This small PR changes the webhook trigger behaviour to be more in line with what's expected. (When 'repository' events are enabled, of course)

In other words:

For system-wide or default webhooks, repository events will now trigger said webhook. Previously it had to be under an organization for create events to be visible - a tad unexpected!
Deleting a repository will now fire its own defined webhooks, not just organisational and system ones.
In order to enable the latter the webhook has to now be triggered before the actual repo undergoes deletion. I'm willing to tweak this to try and 'grab' the webhook model beforehand and trigger the webhook notifier directly afterwards, but this may make the code more complex for little benefit.

Closes #11766, #9180.
2020-10-02 10:37:46 +01:00
c85c9d40c2 Add config option to make create-on-push repositories public by default (#12936)
* Add config option to make create-on-push repositories public by default

* Fix linting

* Add option to 'config cheat sheet' page

* Chinese translation

Signed-off-by: a1012112796 <[email protected]>

* Fix typo in docs

* fix typo

* Add option to example config

Co-authored-by: Tait Hoyem <[email protected]>
Co-authored-by: a1012112796 <[email protected]>
Co-authored-by: techknowlogick <[email protected]>
2020-09-27 15:20:52 -04:00
7a7f56044a Adopt repositories (#12920)
* Don't automatically delete repository files if they are present

Prior to this PR Gitea would delete any repository files if they are
present during creation or migration. This can in certain circumstances
lead to data-loss and is slightly unpleasant.

This PR provides a mechanism for Gitea to adopt repositories on creation
and otherwise requires an explicit flag for deletion.

PushCreate is slightly different - the create will cause adoption if
that is allowed otherwise it will delete the data if that is allowed.

Signed-off-by: Andrew Thornton <[email protected]>

* Update swagger

Signed-off-by: Andrew Thornton <[email protected]>

* Fix tests and migrate overwrite

Signed-off-by: Andrew Thornton <[email protected]>

* as per @lunny

Only offer to adopt or overwrite if the user can do that.

Allow the site administrator to adopt or overwrite in all
circumstances

Signed-off-by: Andrew Thornton <[email protected]>

* Use setting.Repository.DefaultBranch for the default branch

Signed-off-by: Andrew Thornton <[email protected]>

* Always set setting.Repository.DefaultBranch

Signed-off-by: Andrew Thornton <[email protected]>

* update swagger

Signed-off-by: Andrew Thornton <[email protected]>

* update templates

Signed-off-by: Andrew Thornton <[email protected]>

* ensure repo closed

Signed-off-by: Andrew Thornton <[email protected]>

* Rewrite of adoption as per @6543 and @lunny

Signed-off-by: Andrew Thornton <[email protected]>

* Apply suggestions from code review

* update swagger

Signed-off-by: Andrew Thornton <[email protected]>

* missing not

Signed-off-by: Andrew Thornton <[email protected]>

* add modals and flash reporting

Signed-off-by: Andrew Thornton <[email protected]>

* Make the unadopted page searchable

Signed-off-by: Andrew Thornton <[email protected]>

* Add API

Signed-off-by: Andrew Thornton <[email protected]>

* Fix swagger

Signed-off-by: Andrew Thornton <[email protected]>

* fix swagger

Signed-off-by: Andrew Thornton <[email protected]>

* Handle empty and non-master branched repositories

Signed-off-by: Andrew Thornton <[email protected]>

* placate lint

Signed-off-by: Andrew Thornton <[email protected]>

* remove commented out code

Signed-off-by: Andrew Thornton <[email protected]>

Co-authored-by: techknowlogick <[email protected]>
2020-09-25 07:09:23 +03:00
037d5a33a0 Update only the repository columns that need updating (#12900)
We should only update is_empty, default_branch and updated time columns
during commitRepoAction and not update other columns as we risk
overwriting incorrect information.

Fix #11823
Fix #10536

Signed-off-by: Andrew Thornton <[email protected]>

Co-authored-by: techknowlogick <[email protected]>
2020-09-20 13:55:15 -04:00
dd1a651b58 Move all push update operations to a queue (#10133)
* Fix test

* Add no queue for test only

* improve code

* Auto watch whatever branch operation

* Fix lint

* Rename noqueue to immediate

* Remove old PushUpdate function

* Fix tests

Co-authored-by: zeripath <[email protected]>
Co-authored-by: techknowlogick <[email protected]>
2020-09-11 10:14:48 -04:00
6543andGitHub 13bc82009c API endpoint for repo transfer (#9947)
* squash

* optimize

* fail before make any changes

* fix-header
2020-01-31 15:49:04 +00:00
f2d12f7b03 Fix pull view when head repository or head branch missed and close related pull requests when delete head repository or head branch (#9927)
* fix pull view when head repository or head branch missed and close related pull requests when delete branch

* fix pull view broken when head repository deleted

* close pull requests when head repositories deleted

* Add tests for broken pull request head repository or branch

* fix typo

* ignore special error when close pull request

Co-authored-by: Lauris BH <[email protected]>
2020-01-25 10:48:22 +08:00
Lunny XiaoandAntoine GIRARD d32eac44b1 Move RepoWorkingPool to services/repository package (#9754)
* Move RepoWorkingPool to services/repository package

* Make repoWorkingPool private

Co-authored-by: Antoine GIRARD <[email protected]>
2020-01-15 04:14:50 +01:00
Lunny XiaoandGitHub b465d0d787 Move create/fork repository from models to modules/repository (#9489)
* Move create/fork repository from models to modules/repository

* fix wrong reference

* fix test

* fix test

* fix lint

* Fix DBContext

* remove duplicated TestMain

* fix lint

* fix conflicts
2020-01-12 20:11:17 +08:00
John OlheiserandLunny Xiao 6715677b2b Push to create repo (#8419)
* Refactor

Signed-off-by: jolheiser <[email protected]>

* Add push-create to SSH serv

Signed-off-by: jolheiser <[email protected]>

* Cannot push for another user unless admin

Signed-off-by: jolheiser <[email protected]>

* Get owner in case admin pushes for another user

Signed-off-by: jolheiser <[email protected]>

* Set new repo ID in result

Signed-off-by: jolheiser <[email protected]>

* Update to service and use new org perms

Signed-off-by: jolheiser <[email protected]>

* Move pushCreateRepo to services

Signed-off-by: jolheiser <[email protected]>

* Fix import order

Signed-off-by: jolheiser <[email protected]>

* Changes for @guillep2k

* Check owner (not user) in SSH
* Add basic tests for created repos (private, not empty)

Signed-off-by: jolheiser <[email protected]>
2019-12-15 10:49:52 +08:00
Lunny XiaoandGitHub 77730db257 Move repoWorkPool outside rename/transfer repository (#9086)
* Move repoWorkPool outside rename/transfer repository

* fix import

* Fix test
2019-12-06 12:00:50 +08:00
John OlheiserandLunny Xiao 62bcb2b7f1 Add avatar and issue labels to template repositories (#9149)
* Add avatar and issue labels

Signed-off-by: jolheiser <[email protected]>

* Fix redundant if-err

Signed-off-by: jolheiser <[email protected]>
2019-11-25 13:17:51 +08:00
John Olheiserandtechknowlogick e84326aaec Add git hooks and webhooks to template repositories; move to services (#8926)
* Add git hooks and webhooks to template options

Signed-off-by: jolheiser <[email protected]>

* Update models/repo.go

Co-Authored-By: guillep2k <[email protected]>

* Add tooltip if the user can't edit git hooks

Signed-off-by: jolheiser <[email protected]>

* Close repositories after copying git hooks

Signed-off-by: jolheiser <[email protected]>

* Wording

Co-Authored-By: guillep2k <[email protected]>

* Restructure for services

Signed-off-by: jolheiser <[email protected]>

* Return errors

Signed-off-by: jolheiser <[email protected]>

* Move GenerateRepository to using a DBContext

Signed-off-by: jolheiser <[email protected]>

* Wrap with models.WithTx

Signed-off-by: jolheiser <[email protected]>

* Remove debug print

Signed-off-by: jolheiser <[email protected]>

* Move if-error-delete-repo outside WithTx

Signed-off-by: jolheiser <[email protected]>

* Return nil if no repo generated

Signed-off-by: jolheiser <[email protected]>
2019-11-24 12:57:52 -05:00
Lunny XiaoandGitHub 21ae9838e0 Move transfer repository and rename repository on a service package and start action notification (#8573)
* move transfer repository and rename repository on a service package and start action notification

* remove unused codes

* fix lint

* fix bugs

* fix test

* fix test

* fix test

* fix lint

* update go mod and sum
2019-11-15 16:06:11 +08:00
John OlheiserandLunny Xiao 74a6add4d9 Template Repositories (#8768)
* Start work on templates

Signed-off-by: jolheiser <[email protected]>

* Continue work

Signed-off-by: jolheiser <[email protected]>

* Fix IsTemplate vs IsGenerated

Signed-off-by: jolheiser <[email protected]>

* Fix tabs vs spaces

* Tabs vs Spaces

* Add templates to API & start adding tests

Signed-off-by: jolheiser <[email protected]>

* Fix integration tests

Signed-off-by: jolheiser <[email protected]>

* Remove unused User

Signed-off-by: jolheiser <[email protected]>

* Move template tests to existing repos

Signed-off-by: jolheiser <[email protected]>

* Minor re-check updates and cleanup

Signed-off-by: jolheiser <[email protected]>

* make fmt

Signed-off-by: jolheiser <[email protected]>

* Test cleanup

Signed-off-by: jolheiser <[email protected]>

* Fix optionalbool

Signed-off-by: jolheiser <[email protected]>

* make fmt

Signed-off-by: jolheiser <[email protected]>

* Test fixes and icon change

Signed-off-by: jolheiser <[email protected]>

* Add new user and repo for tests

Signed-off-by: jolheiser <[email protected]>

* Fix tests (finally)

Signed-off-by: jolheiser <[email protected]>

* Update meta repo with env variables

Signed-off-by: jolheiser <[email protected]>

* Move generation to create page

Combine with repo create template
Modify API search to prioritize owner for repo

Signed-off-by: jolheiser <[email protected]>

* Fix tests and coverage

Signed-off-by: jolheiser <[email protected]>

* Fix swagger and JS lint

Signed-off-by: jolheiser <[email protected]>

* Fix API searching for own private repos

Signed-off-by: jolheiser <[email protected]>

* Change wording

Signed-off-by: jolheiser <[email protected]>

* Fix repo search test. User had a private repo that didn't show up

Signed-off-by: jolheiser <[email protected]>

* Another search test fix

Signed-off-by: jolheiser <[email protected]>

* Clarify git content

Co-Authored-By: guillep2k <[email protected]>

* Feedback updates

Signed-off-by: jolheiser <[email protected]>

* Add topics WIP

Signed-off-by: jolheiser <[email protected]>

* Finish adding topics

Signed-off-by: jolheiser <[email protected]>

* Update locale

Signed-off-by: jolheiser <[email protected]>
2019-11-11 23:15:29 +08:00
Lunny XiaoandGitHub 9e85358777 Move some repositories' operations to a standalone service package (#8557)
* Move some repositories' operations to a standalone service package

* improve code

* remove unused codes

* add rollback when fork failed

* add repo when return
2019-10-26 14:54:11 +08:00