peter-evans / autopep8

A GitHub action for autopep8, a tool that automatically formats Python code to conform to the PEP 8 style guide.
MIT License
85 stars 15 forks source link

Push the formatting changes to the fork on:pull_request #54

Open yaacine opened 3 years ago

yaacine commented 3 years ago

Hi 👋 thanks for the great job you did on this action ,

I was trying to commit the formatted files into a PR made from a fork on a private repository (where this feature of running workflows from forks is enabled). So I used this action

    # push the formatting changes to the PR itself
      - name: Commit autopep8 changes
        if: steps.autopep8.outputs.exit-code == 2
        run: |
          git config --global user.name 'Peter Evans'
          git config --global user.email 'peter-evans@users.noreply.github.com'
          git commit -am "Automated autopep8 fixes"
          git push

but it seems that it's trying to push to the base repo not the fork itself. and I got this error


remote: Repository not found.
fatal: repository 'https://github.com/<org_name>/<repo_name>/' not found
Error: Process completed with exit code 128.

Knowing that there are couple of developers who forked this repo and want to run the formatting action when they open a PR to the base repo ,Is there any way to address my use case please ?

Thanks in advance.

peter-evans commented 3 years ago

Hi @yaacine

I'm not sure if what you want to do is possible. There are a number of issues with trying to make this kind of workflow work for forks. I don't really recommend it, and as I mention in the readme, I recommend using a slash command style "ChatOps" solution for these kind of operations on pull requests. See slash-command-dispatch for such a solution.

To try and fix your problem, you need to make sure that the pull request branch is being checked out. If you look at the example linked below you can see that it checks out github.head_ref. You will need to do something similar to checkout the pull request branch from the fork. https://github.com/peter-evans/autopep8#direct-push-with-on-pull_request-workflows