{"id":13412063,"url":"https://github.com/peter-evans/autopep8","last_synced_at":"2025-04-06T18:14:28.373Z","repository":{"id":36010444,"uuid":"197388385","full_name":"peter-evans/autopep8","owner":"peter-evans","description":"A GitHub action for autopep8, a tool that automatically formats Python code to conform to the PEP 8 style guide.","archived":false,"fork":false,"pushed_at":"2024-07-04T15:30:34.000Z","size":347,"stargazers_count":85,"open_issues_count":5,"forks_count":14,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-30T15:10:05.584Z","etag":null,"topics":["autopep8","formatter","github-action","pep8","python"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/peter-evans.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"peter-evans"}},"created_at":"2019-07-17T12:48:27.000Z","updated_at":"2025-03-21T11:28:34.000Z","dependencies_parsed_at":"2024-11-26T07:15:37.489Z","dependency_job_id":null,"html_url":"https://github.com/peter-evans/autopep8","commit_stats":{"total_commits":75,"total_committers":6,"mean_commits":12.5,"dds":"0.16000000000000003","last_synced_commit":"48c58cb0cc82fea142e5fd4cc9d00a0b8339cb4d"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peter-evans%2Fautopep8","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peter-evans%2Fautopep8/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peter-evans%2Fautopep8/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peter-evans%2Fautopep8/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peter-evans","download_url":"https://codeload.github.com/peter-evans/autopep8/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247526763,"owners_count":20953143,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["autopep8","formatter","github-action","pep8","python"],"created_at":"2024-07-30T20:01:20.623Z","updated_at":"2025-04-06T18:14:28.356Z","avatar_url":"https://github.com/peter-evans.png","language":"Python","funding_links":["https://github.com/sponsors/peter-evans"],"categories":["Python","Community Resources","五、按场景分类的实用Action"],"sub_categories":["Testing and Linting","Static Analysis","2. 代码质量与测试"],"readme":"# autopep8\n[![GitHub Marketplace](https://img.shields.io/badge/Marketplace-autopep8-blue.svg?colorA=24292e\u0026colorB=0366d6\u0026style=flat\u0026longCache=true\u0026logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAYAAAAfSC3RAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAM6wAADOsB5dZE0gAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAERSURBVCiRhZG/SsMxFEZPfsVJ61jbxaF0cRQRcRJ9hlYn30IHN/+9iquDCOIsblIrOjqKgy5aKoJQj4O3EEtbPwhJbr6Te28CmdSKeqzeqr0YbfVIrTBKakvtOl5dtTkK+v4HfA9PEyBFCY9AGVgCBLaBp1jPAyfAJ/AAdIEG0dNAiyP7+K1qIfMdonZic6+WJoBJvQlvuwDqcXadUuqPA1NKAlexbRTAIMvMOCjTbMwl1LtI/6KWJ5Q6rT6Ht1MA58AX8Apcqqt5r2qhrgAXQC3CZ6i1+KMd9TRu3MvA3aH/fFPnBodb6oe6HM8+lYHrGdRXW8M9bMZtPXUji69lmf5Cmamq7quNLFZXD9Rq7v0Bpc1o/tp0fisAAAAASUVORK5CYII=)](https://github.com/marketplace/actions/autopep8)\n\nA GitHub action for [autopep8](https://github.com/hhatto/autopep8), a tool that automatically formats Python code to conform to the PEP 8 style guide.\n\nThis action is designed to be used in conjunction with [Create Pull Request](https://github.com/peter-evans/create-pull-request). This will automatically create a pull request to merge fixes that autopep8 makes to python code in your repository.\n\n## Usage\n\nThis action is a simple wrapper around [autopep8](https://github.com/hhatto/autopep8). Arguments should be passed to the action via the `args` parameter.\nThis example fixes all python files in your repository with aggressive level 2.\n\n```yml\n      - name: autopep8\n        id: autopep8\n        uses: peter-evans/autopep8@v2\n        with:\n          args: --recursive --in-place --aggressive --aggressive .\n```\n\nThe action outputs the exit code from autopep8. This can be useful in combination with the autopep8 flag `--exit-code` for pull request checks.\n\n```yml\n      - name: Fail if autopep8 made changes\n        if: steps.autopep8.outputs.exit-code == 2\n        run: exit 1\n```\n\nSee [autopep8 documentation](https://github.com/hhatto/autopep8) for further argument details.\n\n## Automated pull requests\n\nOn its own this action is not very useful. Please use it in conjunction with [Create Pull Request](https://github.com/peter-evans/create-pull-request) or a [direct push to branch workflow](#direct-push-with-on-pull_request-workflows).\n\nThe following workflow is a simple example to demonstrate how the two actions work together.\n\n```yml\nname: Format python code\non: push\njobs:\n  autopep8:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v2\n      - name: autopep8\n        uses: peter-evans/autopep8@v2\n        with:\n          args: --recursive --in-place --aggressive --aggressive .\n      - name: Create Pull Request\n        uses: peter-evans/create-pull-request@v3\n        with:\n          commit-message: autopep8 action fixes\n          title: Fixes by autopep8 action\n          body: This is an auto-generated PR with fixes by autopep8.\n          labels: autopep8, automated pr\n          reviewers: peter-evans\n          branch: autopep8-patches\n```\n\nThis configuration will create pull requests that look like this:\n\n![Pull Request Example](https://github.com/peter-evans/autopep8/blob/master/autopep8-example-pr.png?raw=true)\n\n## Automated pull requests with \"on: pull_request\" workflows\n\n**Update**: While the following approach does work in some cases, my strong recommendation would be to use a slash command style \"ChatOps\" solution for operations on pull requests. See [slash-command-dispatch](https://github.com/peter-evans/slash-command-dispatch) for such a solution.\n\nThe following is an example workflow for a use-case where autopep8 runs as both a check on pull requests and raises a further pull request to apply fixes.\n\nHow it works:\n1. When a pull request is raised the workflow executes as a check.\n2. If autopep8 makes any fixes a pull request will be raised for those fixes to be merged into the current pull request branch. The workflow then deliberately causes the check to fail.\n3. When the pull request containing the fixes is merged the workflow runs again. This time autopep8 makes no changes and the check passes.\n4. The original pull request can now be merged.\n\nNote that due to [token restrictions on public repository forks](https://docs.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token#permissions-for-the-github_token), this workflow does not work for pull requests raised from forks.\nPrivate repositories can be configured to [enable workflows](https://docs.github.com/en/github/administering-a-repository/disabling-or-limiting-github-actions-for-a-repository#enabling-workflows-for-private-repository-forks) from forks to run without restriction. \n\n```yml\nname: autopep8\non: pull_request\njobs:\n  autopep8:\n    # Check if the PR is not raised by this workflow and is not from a fork\n    if: startsWith(github.head_ref, 'autopep8-patches') == false \u0026\u0026 github.event.pull_request.head.repo.full_name == github.repository\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v2\n        with:\n          ref: ${{ github.head_ref }}\n      - name: autopep8\n        id: autopep8\n        uses: peter-evans/autopep8@v2\n        with:\n          args: --exit-code --recursive --in-place --aggressive --aggressive .\n      - name: Set autopep8 branch name\n        id: vars\n        run: |\n          branch-name=\"autopep8-patches/${{ github.head_ref }}\"\n          echo \"branch-name=$branch-name\" \u003e\u003e $GITHUB_OUTPUT\n      - name: Create Pull Request\n        if: steps.autopep8.outputs.exit-code == 2\n        uses: peter-evans/create-pull-request@v3\n        with:\n          commit-message: autopep8 action fixes\n          title: Fixes by autopep8 action\n          body: This is an auto-generated PR with fixes by autopep8.\n          labels: autopep8, automated pr\n          reviewers: peter-evans\n          branch: ${{ steps.vars.outputs.branch-name }}\n      - name: Fail if autopep8 made changes\n        if: steps.autopep8.outputs.exit-code == 2\n        run: exit 1\n```\n\n## Direct push with \"on: pull_request\" workflows\n\nThe following workflow is an alternative to the previous workflow. Instead of raising a second pull request it commits the changes made by autopep8 directly to the pull request branch.\n\n**Important caveat:** If you have other pull request checks besides the following workflow then you must use a [Personal Access Token](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) instead of the default `GITHUB_TOKEN`.\nThis is due to a deliberate limitation imposed by GitHub Actions that events raised by a workflow (such as `push`) cannot trigger further workflow runs.\nThis is to prevent accidental \"infinite loop\" situations, and as an anti-abuse measure.\nUsing a `repo` scoped [Personal Access Token](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) is an approved workaround. See [here](https://github.com/peter-evans/create-pull-request/blob/master/docs/concepts-guidelines.md#triggering-further-workflow-runs) for further detail.\n\nHow it works:\n1. When a pull request is raised the workflow executes as a check.\n2. If autopep8 makes any fixes they will be committed directly to the current pull request branch.\n3. The `push` triggers all pull request checks to run again.\n\nNote that due to [token restrictions on public repository forks](https://docs.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token#permissions-for-the-github_token), this workflow does not work for pull requests raised from forks.\nPrivate repositories can be configured to [enable workflows](https://docs.github.com/en/github/administering-a-repository/disabling-or-limiting-github-actions-for-a-repository#enabling-workflows-for-private-repository-forks) from forks to run without restriction.\n\n```yml\nname: autopep8\non: pull_request\njobs:\n  autopep8:\n    # Check if the PR is not from a fork\n    if: github.event.pull_request.head.repo.full_name == github.repository\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v2\n        with:\n          token: ${{ secrets.REPO_ACCESS_TOKEN }}\n          ref: ${{ github.head_ref }}\n      - name: autopep8\n        id: autopep8\n        uses: peter-evans/autopep8@v2\n        with:\n          args: --exit-code --recursive --in-place --aggressive --aggressive .\n      - name: Commit autopep8 changes\n        if: steps.autopep8.outputs.exit-code == 2\n        run: |\n          git config --global user.name 'Peter Evans'\n          git config --global user.email 'peter-evans@users.noreply.github.com'\n          git commit -am \"Automated autopep8 fixes\"\n          git push\n```\n\n## License\n\nMIT License - see the [LICENSE](LICENSE) file for details\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeter-evans%2Fautopep8","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeter-evans%2Fautopep8","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeter-evans%2Fautopep8/lists"}