Skip to content

Commit 8467721

Browse files
authored
Merge pull request #415 from vishnoianil/generate-knowledge
Do not allow to run generate on the knowledge contribution.
2 parents 006b6b6 + f41b99c commit 8467721

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

gobot/handlers/issue_comment_event.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const (
2323
AccessCheckFailed = "Access check failed."
2424
LabelsNotFound = "Required labels not found."
2525
BotEnabled = "Bot is successfully enabled."
26+
NotAllowed = "Command not allowed"
2627
)
2728

2829
type PRCommentHandler struct {
@@ -445,6 +446,27 @@ func (h *PRCommentHandler) sdgSvcCommand(ctx context.Context, client *github.Cli
445446
return util.PostPullRequestCheck(ctx, client, params)
446447
}
447448

449+
present, err = util.CheckKnowledgeLabel(prComment.labels)
450+
if err != nil {
451+
h.Logger.Errorf("Failed to check knowledge label: %v", err)
452+
}
453+
if present {
454+
detailsMsg := "Beep, boop 🤖: Bot does not allow to run generate on the knowledge contribution."
455+
456+
botComment := github.IssueComment{
457+
Body: &detailsMsg,
458+
}
459+
460+
if _, _, err := client.Issues.CreateComment(ctx, prComment.repoOwner, prComment.repoName, prComment.prNum, &botComment); err != nil {
461+
h.Logger.Error("Failed to comment on pull request: %w", err)
462+
}
463+
464+
params.CheckSummary = NotAllowed
465+
params.CheckDetails = detailsMsg
466+
467+
return util.PostPullRequestCheck(ctx, client, params)
468+
}
469+
448470
return h.queueGenerateJob(ctx, client, prComment, "sdg-svc")
449471
}
450472

gobot/util/utils.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"github.com/instructlab/instructlab-bot/gobot/common"
99
)
1010

11+
const KnowledgeLabel string = "knowledge"
12+
1113
func CheckBotEnableStatus(ctx context.Context, client *github.Client, params PullRequestStatusParams) (bool, error) {
1214
checkStatus, response, err := client.Checks.ListCheckRunsForRef(ctx, params.RepoOwner, params.RepoName, params.PrSha, nil)
1315
if err != nil {
@@ -26,6 +28,18 @@ func CheckBotEnableStatus(ctx context.Context, client *github.Client, params Pul
2628
return false, nil
2729
}
2830

31+
func CheckKnowledgeLabel(labels []*github.Label) (bool, error) {
32+
33+
labelFound := false
34+
for _, label := range labels {
35+
if label.GetName() == KnowledgeLabel {
36+
labelFound = true
37+
break
38+
}
39+
}
40+
return labelFound, nil
41+
}
42+
2943
func CheckRequiredLabel(labels []*github.Label, requiredLabels []string) (bool, error) {
3044
if len(requiredLabels) == 0 {
3145
return true, nil

0 commit comments

Comments
 (0)