Skip to content

Commit

Permalink
Do not allow to run generate on the knowledge contribution.
Browse files Browse the repository at this point in the history
Signed-off-by: Anil Vishnoi <[email protected]>
  • Loading branch information
vishnoianil committed Sep 12, 2024
1 parent 006b6b6 commit 6d2326c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions gobot/handlers/issue_comment_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const (
AccessCheckFailed = "Access check failed."
LabelsNotFound = "Required labels not found."
BotEnabled = "Bot is successfully enabled."
NotAllowed = "Command not allowed"
)

type PRCommentHandler struct {
Expand Down Expand Up @@ -445,6 +446,19 @@ func (h *PRCommentHandler) sdgSvcCommand(ctx context.Context, client *github.Cli
return util.PostPullRequestCheck(ctx, client, params)
}

present, err = util.CheckKnowledgeLabel(prComment.labels)
if err != nil {
h.Logger.Errorf("Failed to check knowledge label: %v", err)
}
if present {
detailsMsg := "Beep, boop 🤖: Bot does not allow to run generate on the knowledge contribution."

params.CheckSummary = NotAllowed
params.CheckDetails = detailsMsg

return util.PostPullRequestCheck(ctx, client, params)
}

return h.queueGenerateJob(ctx, client, prComment, "sdg-svc")
}

Expand Down
14 changes: 14 additions & 0 deletions gobot/util/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/instructlab/instructlab-bot/gobot/common"
)

const KnowledgeLabel string = "knowledge"

func CheckBotEnableStatus(ctx context.Context, client *github.Client, params PullRequestStatusParams) (bool, error) {
checkStatus, response, err := client.Checks.ListCheckRunsForRef(ctx, params.RepoOwner, params.RepoName, params.PrSha, nil)
if err != nil {
Expand All @@ -26,6 +28,18 @@ func CheckBotEnableStatus(ctx context.Context, client *github.Client, params Pul
return false, nil
}

func CheckKnowledgeLabel(labels []*github.Label) (bool, error) {

labelFound := false
for _, label := range labels {
if label.GetName() == KnowledgeLabel {
labelFound = true
break
}
}
return labelFound, nil
}

func CheckRequiredLabel(labels []*github.Label, requiredLabels []string) (bool, error) {
if len(requiredLabels) == 0 {
return true, nil
Expand Down

0 comments on commit 6d2326c

Please sign in to comment.