Skip to content

Commit a59e275

Browse files
committed
UPSTREAM: <carry>: add commitchecker
Signed-off-by: dtfranz <[email protected]>
1 parent 1510df3 commit a59e275

File tree

7 files changed

+661
-0
lines changed

7 files changed

+661
-0
lines changed

openshift/Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,14 @@ manifests: $(KUSTOMIZE) $(YQ)
1414
.PHONY: verify-manifests
1515
verify-manifests: manifests
1616
git diff --exit-code
17+
18+
COMMITCHECKER := $(DIR)/bin/commitchecker
19+
20+
.PHONY: commitchecker
21+
$(COMMITCHECKER):
22+
mkdir -p $(DIR)/bin
23+
cd $(DIR) && go build -o $(COMMITCHECKER) ./commitchecker
24+
25+
.PHONY: verify-commits
26+
verify-commits: $(COMMITCHECKER)
27+
$(COMMITCHECKER) -start $(shell echo $${PULL_BASE_SHA:-main})

openshift/commitchecker/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Initial code copied
2+
from https://github.com/openshift/kubernetes/tree/0abcd84431df81ed9f2a1846b5045e46d9032cc1/openshift-hack/commitchecker.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"fmt"
6+
"os"
7+
)
8+
9+
func main() {
10+
var start, end string
11+
flag.StringVar(&start, "start", "master", "The start of the revision range for analysis")
12+
flag.StringVar(&end, "end", "HEAD", "The end of the revision range for analysis")
13+
flag.Parse()
14+
15+
commits, err := CommitsBetween(start, end)
16+
if err != nil {
17+
if err == ErrNotCommit {
18+
_, _ = fmt.Fprintf(os.Stderr, "WARNING: one of the provided commits does not exist, not a true branch\n")
19+
os.Exit(0)
20+
}
21+
_, _ = fmt.Fprintf(os.Stderr, "ERROR: couldn't find commits from %s..%s: %v\n", start, end, err)
22+
os.Exit(1)
23+
}
24+
25+
var errs []string
26+
for _, validate := range AllCommitValidators {
27+
for _, commit := range commits {
28+
errs = append(errs, validate(commit)...)
29+
}
30+
}
31+
32+
if len(errs) > 0 {
33+
for _, e := range errs {
34+
_, _ = fmt.Fprintf(os.Stderr, "%s\n\n", e)
35+
}
36+
37+
os.Exit(2)
38+
}
39+
}

0 commit comments

Comments
 (0)