Skip to content

Commit

Permalink
Refactor README.md file, add new install option, add version flag (#9)
Browse files Browse the repository at this point in the history
* Add functionality to print binary version via `--version` flag

// Print full version
$ codeowners-validator -v
version.Info{Version:"0.1.1", GitCommit:"b0e711f", BuildDate:"2019-11-13T08:15:18Z", GoVersion:"go1.13.3", Compiler:"gc", Platform:"darwin/amd64"}

// Print just the version number
$ codeowners-validator -v --short
Version: 0.1.1

* Add new install option via script, refactor README.md file
  • Loading branch information
mszostok authored Nov 13, 2019
1 parent 610e91c commit 886bf72
Show file tree
Hide file tree
Showing 53 changed files with 6,468 additions and 42 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
scripts/
.idea
codeowners-validator
dist/
2 changes: 2 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ builds:
goarch:
- 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}}
archive:
replacements:
darwin: Darwin
Expand Down
9 changes: 9 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

109 changes: 71 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,57 +7,90 @@

The Codeowners Validator project validates the GitHub [CODEOWNERS](https://help.github.com/articles/about-code-owners/) file. It supports private GitHub repositories and GitHub Enterprise installations.

Executed checks:
* [x] [EXPERIMENTAL] Find unowned files (owners not specified for given files)
* [x] Find duplicated patterns
* [x] Find files/directories that do not exist in a given repository
* [x] Validate owners:
* [x] check if the owner definition is valid (is either a GitHub user name, an organization team name, or an email address)
* [x] check if a GitHub owner has a GitHub account
* [x] check if a GitHub owner is in a given organization
* [x] check if an organization team exists

## Local Installation

`env GO111MODULE=off go get -u github.com/mszostok/codeowners-validator`
![usage](./docs/assets/usage.png)

## Usage
## Installation

![usage](./docs/assets/usage.png)
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).

#### 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/master/install.sh| sh -s v0.1.1

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

# In alpine linux (as it does not come with curl by default)
wget -O - -q https://raw.githubusercontent.com/mszostok/codeowners-validator/master/install.sh| sh -s v0.2.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.

#### From Sources

You can install `codeowners-validator` with `env GO111MODULE=off go get -u github.com/mszostok/codeowners-validator`.

> NOTE: please use the latest go to do this, ideally go 1.12 or greater.
This will put `codeowners-validator` in `$(go env GOPATH)/bin`

## Checks

The following checks are enabled by default:

| Name | Description |
|------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| duppatterns | **[Duplicated Pattern Checker]** <br /><br /> Reports if CODEOWNERS file contain duplicated lines with the same file pattern. |
| files | **[File Exist Checker]** <br /><br /> Reports if CODEOWNERS file contain lines with the file pattern that do not exist in a given repository. |
| owners | **[Valid Owner Checker]** <br /><br /> Reports if CODEOWNERS file contain invalid owners definition. Allowed owner syntax: `@username`, `@org/team-name` or `[email protected]` <br /> _source: https://help.github.com/articles/about-code-owners/#codeowners-syntax_. <br /> <br /> **Checks:** <br /> &#x09; 1. Check if the owner's definition is valid (is either a GitHub user name, an organization team name or an email address). <br /><br /> 2. Check if a GitHub owner has a GitHub account <br /><br /> 3. Check if a GitHub owner is in a given organization <br /> <br />4. Check if an organization team exists |

The experimental checks are disabled by default:

| Name | Description |
|----------|---------------------------------------------------------------------------------------------------------------------------------------------|
| notowned | **[Not Owned File Checker]** <br /><br /> Reports if a given repository contain files that do not have specified owners in CODEOWNERS file. |

To enable experimental check set `EXPERIMENTAL_CHECKS=notowned` environment variable.

Check the [Usage](#usage) section for more info on how to enable and configure given checks.

## Usage

Use the following environment variables to configure the application:

| Name | Required | Default | Description |
|-----|:---------:|:--------|:------------|
| **REPOSITORY_PATH** | Yes | | The repository path to your repository on your local machine. |
| **GITHUB_ACCESS_TOKEN** | No | | The GitHub access token. Instruction for creating token can be found [here](https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/#creating-a-token). If not provided then validating owners functionality could not work properly, e.g. you can reach the API calls quota or if you are setting GitHub Enterprise base URL then an unauthorized error can occur. |
| **GITHUB_BASE_URL** | No | https://api.github.com/ | The GitHub base URL for API requests. Defaults to the public GitHub API, but can be set to a domain endpoint to use with GitHub Enterprise. |
| **GITHUB_UPLOAD_URL** | No | https://uploads.github.com/ | The GitHub upload URL for uploading files. <br> <br>It is taken into account only when the `GITHUB_BASE_URL` is also set. If only the `GITHUB_BASE_URL` is provided then this parameter defaults to the `GITHUB_BASE_URL` value. |
| **CHECKS** | No | - | The list of checks that will be executed. By default the all checks are executed. Possible values: `files`,`owner`,`duppattern` |
| **EXPERIMENTAL_CHECKS** | No | - | The comma separated list of experimental checks that should be executed. By default all experimental checks are turn off. Possible values: `owners`.|
| **CHECK_FAILURE_LEVEL** | No | `warning` | Defines the level on which the application should treat check issues as failures. Defaults to `warning`, which treats both errors and warnings as failures, and exits with error code 3. Possible values are: `error` and `warning`. |
| **OWNER_CHECKER_ORGANIZATION_NAME** | Yes | | The organization name where the repository is created. Used to check if GitHub owner is in the given organization. |
| **NOT_OWNED_CHECKER_SKIP_PATTERNS** | No | - | The comma-separated list of patterns that should be ignored by `not-owned-checker`. For example, you can specify `*` and as a result, the `*` pattern from the **CODEOWNERS** file will be ignored and files owned by this pattern will be reported as unowned unless a later specific pattern will match that path. It's useful because often we have default owners entry at the begging of the CODOEWNERS file, e.g. `* @global-owner1 @global-owner2` |
| Name | Default | Description |
|-----|:--------|:------------|
| <tt>REPOSITORY_PATH</tt> <b>*</b> | | The repository path to your repository on your local machine. |
| <tt>GITHUB_ACCESS_TOKEN</tt>| | The GitHub access token. Instruction for creating a token can be found [here](https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/#creating-a-token). If not provided then validating owners functionality could not work properly, e.g. you can reach the API calls quota or if you are setting GitHub Enterprise base URL then an unauthorized error can occur. |
| <tt>GITHUB_BASE_URL</tt>| https://api.github.com/ | The GitHub base URL for API requests. Defaults to the public GitHub API, but can be set to a domain endpoint to use with GitHub Enterprise. |
| <tt>GITHUB_UPLOAD_URL</tt> | https://uploads.github.com/ | The GitHub upload URL for uploading files. <br> <br>It is taken into account only when the `GITHUB_BASE_URL` is also set. If only the `GITHUB_BASE_URL` is provided then this parameter defaults to the `GITHUB_BASE_URL` value. |
| <tt>CHECKS</tt>| - | The list of checks that will be executed. By default, all checks are executed. Possible values: `files`,`owners`,`duppatterns` |
| <tt>EXPERIMENTAL_CHECKS</tt> | - | The comma-separated list of experimental checks that should be executed. By default, all experimental checks are turned off. Possible values: `notowned`.|
| <tt>CHECK_FAILURE_LEVEL</tt> | `warning` | Defines the level on which the application should treat check issues as failures. Defaults to `warning`, which treats both errors and warnings as failures, and exits with error code 3. Possible values are `error` and `warning`. |
| <tt>OWNER_CHECKER_ORGANIZATION_NAME</tt> <b>*</b>| | The organization name where the repository is created. Used to check if GitHub owner is in the given organization. |
| <tt>NOT_OWNED_CHECKER_SKIP_PATTERNS</tt>| - | The comma-separated list of patterns that should be ignored by `not-owned-checker`. For example, you can specify `*` and as a result, the `*` pattern from the **CODEOWNERS** file will be ignored and files owned by this pattern will be reported as unowned unless a later specific pattern will match that path. It's useful because often we have default owners entry at the begging of the CODOEWNERS file, e.g. `* @global-owner1 @global-owner2` |

<b>*</b> - Required

### Exit status codes
#### Exit status codes

Application exits with different status codes which allow you to easily distinguish between error categories.

| Code | Description |
|:-----:|:------------|
| **1** | The application startup failed due to wrong configuration or internal error. |
| **2** | The application was closed because the OS sends termination signal (SIGINT or SIGTERM). |
| **1** | The application startup failed due to the wrong configuration or internal error. |
| **2** | The application was closed because the OS sends a termination signal (SIGINT or SIGTERM). |
| **3** | The CODEOWNERS validation failed - executed checks found some issues. |

## Roadmap

_Sorted with priority. First - most important._
The [codeowners-validator roadmap uses Github milestones](https://github.com/mszostok/codeowners-validator/milestones) to track the progress of the project.

* [ ] Possibility to execute validator online. Automatically integrates with your GitHub account and allows you to check any repository online without the need to download and execute binary locally.
* [ ] Possibility to use the GitHub URL instead of the path to the local repository.
* [ ] Offline mode - execute all checks which not require internet connection against your local repository
* [ ] Investigate the [Go Plugins](https://golang.org/pkg/plugin/). Implement if it will simplify extending this tool with other checks.
* [ ] Move to [cobra](https://github.com/spf13/cobra/) library.
* [ ] Add test coverage.
* [ ] Add support for configuration via YAML file.
* [ ] Move dep to go modules
Issues with the `priority/important-longterm` label will be implemented as the first one.
Binary file modified docs/assets/usage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion hack/ci/run-lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ golangci::run_checks() {

ENABLE=$(sed 's/ /,/g' <<< "${LINTS[@]}")

golangci-lint --disable-all --enable="${ENABLE}" run
golangci-lint --disable-all --enable="${ENABLE}" run ./...

echo -e "${GREEN}√ run golangci-lint${NC}"
}
Expand Down
Loading

0 comments on commit 886bf72

Please sign in to comment.