hmarr / codeowners Goto Github PK
View Code? Open in Web Editor NEW๐ Command line tool and Go library for CODEOWNERS files
License: MIT License
๐ Command line tool and Go library for CODEOWNERS files
License: MIT License
(This issue is not a problem report.)
Thank you for publishing this tool!
We use this very conveniently.
I'd like to share an example that demonstrates how to report the precise changes made to a CODEOWNERS file within a pull request, which could potentially be useful to others. As you may already be aware, interpreting .github/CODEOWNERS can be quite intricate.
To simplify this process, I've crafted a GitHub Action that provides detailed insights into which files are specifically affected by modifications to .github/CODEOWNERS.
# .github/workflows/post-codeowners-result-diff.yml
name: post-codeowners-result-diff
on:
pull_request:
paths:
- .github/CODEOWNERS
- .github/workflows/post-codeowners-result-diff.yml
jobs:
post-codeowners-result-diff:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
timeout-minutes: 10
steps:
- name: setup codeowners
run: |
mkdir /opt/bin
curl -sL "https://github.com/hmarr/codeowners/releases/download/v${CODEOWNERS_VERSION}/codeowners_${CODEOWNERS_VERSION}_linux_amd64.tar.gz" -o /tmp/codeowners.tar.gz
hash=$(sha256sum /tmp/codeowners.tar.gz | awk '{ print $1 }')
if [ "$hash" = "e69a42a4a28efd58a87a0dc0d8f32223c1f6ccda7954afd40108abf98517a13f" ]; then
cat /tmp/codeowners.tar.gz | tar zfx - -C /opt/bin
else
echo $hash
echo invalid
exit 1
fi
env:
CODEOWNERS_VERSION: 1.1.2
- uses: actions/checkout@v3
with:
ref: ${{ github.base_ref }}
- name: call codeowners command on github.base_ref
run: |
/opt/bin/codeowners > /tmp/result.1
- uses: actions/checkout@v3
with:
ref: ${{ github.ref }}
- name: call codeowners command on github.ref
run: |
/opt/bin/codeowners > /tmp/result.2
- name: make report file
run: |
echo '<details><summary>codeowners diff report (.github/workflows/post-codeowners-result-diff.yml)</summary>' > /tmp/diffs
echo '' >> /tmp/diffs
echo '```diff' >> /tmp/diffs
diff -u /tmp/result.1 /tmp/result.2 >> /tmp/diffs | true
echo '```' >> /tmp/diffs
echo '' >> /tmp/diffs
echo '</details>' >> /tmp/diffs
- name: post comment
uses: marocchino/sticky-pull-request-comment@v2
with:
hide_and_recreate: true
header: report
path: /tmp/diffs
This action will add a report comment like the one below when a pullrequest is opened that modifies .github/CODEOWNERS.
Now, armed with this handy diff report, you can tweak .github/CODEOWNERS with confidence, no more guesswork involved!
Anyway, big thanks for making all of this possible!
When running codeowners
on a typical git repository, many files are printed which are actually not part of the repository because of .gitignore
. Is that correct behavior? Would you consider that to be an improvement if this tool respects (and parses?) .gitignore
if present?
-o ''
shows all
Correct
*.go @user
*.go @zhilyaev
Not Correct.
*.go @firstname.lastname
*.go @dmitrii.zhiliaev
invalid owner format '@dmitrii.zhiliaev' at position 6
Hello!
I noticed some issues running this library on Windows. Using os.PathSeparator
here converts this path /test/public
into this regexp "\\Atest\\public\\.*\\z"
and this makes the regexp.Compile
function return this error:
error parsing regexp: invalid character class range: `\pu`
This specific issue can be fixed by always using /
as a separator but I don't know if it introduces errors in other functions.
According to https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners it is valid to have a line in CODEOWNERS
where no owner is listed. This is interpreted as the file not being owned. Quoting from that link:
# In this example, @octocat owns any file in the `/apps`
# directory in the root of your repository except for the `/apps/github`
# subdirectory, as its owners are left empty.
/apps/ @octocat
/apps/github
codeowners
currently doesn't handle this and in stead reports:
line 1: unexpected end of rule
I tried patching, but I'm not really a proficient in go sadly.
Hey team!
I've noticed that the current rules parser assumes that the owner will always be assigned to a corresponding file path. However, there are some situations when a specific owner is not required and ownership is not defined.
An example of such a file path could be an auto-updated or autogenerated code that is indexed for some reason. A more concrete example is all strings.xml
files in an Android project that are auto-translated and added to a project by a bot on a periodic basis. This kind of change does not require any individuals or teams to verify the change, hence the CODEOWNERS pattern is redundant.
Setting no owner for file path in the CODEOWNERS file seems to be an undocumented feature in GitHub. First discovered in this article and then verified to be a working solution by using the built-in Github validator.
I believe that the current implementation of the parser expects owners to always be specified. I'm keen to understand if you would be open to making this rule parametrisable?
Example of codeowner file:
* @group-x/subgroup-y/subgroup-z
throws invalid owner format '@group-x/subgroup-y/subgroup-z' at position 3
Gitlab docs:
https://docs.gitlab.com/ee/user/project/codeowners/#add-a-group-as-a-code-owner
Also doesn't work when given absolute path to file
Ideally, codeowners
should be agnostic to the relative positioning of the current directory, the repo root, and the file path(s) to evaluate.
I've just noticed that this project parses the codeowners file incorrectly according to Github's specification (examples), given the following lines:
* user-a
src/* user-b
Then the file at src/foo/bar.js
should actually be owned by user-a
, this is because of this logic:
# In this example, @doctocat owns any files in the build/logs
# directory at the root of the repository and any of its
# subdirectories.
/build/logs/ @doctocat
# The `docs/*` pattern will match files like
# `docs/getting-started.md` but not further nested files like
# `docs/build-app/troubleshooting.md`.
docs/* [email protected]
Essentially the /*
only matches direct descendants, not all descendants of a directory. This logic is the same for Gitlab too.
The Gitlab documentation allows to introduce sections into the CODEOWNERS
such as
[README Owners]
README.md @user1 @user2
internal/README.md @user2
That enables Gitlab to show the code ownership within the UI a little bit nicer. Currently, running this tool (version 1.1.1) on such a file leads to the following error:
$ codeowners
line 1: unexpected character '[' at position 1
Would you be willing to allow support for this? Would you accept a PR for that (I haven't looked into the code yet though)
Hello!
This is a nice utility! It would be extremely useful to have a command line argument that given a file path to print the associated codeowners.
Title says it all.
If you run codeowners ./src/file.go
it will always hit a *
rule, or just (unowned)
if there is no *
rule.
Whereas codeowners src/file.go
will correctly match a rule that covers this file/directory.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.