func HandlePullReviewCommentEvent(gc githubClient, pullReviewCommentEvent *github.ReviewCommentEvent,
	cfg *tiexternalplugins.Configuration, log *logrus.Entry) error {
	if pullReviewCommentEvent.PullRequest.State != "open" ||
		pullReviewCommentEvent.Action != github.ReviewCommentActionCreated {
		return nil
	}
	rc := reviewCtx{
		author:  pullReviewCommentEvent.Comment.User.Login,
		body:    pullReviewCommentEvent.Comment.Body,
		htmlURL: pullReviewCommentEvent.Comment.HTMLURL,
		repo:    pullReviewCommentEvent.Repo,
		number:  pullReviewCommentEvent.PullRequest.Number,
	}
	return handle(cfg, rc, gc, log)
}
HandlePullReviewCommentEvent handles a GitHub pull request review comment event and auto respond it.
package autoresponder
import (
	"regexp"
	"strings"
	"github.com/sirupsen/logrus"
	"k8s.io/test-infra/prow/config"
	"k8s.io/test-infra/prow/github"
	"k8s.io/test-infra/prow/pluginhelp"
	"k8s.io/test-infra/prow/pluginhelp/externalplugins"
	"k8s.io/test-infra/prow/plugins"
	tiexternalplugins "github.com/ti-community-infra/tichi/internal/pkg/externalplugins"
)
const PluginName = "ti-community-autoresponder"
type githubClient interface {
	CreateComment(owner, repo string, number int, comment string) error
}
type reviewCtx struct {
	repo                  github.Repo
	author, body, htmlURL string
	number                int
}
func HelpProvider(epa *tiexternalplugins.ConfigAgent) externalplugins.ExternalPluginHelpProvider {
	return func(enabledRepos []config.OrgRepo) (*pluginhelp.PluginHelp, error) {
		configInfo := map[string]string{}
		cfg := epa.Config()
		for _, repo := range enabledRepos {
			opts := cfg.AutoresponderFor(repo.Org, repo.Repo)
			var isConfigured bool
			var configInfoStrings []string
			configInfoStrings = append(configInfoStrings, "The plugin has these configurations:<ul>")
			if len(opts.AutoResponds) != 0 {
				isConfigured = true
			}
			for _, respond := range opts.AutoResponds {
				configInfoStrings = append(configInfoStrings, "<li>"+respond.Regex+":"+respond.Message+"</li>")
			}
			configInfoStrings = append(configInfoStrings, "</ul>")
			if isConfigured {
				configInfo[repo.String()] = strings.Join(configInfoStrings, "\n")
			}
		}
		yamlSnippet, err := plugins.CommentMap.GenYaml(&tiexternalplugins.Configuration{
			TiCommunityAutoresponder: []tiexternalplugins.TiCommunityAutoresponder{
				{
					Repos: []string{"ti-community-infra/test-dev"},
					AutoResponds: []tiexternalplugins.AutoRespond{
						{
							Regex:   "(?mi)^/ping\\s*$",
							Message: "pong",
						},
					},
				},
			},
		})
		if err != nil {
			logrus.WithError(err).Warnf("cannot generate comments for %s plugin", PluginName)
		}
		pluginHelp := &pluginhelp.PluginHelp{
			Description: "The ti-community-autoresponder will trigger an automatic reply when the comment matches a regex.",
			Config:      configInfo,
			Snippet:     yamlSnippet,
			Events: []string{
				tiexternalplugins.PullRequestEvent,
				tiexternalplugins.PullRequestReviewEvent,
				tiexternalplugins.PullRequestReviewCommentEvent,
				tiexternalplugins.IssuesEvent,
				tiexternalplugins.IssueCommentEvent,
			},
		}
		return pluginHelp, nil
	}
}
func HandleIssueCommentEvent(gc githubClient, ice *github.IssueCommentEvent,
	cfg *tiexternalplugins.Configuration, log *logrus.Entry) error {
	if ice.Issue.State != "open" || ice.Action != github.IssueCommentActionCreated {
		return nil
	}
	rc := reviewCtx{
		repo:    ice.Repo,
		author:  ice.Comment.User.Login,
		body:    ice.Comment.Body,
		htmlURL: ice.Comment.HTMLURL,
		number:  ice.Issue.Number,
	}
	return handle(cfg, rc, gc, log)
}