...

Source file src/edge-infra.dev/pkg/f8n/devinfra/jack/plugin/task/handler.go

Documentation: edge-infra.dev/pkg/f8n/devinfra/jack/plugin/task

     1  package task
     2  
     3  import (
     4  	"github.com/google/go-github/v47/github"
     5  
     6  	"edge-infra.dev/pkg/f8n/devinfra/jack/plugin"
     7  )
     8  
     9  const (
    10  	PluginName = "task"
    11  )
    12  
    13  func init() {
    14  	plugin.RegisterIssueHandler(PluginName, handleIssue)
    15  	// plugin.RegisterIssueCommentHandler(PluginName, handleIssueComment)
    16  }
    17  
    18  /*
    19  func handleIssueComment(hp plugin.HandlerParams, ce github.IssueCommentEvent) {
    20  	hp.Log = hp.Log.With().Str("plugin", PluginName).Logger()
    21  
    22  	// check if there are any kind/task commands and bounce if not
    23  	if ce.GetAction() != "created" {
    24    		return
    25  	}
    26  	taskCommands := util.GetSpecificCommandFromBody(ce.Comment.GetBody(), "kind", false, false)
    27  	hp.Log.Info().Msgf("handling a new kind/task command from a comment: %+v", taskCommands)
    28  	err := handleNewComment(hp, ce, taskCommands)
    29  	if err != nil {
    30  		hp.Log.Error().Err(err)
    31  	}
    32  }
    33  */
    34  
    35  func handleIssue(hp plugin.HandlerParams, ie github.IssuesEvent) {
    36  	hp.Log.WithName(PluginName)
    37  
    38  	log := hp.Log
    39  	ctx := hp.Ctx
    40  	client := hp.Client
    41  	log.Info("Running task plugin")
    42  
    43  	switch action := ie.GetAction(); action {
    44  	case "opened":
    45  		if err := addKindToNewIssue(ctx, log, client, ie); err != nil {
    46  			log.Error(err, "Failed to add kind to new issue")
    47  		}
    48  	case "labeled":
    49  		if err := addTaskLabel(ctx, log, client, ie); err != nil {
    50  			log.Error(err, "Failed to add task label")
    51  		}
    52  	case "unlabeled":
    53  		if err := removeTaskLabel(ctx, log, client, ie); err != nil {
    54  			log.Error(err, "Failed to remove task label")
    55  		}
    56  	}
    57  }
    58  

View as plain text