{"id":13725672,"url":"https://github.com/GoogleChromeLabs/pr-bot","last_synced_at":"2025-05-07T20:33:21.317Z","repository":{"id":66027594,"uuid":"99369902","full_name":"GoogleChromeLabs/pr-bot","owner":"GoogleChromeLabs","description":"🤖 Compare your base branch to a pull request and run plugins over it to view differences","archived":false,"fork":false,"pushed_at":"2024-02-07T19:18:11.000Z","size":657,"stargazers_count":180,"open_issues_count":19,"forks_count":19,"subscribers_count":15,"default_branch":"master","last_synced_at":"2024-08-04T01:27:55.506Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GoogleChromeLabs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-08-04T18:29:42.000Z","updated_at":"2023-12-12T17:27:28.000Z","dependencies_parsed_at":null,"dependency_job_id":"c949aaf5-1f19-4417-ba9a-a9d14076c24d","html_url":"https://github.com/GoogleChromeLabs/pr-bot","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoogleChromeLabs%2Fpr-bot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoogleChromeLabs%2Fpr-bot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoogleChromeLabs%2Fpr-bot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoogleChromeLabs%2Fpr-bot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GoogleChromeLabs","download_url":"https://codeload.github.com/GoogleChromeLabs/pr-bot/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224645510,"owners_count":17346173,"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":[],"created_at":"2024-08-03T01:02:30.846Z","updated_at":"2024-11-14T15:31:48.633Z","avatar_url":"https://github.com/GoogleChromeLabs.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","Build Tools to set up performance budget"],"sub_categories":[],"readme":"# pr-bot\n\n[![Build Status](https://travis-ci.org/GoogleChromeLabs/pr-bot.svg?branch=master)](https://travis-ci.org/GoogleChromeLabs/pr-bot) [![Coverage Status](https://coveralls.io/repos/github/GoogleChromeLabs/pr-bot/badge.svg?branch=master)](https://coveralls.io/github/GoogleChromeLabs/pr-bot?branch=master) [![dependencies Status](https://david-dm.org/googlechromelabs/pr-bot/status.svg)](https://david-dm.org/googlechromelabs/pr-bot) [![devDependencies Status](https://david-dm.org/googlechromelabs/pr-bot/dev-status.svg)](https://david-dm.org/googlechromelabs/pr-bot?type=dev)\n\nThis is a small utility to run a set of \"plugins\"\nagainst a Pull Request on Travis and then report\na set of results to GitHub.\n\n![Example PR-Bot Output](http://i.imgur.com/QMOaiQy.png)\n\n## Getting Started\n\nTo use `pr-bot` you'll need to set up a few\nthings:\n\n1. Create a GitHub account to use for bot\nactivity. This will be the account login and\nprofile photo that you'll see when the bot\ncomments on a pull request.\n\n1. Add the GitHub bot account to your project as a collaborator.\n`https://github.com/\u003cowner\u003e/\u003crepo\u003e/settings/collaboration`.\nBe sure to accept the invite email! This will enable the bot\nto set PR statuses.\n\n1. [Create a personal access token for the\nGitHub bot account](https://github.com/settings/tokens).\nThe access token must at least have the `public_repo` scope\nenabled.\n\n1. In the Travis settings for your repository,\nset the personal access token as an environment\nvariable called `GITHUB_TOKEN`.\n\n    ![Imgur](http://i.imgur.com/QzwmvxD.png)\n\n1. Add `pr-bot` as a dependency to your\nproject:\n\n    ```shell\n    npm install --save-dev pr-bot\n    ```\n\n1. Create a file called `pr-bot.config.js` at the\nroot of your project (i.e. this file needs to be commited\nto your GitHub repository).\n\n1. In this new file add the following:\n\n    ```javascript\n    const prbot = require('pr-bot');\n\n    module.exports = {\n      botUsername: `\u003cAdd the GitHub Username for your Bot Account Here\u003e`,\n      repoDetails: {\n        owner: \"\u003cAdd the repo owner, i.e. GoogleChrome\u003e\",\n        repo: \"\u003cAdd the repo name, i.e. workbox\u003e\"\n      },\n      plugins: [\n        new prbot.plugins.Size({\n          globPattern: '**/*.js',\n          globOptions: {\n            ignore: [\n              '**/node_modules/**/*',\n            ]\n          },\n        }),\n      ],\n    };\n    ```\n\n1. Add the following to your `.travis.yml` file\n\n    ```yaml\n    after_script:\n      - npm install -g pr-bot\n      - pr-bot\n    ```\n\nNow you can commit your code and if everything is set up correctly, you'll\nsee comments from your bot account.\n\n![Example output from Size Plugin from pr-bot](http://i.imgur.com/oZPrdXr.png)\n\n### Running Locally\n\nYou can see what `pr-bot` will do locally with the following:\n\n```shell\nnpm install --global pr-bot\npr-bot\n```\n\nThis is useful if you want to see the file differences without\nwaiting on Travis.\n\n![Example console output from Size Plugin from pr-bot](http://i.imgur.com/h518U9O.png)\n\n### Customising Config Path\n\nYou can use the `-c` flag to define a custom config path:\n\n```shell\npr-bot -c ./some-path-my-config.js\n```\n\n### Customising Install and Build\n\nIf `npm install \u0026\u0026 npm build` will not suffice for your project,\nyou define a `buildCommand` parameter in your config file\nto define the command to run in the two checkouts of your project.\n\n```javascript\nmodule.exports = {\n  // Custom build command in travis.config.js\n  buildCommand: `npm install \u0026\u0026 gulp`,\n\n\n  botUsername: `....`,\n  plugins: [...]\n}\n```\n\n## How it Works\n\nWhen you run `pr-bot` it checks out two versions of your project.\n\n1. **If run locally**, it'll checkout the default branch of your repo AND\nuse the current directory and the current files for the second\nversion.\n1. **If run on Travis**, it'll checkout the base of the Pull Request,\nor the target branch, for the first version and it'll checkout the Pull\nRequest commit as the second version.\n\nThese are checked out into tempory files under `/tmp` and `pr-bot`\nwill `npm install \u0026\u0026 npm run build` in each repository.\n\nAfter this, each plugin defined in your config file will be called\nwith a `beforePath` and `afterPath`. This allows plugins to compare\nfiles or anything else they want.\n\nPlugins are expected to return a `promise` that resolves to an `object`\nwith a `prettyLog` parameter and a `markdownLog` parameter. The\n`prettyLog` is used to display plugin output to the console and\n`markdownLog` is used to print to the GitHub comment raised against\nthe Pull Request.\n\n## Adding Custom Plugins\n\nYou can build custom plugins, the key things to note are:\n\nYour plugin must:\n\n1. ..have a `name` property.\n1. ..have a `run` method with a signature of\n   `run({beforePath, afterPath} = {})`.\n1. ..return a Promise from the `run` method.\n\nAnd your plugin should:\n\n1. ..resolve the `run` promise with an `object`with `prettyLog`\nand `markdownLog` string parameters to print out info and if you wish\nto mark the Pull Request as a bad PR (set status to failure), you can return\nthe parameter `failPR` with `true`.\n\nA basic plugin can look like this:\n\n```javascript\n{\n  name: 'Example Plugin',\n  run: () =\u003e {\n    return Promise.resolve({\n      failPR: false,\n      prettyLog: 'Hello from example plugin.',\n      markdownLog: '## Hello from example plugin.'\n    });\n  },\n}\n```\n\nIf you want, your custom plugin can also extend the `PluginInterface` from the\nmodule with `const PluginInterface = require('pr-bot').PluginInterface;`.\n\n## Different Base Branch\n\nWhen developing on a new version, the default branch on GitHub may not be\nthe branch you want to compare PR's (or locally).\n\nYou can compare to other branches using the `overrideBaseBranch` config.\n\n```javascript\nmodule.exports = {\n  overrideBaseBranch: '\u003cname of branch',\n  ...\n};\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGoogleChromeLabs%2Fpr-bot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FGoogleChromeLabs%2Fpr-bot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGoogleChromeLabs%2Fpr-bot/lists"}