prow/cmd/branchprotector/protect.go
func (p *protector) protect() {
	bp := p.cfg.BranchProtection

	// Scan the branch-protection configuration
	for orgName := range bp.Orgs {
		org := bp.GetOrg(orgName)
		if err := p.UpdateOrg(orgName, *org); err != nil {
			p.errors.add(fmt.Errorf("update %s: %v", orgName, err))
		}
	}

	// Do not automatically protect tested repositories
	if !bp.ProtectTested {
		return
	}

	// Some repos with presubmits might not be listed in the branch-protection
	for repo := range p.cfg.Presubmits {
		if p.completedRepos[repo] == true {
			continue
		}
		parts := strings.Split(repo, "/")
		if len(parts) != 2 { // TODO(fejta): use a strong type here instead
			p.errors.add(fmt.Errorf("bad presubmit repo: %s", repo))
			continue
		}
		orgName := parts[0]
		repoName := parts[1]
		repo := bp.GetOrg(orgName).GetRepo(repoName)
		if err := p.UpdateRepo(orgName, repoName, *repo); err != nil {
			p.errors.add(fmt.Errorf("update %s/%s: %v", orgName, repoName, err))
		}
	}
}
func (p *protector) protect() {
	bp := p.cfg.BranchProtection

	// Scan the branch-protection configuration
	for orgName := range bp.Orgs {
		org := bp.GetOrg(orgName)
		if err := p.UpdateOrg(orgName, *org); err != nil {
			p.errors.add(fmt.Errorf("update %s: %v", orgName, err))
		}
	}

	// Do not automatically protect tested repositories
	if !bp.ProtectTested {
		return
	}

	// Some repos with presubmits might not be listed in the branch-protection
	for repo := range p.cfg.Presubmits {
		if p.completedRepos[repo] == true {
			continue
		}
		parts := strings.Split(repo, "/")
		if len(parts) != 2 { // TODO(fejta): use a strong type here instead
			p.errors.add(fmt.Errorf("bad presubmit repo: %s", repo))
			continue
		}
		orgName := parts[0]
		repoName := parts[1]
		repo := bp.GetOrg(orgName).GetRepo(repoName)
		if err := p.UpdateRepo(orgName, repoName, *repo); err != nil {
			p.errors.add(fmt.Errorf("update %s/%s: %v", orgName, repoName, err))
		}
	}
}
func ( p * protector ) protect ( ) { bp := p . cfg . BranchProtection // Scan the branch-protection configuration for orgName := range bp . Orgs { org := bp . GetOrg ( orgName ) if err := p . UpdateOrg ( orgName , * org ) ; err != nil { p . errors . add ( fmt . Errorf ( " " , orgName , err ) ) } } // Do not automatically protect tested repositories if ! bp . ProtectTested { return } // Some repos with presubmits might not be listed in the branch-protection for repo := range p . cfg . Presubmits { if p . completedRepos [ repo ] == true { continue } parts := strings . Split ( repo , " " ) if len ( parts ) != 2 { // TODO(fejta): use a strong type here instead p . errors . add ( fmt . Errorf ( " " , repo ) ) continue } orgName := parts [ 0 ] repoName := parts [ 1 ] repo := bp . GetOrg ( orgName ) . GetRepo ( repoName ) if err := p . UpdateRepo ( orgName , repoName , * repo ) ; err != nil { p . errors . add ( fmt . Errorf ( " " , orgName , repoName , err ) ) } } }
// protect protects branches specified in the presubmit and branch-protection config sections.
protect protects branches specified in the presubmit and branch - protection config sections .