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

chore: add bot response for non-conf results #187

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
31 changes: 26 additions & 5 deletions internal/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ var (
}
managedPRLabels = []string{
"conformance-product-submission",
"not-conformance-product-submission",
"not-verifiable",
"release-documents-checked",
"required-tests-missing",
Expand Down Expand Up @@ -527,18 +528,38 @@ commitLoop:
// handle checks a Conformance Certification PR to determine if the contents of the PR pass sanity checks.
// Adds a comment to indicate whether or not the version in the PR title occurs in the supplied logs.
func handle(log *logrus.Entry, ghc githubClient, pr *suite.PullRequestQuery) error {
if !isConformancePR(pr) {
log.Printf("This PR (%v) is not a conformance PR\n", int(pr.Number))
return nil
}

godogFeaturePaths := GetGodogPaths()
prSuite, err := NewPRSuiteForPR(log, ghc, pr)
if err != nil {
return err
}
prSuite.MetadataFolder = path.Join(common.GetDataPath(), "conformance-testdata")
prSuite.SetSubmissionMetadatafromFolderStructure()
if !isConformancePR(pr) {
log.Printf("This PR (%v) is not a conformance PR\n", int(pr.Number))
finalComment := strings.Join(
[]string{
"This pull request appears to not be a conformance results submission; Checks will not run.",
"",
"If this change is intended to be verified as a conformance results submission see: " +
"[_content of the PR_](https://github.com/cncf/k8s-conformance/blob/master/instructions.md#contents-of-the-pr), " +
"and [_requirements_](https://github.com/cncf/k8s-conformance/blob/master/instructions.md#requirements)",
},
"\n")
labels := []string{"not-conformance-product-submission", "unable-to-process"}
state := "pending"
if _, _, err := updateLabels(log, ghc, pr, prSuite, labels); err != nil {
return err
}
if err := updateComments(log, ghc, pr, prSuite, finalComment); err != nil {
return err
}
if err := updateStatus(log, ghc, pr, prSuite, state); err != nil {
return err
}
return nil
}

if err := prSuite.ItIsAValidAndSupportedRelease(); err != nil {
finalComment := err.Error()
finalComment = fmt.Sprintf("%v.", strings.ToUpper(finalComment[:1])+finalComment[1:])
Expand Down
34 changes: 27 additions & 7 deletions internal/plugin/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (f *FakeGitHubClient) GetCombinedStatus(org, repo, ref string) (*github.Com
if string(f.PopulatedPullRequests[i].PullRequestQuery.Repository.Owner.Login) == org &&
string(f.PopulatedPullRequests[i].PullRequestQuery.Repository.Name) == repo {
sha = f.PopulatedPullRequests[i].HeadRefOID
state = f.PopulatedPullRequests[i].Status.Context
state = f.PopulatedPullRequests[i].Status.State
break
}
}
Expand Down Expand Up @@ -762,6 +762,9 @@ func Test_handle(t *testing.T) {
Labels: []string{"conformance-product-submission"},
KubernetesVersion: common.Pointer("v1.30"),
KubernetesVersionLatest: common.Pointer("v1.30"),
ExpectedComment: "have passed for the submission",
ExpectedStatus: "success",
ExpectedLabels: []string{"conformance-product-submission", "tests-verified-v1.30", "no-failed-tests-v1.30", "release-v1.30", "release-documents-checked"},
SupportingFiles: []*suite.PullRequestFile{
{
Name: "v1.30/coolkube/README.md",
Expand Down Expand Up @@ -791,7 +794,7 @@ contact_email_address: "[email protected]"`,
{
Name: "v1.30/coolkube/e2e.log",
BaseName: "e2e.log",
Contents: "",
Contents: "12345",
BlobURL: "e2e.log",
},
{
Expand All @@ -802,7 +805,8 @@ contact_email_address: "[email protected]"`,
},
},
PullRequestQuery: &suite.PullRequestQuery{
Title: githubql.String("Conformance results for v1.30/coolkube"),
Title: githubql.String("Conformance results for v1.30/coolkube"),
Number: githubql.Int(0),
Commits: struct {
Nodes []struct {
Commit struct {
Expand Down Expand Up @@ -906,8 +910,10 @@ contact_email_address: "[email protected]"`,
},
ExpectedComment: "The release version v1.57 is unable to be processed at this time; Please wait as this version may become available soon.",
ExpectedError: "unable to process release file as it is missing for release v1.57",
ExpectedLabels: []string{"conformance-product-submission", "unable-to-process"},
PullRequestQuery: &suite.PullRequestQuery{
Title: githubql.String("Conformance results for v1.57/coolkube"),
Title: githubql.String("Conformance results for v1.57/coolkube"),
Number: githubql.Int(0),
Commits: struct {
Nodes []struct {
Commit struct {
Expand Down Expand Up @@ -970,6 +976,9 @@ contact_email_address: "[email protected]"`,
PullRequestQuery: &suite.PullRequestQuery{
Title: githubql.String("soup recipes for winter"),
},
ExpectedComment: "This pull request appears to not be a conformance results submission; Checks will not run.",
ExpectedLabels: []string{"not-conformance-product-submission", "unable-to-process"},
ExpectedStatus: "pending",
},
} {
t.Run(tc.Name, func(t *testing.T) {
Expand Down Expand Up @@ -1026,16 +1035,27 @@ contact_email_address: "[email protected]"`,
}
if tc.ExpectedComment != "" {
found := false
got := ""
for _, comment := range ghc.PopulatedPullRequests[tc.PullRequestQuery.Number].Comments {
if comment.Body == tc.ExpectedComment {
if strings.Contains(comment.Body, tc.ExpectedComment) {
got = comment.Body
found = true
}
}
if !found {
t.Fatalf("unable to find expected comment: %v", tc.ExpectedComment)
t.Fatalf("unexpected comment: want = %v; got %v", tc.ExpectedComment, got)
}
}
// TODO check labels and status
if want, got := tc.ExpectedStatus, ghc.PopulatedPullRequests[tc.PullRequestQuery.Number].Status.State; want != "" && want != got {
t.Fatalf("unexpected status: want = %v; got = %v", want, got)
}
prLabels := []string{}
for _, l := range ghc.PopulatedPullRequests[tc.PullRequestQuery.Number].PullRequestQuery.Labels.Nodes {
prLabels = append(prLabels, string(l.Name))
}
if !reflect.DeepEqual(tc.ExpectedLabels, prLabels) {
t.Fatalf("unexpected labels: want = %v; got = %v", tc.ExpectedLabels, prLabels)
}
})
}
}
Expand Down
Loading