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

get mad when someone puts in an email instead of team #2

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Ignore everything
**
#**

# Allow binary
!/codeowners-validator
#!/codeowners-validator
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Bug report
about: Report a bug in the project
title: ''
labels: bug
assignees: mszostok
assignees: stitchfix
---

<!-- Thank you for your contribution -->
Expand Down
8 changes: 4 additions & 4 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ builds:
- amd64
- 386
ldflags:
- -s -w -X github.com/mszostok/codeowners-validator/pkg/version.version={{.Version}} -X github.com/mszostok/codeowners-validator/pkg/version.commit={{.ShortCommit}} -X github.com/mszostok/codeowners-validator/pkg/version.buildDate={{.Date}}
- -s -w -X github.com/stitchfix/codeowners-validator/pkg/version.version={{.Version}} -X github.com/stitchfix/codeowners-validator/pkg/version.commit={{.ShortCommit}} -X github.com/stitchfix/codeowners-validator/pkg/version.buildDate={{.Date}}
# List of combinations of GOOS + GOARCH + GOARM to ignore.
# Default is empty.
ignore:
Expand Down Expand Up @@ -44,6 +44,6 @@ dockers:
binaries:
- codeowners-validator
image_templates:
- "mszostok/codeowners-validator:latest"
- "mszostok/codeowners-validator:{{ .Tag }}"
- "mszostok/codeowners-validator:v{{ .Major }}.{{ .Minor }}"
- "stitchfix/codeowners-validator:latest"
- "stitchfix/codeowners-validator:{{ .Tag }}"
- "stitchfix/codeowners-validator:v{{ .Major }}.{{ .Minor }}"
11 changes: 6 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
# Get latest CA certs & git
FROM alpine:3.14.2 as deps
FROM ubuntu:18.04 as deps

# hadolint ignore=DL3018
RUN apk --no-cache add ca-certificates git
RUN apt update
RUN apt install -y git

FROM scratch

LABEL source=https://github.com/mszostok/codeowners-validator.git
LABEL source=https://github.com/stitchfix/codeowners-validator.git

COPY ./codeowners-validator /codeowners-validator
COPY ./bin/codeowners-validator /codeowners-validator

COPY --from=deps /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=deps /usr/bin/git /usr/bin/git
COPY --from=deps /usr/bin/xargs /usr/bin/xargs
COPY --from=deps /lib /lib
COPY --from=deps /usr/lib /usr/lib
COPY --from=deps /usr/bin/tail /usr/bin/tail

CMD ["/codeowners-validator"]
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

## Codeowners Validator
<a href="/LICENSE"><img alt="Software License" src="https://img.shields.io/badge/license-Apache-brightgreen.svg?style=flat-square"/></a>
<a href="https://goreportcard.com/report/github.com/mszostok/codeowners-validator"><img alt="Go Report Card" src="https://goreportcard.com/badge/github.com/mszostok/codeowners-validator?style=flat-square"/></a>
<a href="https://goreportcard.com/report/github.com/stitchfix/codeowners-validator"><img alt="Go Report Card" src="https://goreportcard.com/badge/github.com/stitchfix/codeowners-validator?style=flat-square"/></a>
<a href="https://twitter.com/m_szostok"><img alt="Twitter Follow" src="https://img.shields.io/twitter/follow/m_szostok?color=a&label=Follow%20%40m_szostok%20for%20updates&style=social"></a>

