Skip to content

New hook: check-moved-repos #726

Closed
Closed

Description

@sirosen

I keep on finding pre-commit configs in various projects which are pointed at https://gitlab.com/pycqa/flake8
It would be awesome if I could turn on a hook which checks for hooks from that repo and flags them as needing an update to the github repo. The same holds for many repos like black which have moved/renamed, and which only work because of github redirects.

I don't know if this is a common case other than flake8, or if it's so common that such a hook would be a huge pain to maintain. But it just needs to be able to read the pre-commit config and pull out the repos, not the rest of the config. It can skip support for old configs (top-level list) and make other simplifying assumptions as necessary.

Activity

  1. asottile commented on Feb 4, 2022

    @asottile
    Member

    yeah I agree it's a good idea but I also agree with this bit :(

    that such a hook would be a huge pain to maintain

    and that's why it's not been generically implemented

    pre-commit.ci has a bit of this implemented for normalization purposes -- but doing this generically is a hard problem:

    • following redirects is expensive
    • it would still need to maintain a large hardcoded list of cross-system moves
    • it would invite potentially spammy PRs for renames
  2. sirosen commented on Feb 4, 2022

    @sirosen
    Author

    I'd suggest putting it in a separate project (I'd just go off and write it myself), but it's such a "pre-commit checks pre-commit config" hook that I almost suggested it as one of the "meta" hooks in pre-commit itself.

    Would you be interested in this as a part of pre-commit? It could be made part of the behavior of autoupdate to check for redirects. I thought it would be easier to implement as a hook, but after reading your points, it seems like auotupdate might be the right place for it.

  3. asottile commented on Feb 4, 2022

    @asottile
    Member

    I've already declined such a feature in pre-commit itself because of the reasons above

  4. sirosen commented on Feb 4, 2022

    @sirosen
    Author

    Looking for a past issue or PR, I see this comment. I'm not clear if the pre-commit.ci feature mentioned there is the normalization of which you spoke here.

    That issue mentions git behavior being complicated (presumably autoupdate starts by cloning). I was considering something doing an HTTP GET, even if autoupdate is not doing that already.

    Perhaps this makes more sense as a flag to autoupdate, like --check-http-redirects? Or maybe I'm still underestimating the complexity.

    If this issue was dead-on-arrival, let's just close. I'm happy to help if there's a feature I could work on, but if not, there's no point spending more time on this topic. :-)

  5. asottile commented on Feb 4, 2022

    @asottile
    Member

    ah yeah it was discussed further here: pre-commit/pre-commit#2003

  6. sirosen commented on Feb 4, 2022

    @sirosen
    Author

    Just thinking about possibilities, is it possible to use the same yaml conf for https://pre-commit.com/hooks somehow?

    I'd be perfectly well satisfied with --warn-unknown-hooks:

    $ pre-commit autoupdate --warn-unknown-hooks
    The following hooks are not listed on pre-commit.com/hooks
      https://gitlab.com/pycqa/flake8
    

    This easily could get very annoying if you have hooks which aren't on the site, unless an ignore mechanism is added.

    $ pre-commit autoupdate --warn-unknown-hooks --exclude-unknown-hook https://gitlab.com/pycqa/flake8
    

    I do not like that, but it's all I can think of if we don't add to config. 😿

    But even without an ignore mechanism, this would be handy for the majority of users.


    As another alternative direction, allow the command to consume some kind of listing of user specified known repo moves. And check redirects (optionally) without trying to follow them.
    e.g.

    $ cat moves.json
    {"https://gitlab.com/pycqa/flake8": "https://github.com/pycqa/flake8"}
    $ check-pre-commit-repo-moves --repo-moves-file moves.json --check-redirects
    Errors found prior to running update:
    
    Redirect found in repo URL
      https://github.com/ambv/black
      has moved to
      https://github.com/psf/black
    
    Known repo move detected:
      https://gitlab.com/pycqa/flake8
      has moved to
      https://github.com/pycqa/flake8
    

    There's no redirect looping or following issue because it doesn't follow redirects.
    We don't get stymied trying to track repo moves.
    It can be added as a hook as long as it gets skipped in pre-commit.ci config.

  7. asottile commented on Feb 4, 2022

    @asottile
    Member

    I don't really want to introduce pre-commit.com or pre-commit.ci as a critical-path component for pre-commit's operation -- part of the current design is it's entirely "distributed" and doesn't have any phone-home

  8. sirosen commented on Feb 28, 2022

    @sirosen
    Author

    I'm still trying to think up a reasonable way of handling this. (Should I not? You can close as far as I'm concerned if you think the problem doesn't have a good, tractable solution.)

    How 👍/👎 would you be on the idea of a new key in hook config which states the "canonical repo" of a hook? The hook owner can then "publish" their rename. That might also help in the case of a hook moving between repos.
    It's not perfect, but it avoids centralizing the information.

  9. asottile commented on Feb 28, 2022

    @asottile
    Member

    yeah I kinda wrote that off here -- the hook config is a top-level list so there isn't a good place to put it pre-commit/pre-commit#2003 (comment)

    I'm going to close this 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions