GithubHelp home page GithubHelp logo

hmarr / codeowners Goto Github PK

View Code? Open in Web Editor NEW
144.0 4.0 14.0 56 KB

๐Ÿ”’ Command line tool and Go library for CODEOWNERS files

License: MIT License

Makefile 0.20% Go 99.80%
codeowners cli go

codeowners's People

Contributors

hmarr avatar irotem avatar justincampbell avatar obukhov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

codeowners's Issues

Example use case: `on: pullrequest` github action

(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.

image-image

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!

Respect .gitignore

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?

[bug] failed for users with dot

Correct

*.go @user
*.go @zhilyaev

Not Correct.

*.go @firstname.lastname
*.go @dmitrii.zhiliaev

invalid owner format '@dmitrii.zhiliaev' at position 6

`ParseFile` issues on Windows

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.

Error when codeowners file lists an empty owner

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.

Unassigned filepaths shouldn't fail

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?

Doesn't correctly follow rules for ownership in nested directories

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]

(from https://docs.github.com/en/free-pro-team@latest/github/creating-cloning-and-archiving-repositories/about-code-owners )

Essentially the /* only matches direct descendants, not all descendants of a directory. This logic is the same for Gitlab too.

Support for sections (Gitlab flavor)

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.