Skip to content

Commit

Permalink
lint: Add commit/PR body linter for epic and issue refs
Browse files Browse the repository at this point in the history
Before: Commits and PRs would inconsistently contain references to issues.
Sometimes the author would forget to add it. Some authors might not
think to add them. And there were no epic references provided.

Why: Adding issue and epic references to PRs and commits provides
traceability and context for the revenue teams, product, management and
engineers.

Now: A new GitHub Action workflow checks for references to issues the PR
closes or informs and epics the PR is part of. It looks for references
in the PR body and in commit messages and, if it doesn't find what it
expects, it fails the check.

Release note: None

Release justification: Adding linter for epic tracking for engineering,
docs, and internal teams.
  • Loading branch information
Nick Vigilante committed Oct 4, 2022
1 parent 4780ee1 commit a7ef46a
Show file tree
Hide file tree
Showing 8 changed files with 961 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@
/pkg/cmd/gossipsim/ @cockroachdb/kv-prs
/pkg/cmd/import-tools/ @cockroachdb/dev-inf
/pkg/cmd/internal/issues/ @cockroachdb/test-eng
/pkg/cmd/lint-epic-issue-refs/ @cockroachdb/dev-inf
/pkg/cmd/mirror/ @cockroachdb/dev-inf
/pkg/cmd/prereqs/ @cockroachdb/dev-inf
/pkg/cmd/protoc-gen-gogoroach/ @cockroachdb/dev-inf
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/pr-epic-issue-ref-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Epic + Issue Ref Linter for PR Body or Commit Messages

on:
pull_request:
types: [opened, reopened, synchronize, edited]

jobs:
linter:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Bazel cache
id: bazel-cache
uses: actions/cache@v2
with:
path: |
~/.cache/bazel
key: ${{ runner.os }}-bazel-cache

- name: Install bazelisk
run: |
curl -fsSL https://github.com/bazelbuild/bazelisk/releases/download/v1.10.1/bazelisk-linux-amd64 > /tmp/bazelisk
sha256sum -c - <<EOF
4cb534c52cdd47a6223d4596d530e7c9c785438ab3b0a49ff347e991c210b2cd /tmp/bazelisk
EOF
mkdir -p "${GITHUB_WORKSPACE}/bin/"
mv /tmp/bazelisk "${GITHUB_WORKSPACE}/bin/bazel"
chmod +x "${GITHUB_WORKSPACE}/bin/bazel"
- name: Run lint
run: build/github/pr-epic-issue-ref-lint.sh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7 changes: 7 additions & 0 deletions build/github/pr-epic-issue-ref-lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

set -euo pipefail

PR_NUMBER="$(echo "$GITHUB_REF" | awk -F '/' '{print $3}')"

GITHUB_TOKEN="${GITHUB_TOKEN}" bin/bazel run //pkg/cmd/lint-epic-issue-refs:lint-epic-issue-refs "$PR_NUMBER"
5 changes: 5 additions & 0 deletions pkg/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ ALL_TESTS = [
"//pkg/cmd/github-pull-request-make:github-pull-request-make_test",
"//pkg/cmd/internal/issues:issues_test",
"//pkg/cmd/label-merged-pr:label-merged-pr_test",
"//pkg/cmd/lint-epic-issue-refs:lint-epic-issue-refs_test",
"//pkg/cmd/mirror:mirror_test",
"//pkg/cmd/prereqs:prereqs_test",
"//pkg/cmd/publish-artifacts:publish-artifacts_test",
Expand Down Expand Up @@ -927,6 +928,9 @@ GO_TARGETS = [
"//pkg/cmd/label-merged-pr:label-merged-pr",
"//pkg/cmd/label-merged-pr:label-merged-pr_lib",
"//pkg/cmd/label-merged-pr:label-merged-pr_test",
"//pkg/cmd/lint-epic-issue-refs:lint-epic-issue-refs",
"//pkg/cmd/lint-epic-issue-refs:lint-epic-issue-refs_lib",
"//pkg/cmd/lint-epic-issue-refs:lint-epic-issue-refs_test",
"//pkg/cmd/mirror:mirror",
"//pkg/cmd/mirror:mirror_lib",
"//pkg/cmd/mirror:mirror_test",
Expand Down Expand Up @@ -2321,6 +2325,7 @@ GET_X_DATA_TARGETS = [
"//pkg/cmd/import-tools:get_x_data",
"//pkg/cmd/internal/issues:get_x_data",
"//pkg/cmd/label-merged-pr:get_x_data",
"//pkg/cmd/lint-epic-issue-refs:get_x_data",
"//pkg/cmd/mirror:get_x_data",
"//pkg/cmd/prereqs:get_x_data",
"//pkg/cmd/protoc-gen-gogoroach:get_x_data",
Expand Down
33 changes: 33 additions & 0 deletions pkg/cmd/lint-epic-issue-refs/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
load("//build/bazelutil/unused_checker:unused.bzl", "get_x_data")
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test")

go_library(
name = "lint-epic-issue-refs_lib",
srcs = [
"lint_epic_issue_refs.go",
"main.go",
],
importpath = "github.com/cockroachdb/cockroach/pkg/cmd/lint-epic-issue-refs",
visibility = ["//visibility:private"],
deps = [
"@com_github_google_go_github//github",
"@com_github_spf13_cobra//:cobra",
"@org_golang_x_oauth2//:oauth2",
],
)

go_binary(
name = "lint-epic-issue-refs",
embed = [":lint-epic-issue-refs_lib"],
visibility = ["//visibility:public"],
)

go_test(
name = "lint-epic-issue-refs_test",
srcs = ["lint_epic_issue_refs_test.go"],
args = ["-test.timeout=295s"],
embed = [":lint-epic-issue-refs_lib"],
deps = ["@com_github_stretchr_testify//assert"],
)

get_x_data(name = "get_x_data")
Loading

0 comments on commit a7ef46a

Please sign in to comment.