remove merge request scope
This commit is contained in:
parent
dc1ee4a5f9
commit
a3d227fb12
1 changed files with 24 additions and 29 deletions
|
@ -214,9 +214,16 @@ func (r *Gitlab) Deactivate(user *common.User, repo *common.Repo, link string) e
|
||||||
// ParseHook parses the post-commit hook from the Request body
|
// ParseHook parses the post-commit hook from the Request body
|
||||||
// and returns the required data in a standard format.
|
// and returns the required data in a standard format.
|
||||||
func (r *Gitlab) Hook(req *http.Request) (*common.Hook, error) {
|
func (r *Gitlab) Hook(req *http.Request) (*common.Hook, error) {
|
||||||
|
defer req.Body.Close()
|
||||||
var payload, _ = ioutil.ReadAll(req.Body)
|
var payload, _ = ioutil.ReadAll(req.Body)
|
||||||
var parsed, _ = gogitlab.ParseHook(payload)
|
var parsed, err = gogitlab.ParseHook(payload)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(parsed.After) == 0 || parsed.TotalCommitsCount == 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
if parsed.ObjectKind == "merge_request" {
|
if parsed.ObjectKind == "merge_request" {
|
||||||
// NOTE: in gitlab 8.0, gitlab will get same MR models as github
|
// NOTE: in gitlab 8.0, gitlab will get same MR models as github
|
||||||
|
@ -224,41 +231,29 @@ func (r *Gitlab) Hook(req *http.Request) (*common.Hook, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
obj := parsed.ObjectAttributes
|
if len(parsed.After) == 0 {
|
||||||
if !(obj.State == "opened" && obj.MergeStatus == "unchecked") {
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var hook = new(common.Hook)
|
var hook = new(common.Hook)
|
||||||
|
hook.Repo.Owner = req.FormValue("owner")
|
||||||
|
hook.Repo.Name = req.FormValue("name")
|
||||||
|
hook.Commit.Sha = parsed.After
|
||||||
|
hook.Commit.Branch = parsed.Branch()
|
||||||
|
|
||||||
hook.Repo.Name = obj.Source.Name
|
var head = parsed.Head()
|
||||||
hook.Repo.Owner = obj.Source.Namespace
|
hook.Commit.Message = head.Message
|
||||||
|
hook.Commit.Timestamp = head.Timestamp
|
||||||
|
|
||||||
// Check pull request comes from public fork
|
// extracts the commit author (ideally email)
|
||||||
if obj.Source.VisibilityLevel < 20 {
|
// from the post-commit hook
|
||||||
//hook.SourceRemote = obj.Source.SshUrl
|
switch {
|
||||||
// If pull request source repo is not a public
|
case head.Author != nil:
|
||||||
// check for non-internal pull request
|
hook.Commit.Author.Email = head.Author.Email
|
||||||
if obj.Source.Name != obj.Target.Name || obj.Source.Namespace != obj.Target.Namespace {
|
case head.Author == nil:
|
||||||
return nil, nil
|
hook.Commit.Author.Login = parsed.UserName
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hook.Commit.Author.Login = req.FormValue("owner")
|
|
||||||
hook.Commit.Sha = obj.LastCommit.Id
|
|
||||||
hook.Commit.Branch = obj.TargetBranch
|
|
||||||
hook.Commit.Timestamp = obj.LastCommit.Timestamp
|
|
||||||
hook.Commit.Message = obj.Title
|
|
||||||
|
|
||||||
if obj.LastCommit.Author == nil {
|
|
||||||
// Waiting for merge https://github.com/gitlabhq/gitlabhq/pull/7967
|
|
||||||
hook.Commit.Author.Email = ""
|
|
||||||
} else {
|
|
||||||
hook.Commit.Author.Email = obj.LastCommit.Author.Email
|
|
||||||
}
|
|
||||||
|
|
||||||
hook.PullRequest.Number = obj.IId
|
|
||||||
|
|
||||||
return hook, nil
|
return hook, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue