andreoliwa / nitpick

Enforce the same settings on multiple projects

Home Page:https://nitpick.readthedocs.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to get from private repo (within a GitHub team)

amitkparekh opened this issue Β· comments

Your bug may already be reported!
Please search on the issue tracker before creating one.
If you found an issue, write a comment or upvote it with a thumbs-up πŸ‘πŸ».

Expected behavior

I should be able to get the style from a private repo within a GitHub team.

Current behavior

Currently getting a 404 error with URL not found.

Steps to reproduce

  1. Put a nitpick style in a private repo
  2. Create a PAT with the repos scope
  3. Add github://$GITHUB_PAT@team-name/repo-name/nitpick-style.toml to a pyproject.toml in another project ($GITHUB_PAT is the GitHub Personal Access Token, which can either be copy-pasted or as a env variable, as described in the documentation).
  4. Run nitpick check
  5. Get 404.

Possible Solution

I looked at the fetcher for GitHub URLs and I noticed that there isn't an aspect which also specifies the username. I tried to use curl as shown by the GitHub API docs and was able to get to the correct repo and file because I provided both my username and the PAT in -u.

Context

We have a common template repository with rules and such for GitHub Actions and a common style guide, but any changes to it need to be manually updated to all derived repositories. Nitpick reminds me of ESLint configs (like AirBnB's) where there can be a single source that projects can pull from, and any changes can be reflected throughout.

Your environment

  • nitpick version used: 0.31.0

  • Python version: 3.9.9

  • Operating System and version: Mac OS 12.0.1

  • Link to your project:

  • Run the following commands and paste the output:

    which python3
    python3 -V
    pip freeze
    cat $(which flake8)

For more information, see the CONTRIBUTING guide.

Hi, thanks for the bug report!

I just realised that the docs might be written in a misleading way...
The "token" mentioned in the docs is the ?token= query string argument that shows up when you click on the "Raw" button on a private file:

image

You will see a URL similar to https://raw.githubusercontent.com/your-user/your-private-repo/your-branch/file-in-the-private-repo?token=GHSAT0AAAAAABOMHNKFHPDRJQ3Y2GCMUP7CYPF7GEA.

  1. I don't know if the GitHub fetcher works with a PAT.
  2. I'm also not sure, but I remember this query string token expires after some time.

To be honest, I myself didn't use this feature in a long time.
It was recently fixed in #409.
I didn't even know it was broken, because I don't use private styles anymore. πŸ˜…

Can you try with this query string token instead of a PAT and let me know if it works?

Can you try with this query string token instead of a PAT and let me know if it works?

Hi @amitkparekh. Bumping again because I think you didn't see my comment above. ☝🏻 πŸ™‚


@mjpieters you read your styles from a private repo by using a GitHub token on your style URLs, right?
How is this working out for you?
Did you experience any problems with the URL token?

@mjpieters you read your styles from a private repo by using a GitHub token on your style URLs, right?
How is this working out for you?
Did you experience any problems with the URL token?

I'm not, actually; we push the files to GitHub pages.

I suspect this specific issue can be solved by using a development version with my relative URL changes. Or by inserting the token into all URLs in the style files in the private repo, one or the other :-)

πŸ‘πŸ» Thanks for the answer anyway. πŸ™‚

I'll wait for more info from Amit, so I can find out if this bug is still happening or not.


by using a development version

By the way: I'll create a release with your changes. πŸ˜‰

I looked at the fetcher for GitHub URLs and I noticed that there isn't an aspect which also specifies the username.

The token itself identifies the user, the username is not required. You can send the token in a basic type Authorization header as the username with an empty password or as the password with an empty username, or you can use it in a token style Authorization header.

I can actually reproduce the issue, when omitting the git reference.

The issue is that the API call to fetch the default branch will fail as there is no token passed to the API call (in nitpick.style.fetchers.github.get_default_branch()).

The workaround is to add the default branch after the repo name; e.g. if your default branch name is main, use github://$GITHUB_PAT@team-name/repo-name@main/nitpick-style.toml

The fix should be easy enough, I can create a PR tomorrow.

I have a working change; the tests need updating but that change fixes this issue I think.

The issue is that the API call to fetch the default branch will fail as there is no token passed to the API call (in nitpick.style.fetchers.github.get_default_branch()).

Thanks for spotting this so quickly.
I focused on the personal access token thing and didn't notice this problem.

This will be shipped on the next release.
I usually wait a bit to release unless it's a critical bug.
I just released a version yesterday.

@amitkparekh Please install the development version and let us know if it doesn't work.

pipx install git+https://github.com/andreoliwa/nitpick

@andreoliwa I'm really sorry I didn't reply! My GitHub notifications weren't set up right and I wasn't getting anything.

Unfortunately, we needed to get going and so decided against using nitpick currently but once things settle down, I'm considering taking another run at implementing nitpick and seeing if it works.

Thank you so much for finding the issue though!

Alright. πŸ‘πŸ»
When you will try Nitpick again, let me know if the recent changes work for you.

If not, I can investigate the problem again later.