{"id":15293470,"url":"https://github.com/tido64/suggestion-bot","last_synced_at":"2025-04-13T13:32:00.599Z","repository":{"id":36954089,"uuid":"281384332","full_name":"tido64/suggestion-bot","owner":"tido64","description":"suggestion-bot submits code reviews with suggestions based on your diffs","archived":false,"fork":false,"pushed_at":"2024-04-08T09:29:43.000Z","size":8994,"stargazers_count":6,"open_issues_count":1,"forks_count":4,"subscribers_count":1,"default_branch":"trunk","last_synced_at":"2024-04-14T04:43:33.727Z","etag":null,"topics":["azure-devops","code-review","diff","github","pull-request","review","suggestions"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/tido64.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}},"created_at":"2020-07-21T11:54:35.000Z","updated_at":"2024-04-15T07:10:53.465Z","dependencies_parsed_at":"2023-10-02T04:35:09.002Z","dependency_job_id":"2c833d22-ac55-49c0-b20c-7116ddc21fbc","html_url":"https://github.com/tido64/suggestion-bot","commit_stats":{"total_commits":300,"total_committers":6,"mean_commits":50.0,"dds":0.3833333333333333,"last_synced_commit":"a1bc1bb7f016b811757795fdf54a9da1829cdc06"},"previous_names":[],"tags_count":45,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tido64%2Fsuggestion-bot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tido64%2Fsuggestion-bot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tido64%2Fsuggestion-bot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tido64%2Fsuggestion-bot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tido64","download_url":"https://codeload.github.com/tido64/suggestion-bot/tar.gz/refs/heads/trunk","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248721169,"owners_count":21151059,"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":["azure-devops","code-review","diff","github","pull-request","review","suggestions"],"created_at":"2024-09-30T16:48:53.663Z","updated_at":"2025-04-13T13:31:55.573Z","avatar_url":"https://github.com/tido64.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# suggestion-bot\n\n[![build](https://github.com/tido64/suggestion-bot/actions/workflows/build.yml/badge.svg)](https://github.com/tido64/suggestion-bot/actions/workflows/build.yml)\n[![npm version](https://img.shields.io/npm/v/suggestion-bot)](https://www.npmjs.com/package/suggestion-bot)\n\n`suggestion-bot` submits code reviews with suggestions based on your diffs.\n\n![screenshot of code review with suggestions](docs/screenshot.png)\n\n## Usage\n\n```\nUsage: cli.js [options] [diff | file]\n\nSubmit code reviews with suggestions based on your diffs\n\nArguments:\n  diff | file            the diff or file containing diff to create suggestions from\n\nOptions:\n  -h, --help             display this help message\n  -v, --version          display version number\n  -m, --message \u003cmsg\u003e    use the specified message as the PR comment\n  -f, --fail             fail if comments could not be posted\n\nExamples:\n  # Submit current changes as suggestions\n  GITHUB_TOKEN=\u003csecret\u003e suggestion-bot \"$(git diff)\"\n\n  # Alternatively, pipe to suggestion-bot\n  # to avoid escape character issues\n  git diff | GITHUB_TOKEN=\u003csecret\u003e suggestion-bot\n```\n\nIf your CI is hosted by Azure DevOps, replace `GITHUB_TOKEN` with\n`AZURE_PERSONAL_ACCESS_TOKEN`.\n\n## Requirements\n\n- Host your code on [GitHub](https://github.com/)\n- `GITHUB_TOKEN` permissions:\n  - `pull-requests: write` — required for creating code reviews\n  - `issues: write` — fallback in case creating a review fails\n\n-- or --\n\n- Host your code on [Azure DevOps](https://dev.azure.com/)\n- An Azure DevOps\n  [personal access token](https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops\u0026tabs=preview-page)\n\n## Recipes\n\n- [Using `suggestion-bot` with GitHub Actions](#using-suggestion-bot-with-github-actions)\n- [Using `suggestion-bot` with `clang-format`](#using-suggestion-bot-with-clang-format)\n- [Using `suggestion-bot` with Prettier](#using-suggestion-bot-with-prettier)\n\n### Using `suggestion-bot` with GitHub Actions\n\n1. Install `suggestion-bot` in your project\n\n   ```sh\n   yarn add suggestion-bot --dev\n   ```\n\n2. Configure your GitHub workflow so `suggestion-bot` can access the\n   `GITHUB_TOKEN` secret provided by GitHub via an environment variable with the\n   same name:\n\n   ```yaml\n   # .github/workflows/build.yml\n   jobs:\n     lint:\n       runs-on: ubuntu-latest\n       steps:\n         - name: Set up Node.js\n           uses: actions/setup-node@v1\n           with:\n             node-version: 18\n         - name: Checkout\n           uses: actions/checkout@v2\n         - name: Install\n           run: yarn\n         - name: ClangFormat\n           if: ${{ github.event_name == 'pull_request' }}\n           env:\n             GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n           run: scripts/clang-format-diff.sh | yarn suggestion-bot\n   ```\n\n### Using `suggestion-bot` with `clang-format`\n\nUse\n[`clang-format-diff`](https://clang.llvm.org/docs/ClangFormat.html#script-for-patch-reformatting)\nto format only changed files:\n\n```sh\ncurl --silent --show-error --remote-name https://raw.githubusercontent.com/llvm/llvm-project/release/10.x/clang/tools/clang-format/clang-format-diff.py\ngit diff --unified=0 --no-color @^ \\\n  | python clang-format-diff.py -p1 -regex '.*\\.(cpp|cc|c\\+\\+|cxx|c|cl|h|hh|hpp|m|mm|inc)' -sort-includes \\\n  | yarn suggestion-bot\n```\n\n### Using `suggestion-bot` with Prettier\n\nWe must first write a script that pipes [Prettier](https://prettier.io/)'s\noutput to `diff` so we can feed it to `suggestion-bot` later.\n\n```js\n#!/usr/bin/env node\n\nimport { spawnSync } from \"node:child_process\";\nimport * as fs from \"node:fs\";\nimport * as prettier from \"prettier\";\nimport suggest from \"suggestion-bot\";\n\nconst diff = process.argv.slice(2).reduce((diff, filepath) =\u003e {\n  const source = fs.readFileSync(filepath, { encoding: \"utf8\" });\n  const { stdout } = spawnSync(\"diff\", [\"--unified\", filepath, \"-\"], {\n    input: prettier.format(source, { filepath }),\n    encoding: \"utf-8\",\n  });\n  return diff + stdout;\n}, \"\");\n\nsuggest(diff);\n```\n\nSave the script somewhere, e.g. `scripts/prettier-diff.mjs`, then invoke it with\nNode:\n\n```sh\nnode scripts/prettier-diff.mjs $(git ls-files '*.js')\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftido64%2Fsuggestion-bot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftido64%2Fsuggestion-bot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftido64%2Fsuggestion-bot/lists"}