func (g GitHub) IsMergeable(prHook *octokat.PullRequestHook) (mergeable bool, err error) { // assume the PR is mergable unless we specifically set to false // because mergable true is equivalent to skip mergeable = true // we only want the prs that are opened/synchronized if !prHook.IsOpened() && !prHook.IsSynchronize() { return mergeable, nil } // get the PR pr := prHook.PullRequest repo := getRepo(prHook.Repo) content, err := g.getContent(repo, prHook.Number, true) if err != nil { return mergeable, err } commentType := "merge conflicts" if !isMergeable(pr) { mergeable = false log.Debugf("Found pr %d was not mergable, going to add comment", prHook.Number) // add a comment comment := "Looks like we would not be able to merge this PR because of merge conflicts. Please rebase, fix conflicts, and force push to your branch." if err := g.addUniqueComment(repo, strconv.Itoa(prHook.Number), comment, commentType, content); err != nil { return mergeable, err } // set the status if err := g.failureStatus(repo, pr.Head.Sha, "docker/is-mergable", "This PR is not mergable, please fix conflicts.", "https://docs.docker.com/project/work-issue/"); err != nil { return mergeable, err } return mergeable, nil } // otherwise try to find the comment and remove it if err := g.removeComment(repo, pr, commentType, content); err != nil { return mergeable, err } return mergeable, nil }
func (g GitHub) DcoVerified(prHook *octokat.PullRequestHook) (bool, error) { // we only want the prs that are opened/synchronized if !prHook.IsOpened() && !prHook.IsSynchronize() { return false, nil } // get the PR pr := prHook.PullRequest repo := getRepo(prHook.Repo) // check if this is a bump branch, then we don't want to check sig if pr.Base.Ref == "release" { return true, nil } content, err := g.getContent(repo, prHook.Number, true) if err != nil { return false, err } // we only want apply labels // to opened pull requests var labels []string //check if it's a proposal isProposal := strings.Contains(strings.ToLower(pr.Title), "proposal") switch { case isProposal: labels = []string{"status/1-design-review"} case content.IsDocsOnly(): labels = []string{"status/3-docs-review"} default: labels = []string{"status/0-triage"} } if labelOs(pr, "windows", content.OnlyWindows) { labels = append(labels, "group/windows") } // add labels if there are any // only add labels to new PRs not sync if len(labels) > 0 && prHook.IsOpened() { log.Debugf("Adding labels %#v to pr %d", labels, prHook.Number) if err := g.addLabel(repo, prHook.Number, labels...); err != nil { return false, err } log.Infof("Added labels %#v to pr %d", labels, prHook.Number) } var verified bool if content.CommitsSigned() { if err := g.removeLabel(repo, prHook.Number, "dco/no"); err != nil { return false, err } if err := g.removeComment(repo, pr, "sign your commits", content); err != nil { return false, err } if err := g.successStatus(repo, pr.Head.Sha, "docker/dco-signed", "All commits signed"); err != nil { return false, err } verified = true } else { if err := g.addLabel(repo, prHook.Number, "dco/no"); err != nil { return false, err } if err := g.addDCOUnsignedComment(repo, pr, content); err != nil { return false, err } if err := g.failureStatus(repo, pr.Head.Sha, "docker/dco-signed", "Some commits without signature", "https://github.com/docker/docker/blob/master/CONTRIBUTING.md#sign-your-work"); err != nil { return false, err } } return verified, nil }