func ValidatePRR()

in pkg/kepval/approval.go [32:98]


func ValidatePRR(kep *api.Proposal, h *api.PRRHandler, prrDir string) error {
	requiredPRRApproval, _, _, err := isPRRRequired(kep)
	if err != nil {
		return errors.Wrap(err, "checking if PRR is required")
	}

	if !requiredPRRApproval {
		logrus.Debugf("PRR review is not required for %s", kep.Number)
		return nil
	}

	prrFilename := kep.Number + ".yaml"
	prrFilepath := filepath.Join(
		prrDir,
		kep.OwningSIG,
		prrFilename,
	)

	logrus.Infof("PRR file: %s", prrFilepath)

	prrFile, err := os.Open(prrFilepath)
	if os.IsNotExist(err) {
		return err
	}

	if err != nil {
		return errors.Wrapf(err, "could not open file %s", prrFilepath)
	}

	// TODO: Create a context to hold the parsers
	prr, prrParseErr := h.Parse(prrFile)
	if prrParseErr != nil {
		return errors.Wrap(prrParseErr, "parsing PRR approval file")
	}

	// TODO: This shouldn't be required once we push the errors into the
	//       parser struct
	if prr.Error != nil {
		return errors.Wrapf(prr.Error, "%v has an error", prrFilepath)
	}

	stagePRRApprover, err := prr.ApproverForStage(kep.Stage)
	if err != nil {
		return errors.Wrapf(err, "getting PRR approver for %s stage", kep.Stage)
	}

	if stagePRRApprover == "" {
		return errors.New("PRR approver cannot be empty")
	}

	if strings.HasPrefix(stagePRRApprover, "@") {
		stagePRRApprover = strings.TrimPrefix(stagePRRApprover, "@")
	}

	validApprover := api.IsOneOf(stagePRRApprover, h.PRRApprovers)
	if !validApprover {
		return errors.New(
			fmt.Sprintf(
				"this contributor (%s) is not a PRR approver (%v)",
				stagePRRApprover,
				h.PRRApprovers,
			),
		)
	}

	return nil
}