Ejemplo n.º 1
0
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
}
Ejemplo n.º 2
0
func (h *Handler) handlePullRequest(prHook *octokat.PullRequestHook) error {
	// we only want the prs that are opened
	if !prHook.IsOpened() {
		return nil
	}

	// get the PR
	pr := prHook.PullRequest

	// initialize github client
	gh := h.Client
	repo := getRepo(prHook.Repo)
	prId := strconv.Itoa(prHook.Number)

	// checkout the repository in a temp dir
	temp, err := ioutil.TempDir("", fmt.Sprintf("pr-%d", prHook.Number))
	if err != nil {
		return err
	}
	defer os.RemoveAll(temp)

	if err := fetchPullRequest(temp, pr.Base.Repo.HTMLURL, prHook.Number); err != nil {
		return err
	}

	prFiles, err := gh.PullRequestFiles(repo, prId, &octokat.Options{})
	if err != nil {
		return err
	}

	if err = validateFormat(gh, repo, pr.Head.Sha, temp, prId, prFiles); err != nil {
		return err
	}

	return nil
}
Ejemplo n.º 3
0
Archivo: dco.go Proyecto: se77en/leeroy
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
}