Skip to content

Commit

Permalink
Merge pull request #28 from Adirio/cleanup
Browse files Browse the repository at this point in the history
🌱 Organize verify directory
  • Loading branch information
k8s-ci-robot committed Dec 3, 2020
2 parents 09382ff + 9f8cedc commit 7259830
Show file tree
Hide file tree
Showing 13 changed files with 516 additions and 386 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Expand Up @@ -6,7 +6,7 @@ COPY notes notes
WORKDIR /go/src/verify/verify

ENV CGO_ENABLED=0
RUN go build -o /go/bin/verifypr ./cmd/
RUN go build -o /go/bin/verifypr ./

FROM gcr.io/distroless/static-debian10

Expand Down
7 changes: 4 additions & 3 deletions README.md
Expand Up @@ -46,9 +46,10 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN }}
```

The code that actually runs lives in [verify/cmd](/verify/cmd), while
[/verify](/verify) contains a framework for running PR description checks
from GitHub actions & uploading the result via the GitHub checks API.
The code that actually runs lives in [verify](/verify), while
[/verify/pkg/action](/verify/pkg/action) contains a framework for running PR
description checks from GitHub actions & uploading the result via the GitHub
checks API.

This repo itself uses a "live" version of the action that always rebuilds
from the local code (master branch), which lives in
Expand Down
67 changes: 0 additions & 67 deletions notes/verify/title.go

This file was deleted.

91 changes: 0 additions & 91 deletions verify/cmd/runner.go

This file was deleted.

53 changes: 53 additions & 0 deletions verify/descriptiveness.go
@@ -0,0 +1,53 @@
/*
Copyright 2020 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

import (
"strings"

"github.com/google/go-github/v32/github"

"sigs.k8s.io/kubebuilder-release-tools/verify/pkg/action"
)

type prDescriptivenessError struct{}

func (e prDescriptivenessError) Error() string {
return "Your PR description is *really* short."
}
func (e prDescriptivenessError) Details() string {
return `It probably isn't descriptive enough.
You should give a description that highlights both what you're doing it and *why* you're doing it.
Someone reading the PR description without clicking any issue links should be able to roughly understand what's going on.`
}

// checkPRDescriptiveness
func checkPRDescriptiveness(requiredLines int) action.ValidateFunc {
return func(pr *github.PullRequest) (string, string, error) {
lineCnt := 0
for _, line := range strings.Split(pr.GetBody(), "\n") {
if strings.TrimSpace(line) == "" {
continue
}
lineCnt++
}
if lineCnt < requiredLines {
return "", "", &prDescriptivenessError{}
}
return "Your PR looks descriptive enough!", "", nil
}
}
50 changes: 50 additions & 0 deletions verify/issue.go
@@ -0,0 +1,50 @@
/*
Copyright 2020 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

import (
"fmt"
"regexp"

"github.com/google/go-github/v32/github"

notes "sigs.k8s.io/kubebuilder-release-tools/notes/common"
)

var tagRegexp = regexp.MustCompile(`#\d+\b`)

type prIssueInTitleError struct{}

func (e prIssueInTitleError) Error() string {
return "Your PR has an Issue or PR number in the title."
}
func (e prIssueInTitleError) Details() string {
return fmt.Sprintf(`The title should just be descriptive.
Issue numbers belong in the PR body as either %#q (if it closes the issue or PR), or something like %#q (if it's just related).`,
"Fixes #XYZ", "Related to #XYZ",
)
}

// checkIssueInTitle verifies that the PR title does not contain any Issue or PR tag
func checkIssueInTitle(pr *github.PullRequest) (string, string, error) {
_, title := notes.PRTypeFromTitle(pr.GetTitle())
if tagRegexp.MatchString(title) {
return "", "", prIssueInTitleError{}
}

return "Your PR title does not contain any Issue or PR tags", "", nil
}
41 changes: 41 additions & 0 deletions verify/main.go
@@ -0,0 +1,41 @@
/*
Copyright 2020 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

import (
"sigs.k8s.io/kubebuilder-release-tools/verify/pkg/action"
)

func main() {
action.New(
action.NewPlugin(
"PR Type",
"PR Type in Title",
verifyPRType,
),
action.NewPlugin(
"PR Issue",
"Issue/PR tag in PR title",
checkIssueInTitle,
),
action.NewPlugin(
"PR Desc",
"Basic PR Descriptiveness Check",
checkPRDescriptiveness(2),
),
).Run()
}

0 comments on commit 7259830

Please sign in to comment.