package main

import "src.opensuse.org/autogits/common"

type PullRequestReviewed struct {
	gitea common.Gitea
}

func (o *PullRequestReviewed) Process(req *common.PullRequestWebhookEvent, git common.Git, config *common.AutogitConfig) error {
	prset, err := common.FetchPRSet(o.gitea, req.Repository.Owner.Username, req.Repository.Name, req.Number, config)
	if err != nil {
		return err
	}

	maintainers, err := common.FetchProjectMaintainershipData(o.gitea, prset.Config.Organization, prset.Config.GitProjectName, prset.Config.Branch)
	if err != nil {
		return err
	}

	if prset.IsApproved(o.gitea, maintainers) {
		prset.Merge(GitAuthor, GitEmail)
	}

	return nil
}
