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

🌱 Organize verify directory #28

Merged
merged 1 commit into from
Dec 3, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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()
}