Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not allow to run generate on the knowledge contribution. #415

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 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,27 @@ 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."

botComment := github.IssueComment{
Body: &detailsMsg,
}

if _, _, err := client.Issues.CreateComment(ctx, prComment.repoOwner, prComment.repoName, prComment.prNum, &botComment); err != nil {
h.Logger.Error("Failed to comment on pull request: %w", err)
}

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
Loading