generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
516 additions
and
386 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
Oops, something went wrong.