Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#6946 Run hooks on merge/edit and cope with protected branches #6961

Merged
merged 22 commits into from
Jul 1, 2019

Conversation

zeripath
Copy link
Contributor

@zeripath zeripath commented May 15, 2019

Fix #6946 by setting and checking PullRequest ID on pushing if we're pushing from a PR.
Fixes #6003.

@zeripath zeripath force-pushed the fix-#6946-pass-in-pr-into-hooks branch from cbf008b to 71467f9 Compare May 15, 2019 19:29
@lafriks lafriks added this to the 1.9.0 milestone May 15, 2019
@codecov-io
Copy link

codecov-io commented May 15, 2019

Codecov Report

Merging #6961 into master will increase coverage by 0.05%.
The diff coverage is 41.3%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #6961      +/-   ##
==========================================
+ Coverage   41.24%   41.29%   +0.05%     
==========================================
  Files         466      466              
  Lines       63153    63186      +33     
==========================================
+ Hits        26048    26095      +47     
+ Misses      33700    33680      -20     
- Partials     3405     3411       +6
Impacted Files Coverage Δ
models/branches.go 50% <ø> (ø) ⬆️
cmd/serv.go 0% <0%> (ø) ⬆️
cmd/hook.go 0% <0%> (ø) ⬆️
models/pull.go 56.1% <0%> (+5.16%) ⬆️
modules/private/hook.go 0% <0%> (ø) ⬆️
models/helper_environment.go 88.46% <100%> (+2.74%) ⬆️
modules/pull/merge.go 38.52% <22.22%> (-0.84%) ⬇️
routers/private/hook.go 48.14% <26.31%> (-2.73%) ⬇️
models/repo_indexer.go 67.08% <0%> (-2.09%) ⬇️
models/repo_list.go 72.08% <0%> (-1.02%) ⬇️
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e5a4d78...77e8790. Read the comment docs.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label May 15, 2019
@zeripath zeripath changed the title Fix #6946 by setting pull request ID on pushing WIP: Fix #6946 by setting pull request ID on pushing May 15, 2019
@zeripath
Copy link
Contributor Author

zeripath commented May 15, 2019

OK two things:

  1. I'm getting a deadlock on merges which is interesting because I don't think that should be happening.
  2. I'm also getting an error on the tests.

~~Right I think I'll leave this as WIP but open a second PR to stop running the push hooks on merge. ~~

These are fixed.

@zeripath
Copy link
Contributor Author

OK I've discovered the issue here, TestSearchRepos is broken.

@zeripath zeripath changed the title WIP: Fix #6946 by setting pull request ID on pushing Fix #6946 by setting pull request ID on pushing May 17, 2019
@zeripath zeripath changed the title Fix #6946 by setting pull request ID on pushing #6946 Run hooks on merge/edit and cope with protected branches May 20, 2019
@zeripath
Copy link
Contributor Author

Now working after applying #7004 to fix that broken test

}

// HookPreReceive check whether the provided commits are allowed
func HookPreReceive(ownerName, repoName string, opts HookOptions) (int, string) {
reqURL := setting.LocalURL + fmt.Sprintf("api/internal/hook/pre-receive/%s/%s?old=%s&new=%s&ref=%s&userID=%d&gitObjectDirectory=%s&gitAlternativeObjectDirectories=%s",
reqURL := setting.LocalURL + fmt.Sprintf("api/internal/hook/pre-receive/%s/%s?old=%s&new=%s&ref=%s&userID=%d&gitObjectDirectory=%s&gitAlternativeObjectDirectories=%s&prID=%d",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we get the prID from routers but not envs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately not. Remember the hooks are called from within git.

@lunny
Copy link
Member

lunny commented Jun 26, 2019

Please resolve conflicts

models/pull.go Outdated
@@ -555,7 +555,7 @@ func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository, mergeStyle
return ErrInvalidMergeStyle{pr.BaseRepo.ID, mergeStyle}
}

env := PushingEnvironment(doer, pr.BaseRepo)
env := FullPushingEnvironment(doer, doer, pr.BaseRepo, pr.ID)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

author should be pullrequest's poster

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@zeripath
Copy link
Contributor Author

Conflicts resolved.

@zeripath
Copy link
Contributor Author

So the next step once we have this PR is to enforce that we have to have an appropriate Gitea environment before allowing pushing to gitea repositories - this will prevent the numerous issues that we get whereby people abuse Gitea repositories by pushing outside of Gitea.

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Jun 28, 2019
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Jun 30, 2019
@lunny lunny merged commit 3563650 into go-gitea:master Jul 1, 2019
@zeripath zeripath deleted the fix-#6946-pass-in-pr-into-hooks branch July 1, 2019 06:45
jeffliu27 pushed a commit to jeffliu27/gitea that referenced this pull request Jul 18, 2019
go-gitea#6961)

* Fix go-gitea#6946 by checking PullRequest ID on pushing

* Ensure we have the owner name, the pr attributes and the the issue

* Fix TestSearchRepo by waiting till indexing is done

* Update integrations/repo_search_test.go

* changes as per @mrsdizzie

* missing comma

* Spelling mistake

* Fix full pushing environment
@stealthybox
Copy link
Contributor

stealthybox commented Aug 12, 2019

glad to see this fixed in gitea
thank you @zeripath 🌮

related gogs issue gogs/gogs#5120

@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error when merge pull request no git hook executed during "gitea squash and merge"
7 participants