-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow unowned patterns by default with an option to change it (#113)
- Loading branch information
Showing
17 changed files
with
146 additions
and
96 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,32 +109,33 @@ The experimental checks are disabled by default: | |
|----------|---------------------------------------------------------------------------------------------------------------------------------------------| | ||
| 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. | ||
To enable experimental check set `EXPERIMENTAL_CHECKS=notowned` environment variable. | ||
|
||
Check the [Configuration](#configuration) section for more info on how to enable and configure given checks. | ||
|
||
## Configuration | ||
|
||
Use the following environment variables to configure the application: | ||
|
||
| Name | Default | Description | | ||
|-----|:--------|:------------| | ||
| <tt>REPOSITORY_PATH</tt> <b>*</b> | | Path to your repository on your local machine. | | ||
| <tt>GITHUB_ACCESS_TOKEN</tt>| | GitHub access token. Instruction for creating a token can be found [here](./docs/gh-token.md). If not provided, the owners validating functionality may not work properly. For example, you may reach the API calls quota or, if you are setting GitHub Enterprise base URL, an unauthorized error may occur. | | ||
| <tt>GITHUB_BASE_URL</tt>| https://api.github.com/ | 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/ | GitHub upload URL for uploading files. <br> <br>It is taken into account only when `GITHUB_BASE_URL` is also set. If only `GITHUB_BASE_URL` is provided, this parameter defaults to the `GITHUB_BASE_URL` value. | | ||
| <tt>CHECKS</tt>| - | List of checks to be executed. By default, all checks are executed. Possible values: `files`,`owners`,`duppatterns`,`syntax`. | | ||
| <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_REPOSITORY</tt> <b>*</b>| | The owner and repository name separated by slash. For example, gh-codeowners/codeowners-samples. Used to check if GitHub owner is in the given organization. | | ||
| <tt>OWNER_CHECKER_IGNORED_OWNERS</tt> | `@ghost`| The comma-separated list of owners that should not be validated. Example: `"@owner1,@owner2,@org/team1,[email protected]"`. | | ||
| <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` | | ||
| Name | Default | Description | | ||
|------------------------------------------------|:--------|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ||
| <tt>REPOSITORY_PATH</tt> <b>*</b> | | Path to your repository on your local machine. | | ||
| <tt>GITHUB_ACCESS_TOKEN</tt> | | GitHub access token. Instruction for creating a token can be found [here](./docs/gh-token.md). If not provided, the owners validating functionality may not work properly. For example, you may reach the API calls quota or, if you are setting GitHub Enterprise base URL, an unauthorized error may occur. | | ||
| <tt>GITHUB_BASE_URL</tt> | `https://api.github.com/` | 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/` | GitHub upload URL for uploading files. <br> <br>It is taken into account only when `GITHUB_BASE_URL` is also set. If only `GITHUB_BASE_URL` is provided, this parameter defaults to the `GITHUB_BASE_URL` value. | | ||
| <tt>CHECKS</tt> | - | List of checks to be executed. By default, all checks are executed. Possible values: `files`,`owners`,`duppatterns`,`syntax`. | | ||
| <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_REPOSITORY</tt> <b>*</b> | | The owner and repository name separated by slash. For example, gh-codeowners/codeowners-samples. Used to check if GitHub owner is in the given organization. | | ||
| <tt>OWNER_CHECKER_IGNORED_OWNERS</tt> | `@ghost`| The comma-separated list of owners that should not be validated. Example: `"@owner1,@owner2,@org/team1,[email protected]"`. | | ||
| <tt>OWNER_CHECKER_ALLOW_UNOWNED_PATTERNS</tt> | `true` | Specifies whether CODEOWNERS may have unowned files. For example: <br> <br> `/infra/oncall-rotator/ @sre-team` <br> `/infra/oncall-rotator/oncall-config.yml` <br> <br> The `/infra/oncall-rotator/oncall-config.yml` file is not owned by anyone. | | ||
| <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 | ||
|
||
Application exits with different status codes which allow you to easily distinguish between error categories. | ||
Application exits with different status codes which allow you to easily distinguish between error categories. | ||
|
||
| Code | Description | | ||
|:-----:|:------------| | ||
|
@@ -144,7 +145,7 @@ Application exits with different status codes which allow you to easily distingu | |
|
||
## Contributing | ||
|
||
Contributions are greatly appreciated! The project follows the typical GitHub pull request model. See [CONTRIBUTING.md](CONTRIBUTING.md) for more details. | ||
Contributions are greatly appreciated! The project follows the typical GitHub pull request model. See [CONTRIBUTING.md](CONTRIBUTING.md) for more details. | ||
|
||
## Roadmap | ||
|
||
|
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 |
---|---|---|
|
@@ -47,6 +47,11 @@ inputs: | |
description: "The comma-separated list of owners that should not be validated. Example: @owner1,@owner2,@org/team1,[email protected]." | ||
required: false | ||
|
||
owner_checker_allow_unowned_patterns: | ||
description: "Specifies whether CODEOWNERS may have unowned files. For example, `/infra/oncall-rotator/oncall-config.yml` doesn't have owner and this is not reported." | ||
default: "true" | ||
required: false | ||
|
||
runs: | ||
using: 'docker' | ||
image: 'docker://mszostok/codeowners-validator:v0.6.0' | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ func TestDuplicatedPattern(t *testing.T) { | |
"Should report info about duplicated entries": { | ||
codeownersInput: ` | ||
* @global-owner1 @global-owner2 | ||
/build/logs/ @doctocat | ||
/build/logs/ @doctocat | ||
|
@@ -29,21 +29,21 @@ func TestDuplicatedPattern(t *testing.T) { | |
{ | ||
Severity: check.Error, | ||
LineNo: nil, | ||
Message: `Pattern "/build/logs/" is defined 2 times in lines: | ||
Message: `Pattern "/build/logs/" is defined 2 times in lines: | ||
* 4: with owners: [@doctocat] | ||
* 5: with owners: [@doctocat]`, | ||
}, | ||
{ | ||
Severity: check.Error, | ||
LineNo: nil, | ||
Message: `Pattern "/script" is defined 2 times in lines: | ||
Message: `Pattern "/script" is defined 2 times in lines: | ||
* 7: with owners: [@mszostok] | ||
* 8: with owners: [[email protected]]`, | ||
}, | ||
}, | ||
}, | ||
"Should not report any issues with correct CODEOWNERS file": { | ||
codeownersInput: check.FixtureValidCODEOWNERS, | ||
codeownersInput: FixtureValidCODEOWNERS, | ||
expectedIssues: nil, | ||
}, | ||
} | ||
|
@@ -54,7 +54,7 @@ func TestDuplicatedPattern(t *testing.T) { | |
sut := check.NewDuplicatedPattern() | ||
|
||
// when | ||
out, err := sut.Check(context.TODO(), check.LoadInput(tc.codeownersInput)) | ||
out, err := sut.Check(context.TODO(), LoadInput(tc.codeownersInput)) | ||
|
||
// then | ||
require.NoError(t, err) | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
package check | ||
package check_test | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/mszostok/codeowners-validator/internal/check" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/mszostok/codeowners-validator/pkg/codeowners" | ||
) | ||
|
@@ -20,10 +25,21 @@ var FixtureValidCODEOWNERS = ` | |
/script [email protected] | ||
` | ||
|
||
func LoadInput(in string) Input { | ||
func LoadInput(in string) check.Input { | ||
r := strings.NewReader(in) | ||
|
||
return Input{ | ||
return check.Input{ | ||
CodeownersEntries: codeowners.ParseCodeowners(r), | ||
} | ||
} | ||
|
||
func assertIssue(t *testing.T, expIssue *check.Issue, gotIssues []check.Issue) { | ||
t.Helper() | ||
|
||
if expIssue != nil { | ||
require.Len(t, gotIssues, 1) | ||
assert.EqualValues(t, *expIssue, gotIssues[0]) | ||
} else { | ||
assert.Empty(t, gotIssues) | ||
} | ||
} |
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package check | ||
|
||
func IsValidOwner(owner string) bool { | ||
return isEmailAddress(owner) || isGithubUser(owner) || isGithubTeam(owner) | ||
} |
Oops, something went wrong.