-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
#6946 Run hooks on merge/edit and cope with protected branches #6961
Conversation
cbf008b
to
71467f9
Compare
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
OK two things:
~~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. |
OK I've discovered the issue here, TestSearchRepos is broken. |
Now working after applying #7004 to fix that broken test |
…zeripath/gitea into fix-go-gitea#6946-pass-in-pr-into-hooks
} | ||
|
||
// 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", |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Conflicts resolved. |
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. |
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
glad to see this fixed in gitea related gogs issue gogs/gogs#5120 |
Fix #6946 by setting and checking PullRequest ID on pushing if we're pushing from a PR.
Fixes #6003.