The Codeowners Validator project validates the GitHub [CODEOWNERS](https://help.github.com/articles/about-code-owners/) file based on [specified checks](#checks). It supports public and private GitHub repositories and also GitHub Enterprise installations.
Expand All @@ -29,7 +29,7 @@ docker run --rm -v $(pwd):/repo -w /repo \
-e GITHUB_ACCESS_TOKEN="$GH_TOKEN" \
-e EXPERIMENTAL_CHECKS="notowned" \
-e OWNER_CHECKER_REPOSITORY="org-name/rep-name" \
mszostok/codeowners-validator:v0.6.0
stitchfix/codeowners-validator:v0.6.0
```

#### Command line
Expand All @@ -46,7 +46,7 @@ env REPOSITORY_PATH="." \
#### GitHub Action

```yaml
- uses: mszostok/[email protected]
- uses: stitchfix/[email protected]
with:
checks: "files,owners,duppatterns"
experimental_checks: "notowned"
Expand All @@ -62,31 +62,31 @@ Check the [Configuration](#configuration) section for more info on how to enable

## Installation

It's highly recommended to install a fixed version of `codeowners-validator`. Releases are available on the [releases page](https://github.com/mszostok/codeowners-validator/releases).
It's highly recommended to install a fixed version of `codeowners-validator`. Releases are available on the [releases page](https://github.com/stitchfix/codeowners-validator/releases).

#### From Release

Here is the recommended way to install `codeowners-validator`:

```bash
# binary installed into ./bin/
curl -sfL https://raw.githubusercontent.com/mszostok/codeowners-validator/main/install.sh | sh -s v0.6.0
curl -sfL https://raw.githubusercontent.com/stitchfix/codeowners-validator/main/install.sh | sh -s v0.6.0

# binary installed into $(go env GOPATH)/bin/codeowners-validator
curl -sfL https://raw.githubusercontent.com/mszostok/codeowners-validator/main/install.sh | sh -s -- -b $(go env GOPATH)/bin v0.6.0
curl -sfL https://raw.githubusercontent.com/stitchfix/codeowners-validator/main/install.sh | sh -s -- -b $(go env GOPATH)/bin v0.6.0

# In alpine linux (as it does not come with curl by default)
wget -O - -q https://raw.githubusercontent.com/mszostok/codeowners-validator/main/install.sh | sh -s v0.6.0
wget -O - -q https://raw.githubusercontent.com/stitchfix/codeowners-validator/main/install.sh | sh -s v0.6.0

# Print version. Add `--short` to print just the version number.
codeowners-validator -v
```

You can also download [latest version](https://github.com/mszostok/codeowners-validator/releases/latest) from release page manually.
You can also download [latest version](https://github.com/stitchfix/codeowners-validator/releases/latest) from release page manually.

#### From Sources

You can install `codeowners-validator` with `go install github.com/mszostok/[email protected]`.
You can install `codeowners-validator` with `go install github.com/stitchfix/[email protected]`.

> NOTE: please use Go 1.16 or greater.

Expand Down Expand Up @@ -148,6 +148,6 @@ Contributions are greatly appreciated! The project follows the typical GitHub pu

## Roadmap

The [codeowners-validator roadmap uses Github milestones](https://github.com/mszostok/codeowners-validator/milestone/1) to track the progress of the project.
The [codeowners-validator roadmap uses Github milestones](https://github.com/stitchfix/codeowners-validator/milestone/1) to track the progress of the project.

They are sorted with priority. First are most important.
19 changes: 10 additions & 9 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ inputs:
description: "The comma-separated list of owners that should not be validated. Example: @owner1,@owner2,@org/team1,[email protected]."
required: false

runs:
using: 'docker'
image: 'docker://mszostok/codeowners-validator:v0.6.0'
env:
ENVS_PREFIX: "INPUT"

branding:
icon: "shield"
color: "gray-dark"
# runs:
# using: 'docker'
# image: 'docker://histhing'

# env:
# ENVS_PREFIX: "INPUT"
# #TODO: build container separately, make new action that just uses the image.
# branding:
# icon: "shield"
# color: "gray-dark"
2 changes: 1 addition & 1 deletion docs/assets/usage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions docs/gh-action.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
</p>

##
The [Codeowners Validator](https://github.com/mszostok/codeowners-validator) is available as a GitHub Action.
The [Codeowners Validator](https://github.com/stitchfix/codeowners-validator) is available as a GitHub Action.

<p align="center">
<img src="https://raw.githack.com/mszostok/codeowners-validator/main/docs/assets/action-output.png" width="600px" alt="demo">
<img src="https://raw.githack.com/stitchfix/codeowners-validator/main/docs/assets/action-output.png" width="600px" alt="demo">
</p>


Expand All @@ -35,7 +35,7 @@ jobs:
# Checks-out your repository, which is validated in the next step
- uses: actions/checkout@v2
- name: GitHub CODEOWNERS Validator
uses: mszostok/[email protected].0
uses: stitchfix/[email protected].5
# input parameters
with:
# "The list of checks that will be executed. By default, all checks are executed. Possible values: files,owners,duppatterns,syntax"
Expand Down
2 changes: 1 addition & 1 deletion docs/investigation/file_exists_checker/glob.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This document describes investigation about [`file exists`](../../../internal/ch
A [CODEOWNERS](https://docs.github.com/en/free-pro-team@latest/github/creating-cloning-and-archiving-repositories/about-code-owners#codeowners-syntax) file uses a pattern that follows the same rules used in [gitignore](https://git-scm.com/docs/gitignore#_pattern_format) files.
The gitignore files support two consecutive asterisks ("**") in patterns that match against the full path name. Unfortunately the core Go library `filepath.Glob` does not support [`**`](https://github.com/golang/go/issues/11862) at all.

This caused that for some patterns the [`file exists`](../../../internal/check/file_exists.go) checker didn't work properly, see [issue#22](https://github.com/mszostok/codeowners-validator/issues/22).
This caused that for some patterns the [`file exists`](../../../internal/check/file_exists.go) checker didn't work properly, see [issue#22](https://github.com/stitchfix/codeowners-validator/issues/22).

Additionally, we need to support a single asterisk at the beginning of the pattern. For example, `*.js` should check for all JS files in the whole git repository. To achieve that we need to detect that and change from `*.js` to `**/*.js`.

Expand Down
2 changes: 1 addition & 1 deletion docs/investigation/file_exists_checker/go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/mszostok/codeowners-validator/docs/investigation/file_exists_checker
module github.com/stitchfix/codeowners-validator/docs/investigation/file_exists_checker

go 1.15

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/mszostok/codeowners-validator
module github.com/stitchfix/codeowners-validator

go 1.17

Expand Down
10 changes: 4 additions & 6 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ set -e
usage() {
this=$1
cat <<EOF
$this: download go binaries for mszostok/codeowners-validator
$this: download go binaries for stitchfix/codeowners-validator

Usage: $this [-b] bindir [-d] [tag]
-b sets bindir or installation directory, Defaults to ./bin
-d turns on debug logging
[tag] is a tag from
https://github.com/mszostok/codeowners-validator/releases
https://github.com/stitchfix/codeowners-validator/releases
If tag is missing, then the latest will be used.

Generated by godownloader
Expand Down Expand Up @@ -45,9 +45,7 @@ parse_args() {
execute() {
tmpdir=$(mktemp -d)
log_debug "downloading files into ${tmpdir}"
http_download "${tmpdir}/${TARBALL}" "${TARBALL_URL}"
http_download "${tmpdir}/${CHECKSUM}" "${CHECKSUM_URL}"
hash_sha256_verify "${tmpdir}/${TARBALL}" "${tmpdir}/${CHECKSUM}"
http_download "https://github.com/stitchfix/codeowners-validator/archive/refs/tags/v0.6.15.tar.gz"
srcdir="${tmpdir}"
(cd "${tmpdir}" && untar "${TARBALL}")
test ! -d "${BINDIR}" && install -d "${BINDIR}"
Expand Down Expand Up @@ -350,7 +348,7 @@ End of functions from https://github.com/client9/shlib
EOF

PROJECT_NAME="codeowners-validator"
OWNER=mszostok
OWNER=stitchfix
REPO="codeowners-validator"
BINARY=codeowners-validator
FORMAT=tar.gz
Expand Down
4 changes: 2 additions & 2 deletions internal/check/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"strings"
"sync"

"github.com/mszostok/codeowners-validator/internal/ptr"
"github.com/mszostok/codeowners-validator/pkg/codeowners"
"github.com/stitchfix/codeowners-validator/internal/ptr"
"github.com/stitchfix/codeowners-validator/pkg/codeowners"
)

type (
Expand Down
2 changes: 1 addition & 1 deletion internal/check/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package check_test
import (
"testing"

"github.com/mszostok/codeowners-validator/internal/check"
"github.com/stitchfix/codeowners-validator/internal/check"

"github.com/stretchr/testify/assert"
)
Expand Down
4 changes: 2 additions & 2 deletions internal/check/duplicated_pattern.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"
"strings"

"github.com/mszostok/codeowners-validator/internal/ctxutil"
"github.com/mszostok/codeowners-validator/pkg/codeowners"
"github.com/stitchfix/codeowners-validator/internal/ctxutil"
"github.com/stitchfix/codeowners-validator/pkg/codeowners"
)

// DuplicatedPattern validates if CODEOWNERS file does not contain
Expand Down
6 changes: 3 additions & 3 deletions internal/check/duplicated_pattern_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"testing"

"github.com/mszostok/codeowners-validator/internal/check"
"github.com/stitchfix/codeowners-validator/internal/check"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand All @@ -22,7 +22,7 @@ func TestDuplicatedPattern(t *testing.T) {
/build/logs/ @doctocat
/build/logs/ @doctocat

/script @mszostok
/script @stitchfix
/script [email protected]
`,
expectedIssues: []check.Issue{
Expand All @@ -37,7 +37,7 @@ func TestDuplicatedPattern(t *testing.T) {
Severity: check.Error,
LineNo: nil,
Message: `Pattern "/script" is defined 2 times in lines:
* 7: with owners: [@mszostok]
* 7: with owners: [@stitchfix]
* 8: with owners: [[email protected]]`,
},
},
Expand Down
2 changes: 1 addition & 1 deletion internal/check/file_exists.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"os"
"path/filepath"

"github.com/mszostok/codeowners-validator/internal/ctxutil"
"github.com/stitchfix/codeowners-validator/internal/ctxutil"

"github.com/mattn/go-zglob"
"github.com/pkg/errors"
Expand Down
4 changes: 2 additions & 2 deletions internal/check/file_exists_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"testing"
"time"

"github.com/mszostok/codeowners-validator/internal/check"
"github.com/mszostok/codeowners-validator/internal/ptr"
"github.com/stitchfix/codeowners-validator/internal/check"
"github.com/stitchfix/codeowners-validator/internal/ptr"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down
2 changes: 1 addition & 1 deletion internal/check/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package check
import (
"strings"

"github.com/mszostok/codeowners-validator/pkg/codeowners"
"github.com/stitchfix/codeowners-validator/pkg/codeowners"
)

var FixtureValidCODEOWNERS = `
Expand Down
2 changes: 1 addition & 1 deletion internal/check/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"errors"
"testing"

"github.com/mszostok/codeowners-validator/internal/check"
"github.com/stitchfix/codeowners-validator/internal/check"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down
16 changes: 10 additions & 6 deletions internal/check/valid_owner.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/mail"
"strings"

"github.com/mszostok/codeowners-validator/internal/ctxutil"
"github.com/stitchfix/codeowners-validator/internal/ctxutil"

"github.com/google/go-github/v29/github"
"github.com/pkg/errors"
Expand Down Expand Up @@ -93,7 +93,7 @@ func (v *ValidOwner) Check(ctx context.Context, in Input) (Output, error) {
}
}

return bldr.Output(), nil
return bldr.Output(), nil
}

func isEmailAddress(s string) bool {
Expand All @@ -119,16 +119,20 @@ func (v *ValidOwner) isIgnoredOwner(name string) bool {

func (v *ValidOwner) selectValidateFn(name string) func(context.Context, string) *validateError {
switch {
case isEmailAddress(name):
// TODO(mszostok): try to check if e-mail really exists
//return func(context.Context, string) *validateError { return nil }
//return newValidateError("Not a GitHub team - Email addresses are not permitted: %v", name)
return func(_ context.Context, name string) *validateError {
return newValidateError("Not valid owner definition, owner must not be an email address %q", name)
}
case isGithubUser(name):
return v.validateGithubUser
case isGithubTeam(name):
return v.validateTeam
case isEmailAddress(name):
// TODO(mszostok): try to check if e-mail really exists
return func(context.Context, string) *validateError { return nil }
default:
return func(_ context.Context, name string) *validateError {
return newValidateError("Not valid owner definition %q", name)
return newValidateError("Not valid owner definition, blah blah test test %q", name)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/check/valid_owner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"testing"

"github.com/mszostok/codeowners-validator/internal/ptr"
"github.com/stitchfix/codeowners-validator/internal/ptr"
"github.com/stretchr/testify/require"

"github.com/stretchr/testify/assert"
Expand Down
2 changes: 1 addition & 1 deletion internal/check/valid_syntax.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"regexp"
"strings"

"github.com/mszostok/codeowners-validator/internal/ctxutil"
"github.com/stitchfix/codeowners-validator/internal/ctxutil"
)

var (
Expand Down
Loading