1 package task 2 3 import ( 4 //"strings" 5 6 //"github.com/google/go-github/v47/github" 7 8 "edge-infra.dev/pkg/f8n/devinfra/jack/constants" 9 //"edge-infra.dev/pkg/f8n/devinfra/jack/plugin" 10 ) 11 12 // handleNewComment handles new comment events for the task plugin 13 /* 14 func handleNewComment(hp plugin.HandlerParams, ce github.IssueCommentEvent, taskCommands []string) error { 15 // Validate the kind/ label and if its not a valid label --> bounce 16 tempCommand := taskCommands[0] 17 kind, validKind := validateKindCommand(tempCommand) 18 if !validKind { 19 hp.Log.Info().Msg("command is not a valid kind") 20 return nil 21 } 22 23 // Gather the label names 24 // *task name 25 labelNames := []string{} 26 labels := ce.GetIssue().Labels 27 for _, label := range labels { 28 name := label.GetName() 29 // if the kind command is for a kind thats already there exit 30 if name == kind { 31 hp.Log.Info().Msgf("%s label already exists. Exiting.", kind) 32 return nil 33 } 34 35 // only add none kind labels to the list 36 if !strings.Contains(name, "kind/") && name != string(constants.Task) { 37 labelNames = append(labelNames, name) 38 } 39 } 40 41 // remove the old kind and add the new 42 labelNames = append(labelNames, kind) 43 githubIssueBody := &github.IssueRequest{Labels: &labelNames} 44 _, _, err := hp.Client.Issues().Edit(hp.Ctx, ce.Repo.GetOwner().GetLogin(), ce.Repo.GetName(), ce.GetIssue().GetNumber(), githubIssueBody) 45 if err != nil { 46 hp.Log.Error().Err(err).Msg("Failed to update issue desc") 47 return err 48 } 49 return nil 50 } 51 */ 52 53 // check if the given kind is valid return the constant for the appro kind 54 func validateKindCommand(taskCommand string) (string, bool) { 55 task := string(constants.Task) 56 epic := string(constants.Epic) 57 capability := string(constants.Capability) 58 feature := string(constants.Feature) 59 story := string(constants.Story) 60 61 switch taskCommand { 62 case "task", task: 63 return task, true 64 case "epic", epic: 65 return epic, true 66 case "capacity", capability: 67 return capability, true 68 case "feature", feature: 69 return feature, true 70 case "story", story: 71 return story, true 72 } 73 return "", false 74 } 75