// Validate approves builds from the same repository, and blocks builds from forks.
Validate approves builds from the same repository, and blocks builds from forks.
// Validate approves builds from the same repository and blocks builds from forks .
func (p *plugin) Validate(ctx context.Context, req *validator.Request) error {
	switch req.Build.Event {
	case "push", "tag": 
		log.Debugf("%s build ignored", req.Build.Event)
		return nil
	case "cron", "promote", "rollback", "custom": 
		log.Debugf("%s build ignored", req.Build.Event)
		return nil
	case "pull_request": 
		break
	default: 
		log.Warnf("%s build unrecognized", req.Build.Event)
		return validator.ErrBlock
	}
	sourceRepo := req.Build.Fork
	targetRepo := req.Repo.Slug
	if sourceRepo != targetRepo { 
		log.WithFields(log.Fields{"source": sourceRepo, "target": targetRepo}).Infof("%s needs approval", req.Build.Link)
		return validator.ErrBlock
	} else {
		log.WithFields(log.Fields{"source": sourceRepo, "target": targetRepo}).Infof("%s approved", req.Build.Link)
		return nil
	}
}
func ( p * plugin ) Validate ( ctx context . Context , req * validator . Request ) error { switch req . Build . Event { case " " , " " : log . Debugf ( " " , req . Build . Event ) return nil case " " , " " , " " , " " : log . Debugf ( " " , req . Build . Event ) return nil case " " : break default : log . Warnf ( " " , req . Build . Event ) return validator . ErrBlock } sourceRepo := req . Build . Fork targetRepo := req . Repo . Slug if sourceRepo != targetRepo { log . WithFields ( log . Fields { " " : sourceRepo , " " : targetRepo } ) . Infof ( " " , req . Build . Link ) return validator . ErrBlock } else { log . WithFields ( log . Fields { " " : sourceRepo , " " : targetRepo } ) . Infof ( " " , req . Build . Link ) return nil } }
Validate approves builds from the same repository, and blocks builds from forks.
Validate approves builds from the same repository and blocks builds from forks .
// triggered by folks with write access to the repo, therefore trusted // triggered by folks with write access in drone // may be triggered by folks without write access, needs approval // unknown new event, fail secure // then the PR is coming from a fork