Name: pr-bot
Owner: GoogleChromeLabs
Description: ? Compare your base branch to a pull request and run plugins over it to view differences
Created: 2017-08-04 18:29:42.0
Updated: 2018-05-18 09:00:27.0
Pushed: 2017-10-27 22:31:46.0
Size: 440
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
This is a small utility to run a set of “plugins” against a Pull Request on Travis and then report a set of results to GitHub.
To use pr-bot
you'll need to set up a few
things:
Create a GitHub account to use for bot activity. This will be the account login and profile photo that you'll see when the bot comments on a pull request.
In the Travis settings for your repository,
set the personal access token as an environment
variable called GITHUB_TOKEN
.
Add pr-bot
as a dependency to your
project:
install --save-dev pr-bot
Create a file called pr-bot.config.js
at the
root of your project (i.e. this file needs to be commited
to your GitHub repository).
In this new file add the following:
t prbot = require('pr-bot');
le.exports = {
tUsername: `<Add the GitHub Username for your Bot Account Here>`,
ugins: [
new prbot.plugins.Size({
globPattern: '**/*.js',
globOptions: {
ignore: [
'**/node_modules/**/*',
]
},
}),
Add the following to your .travis.yml
file
r_script:
npm install -g pr-bot
pr-bot
Now you can commit your code and if everything is set up correctly, you'll see comments from your bot account.
You can see what pr-bot
will do locally with the following:
install --global pr-bot
ot
This is useful if you want to see the file differences without waiting on Travis.
You can use the -c
flag to define a custom config path:
ot -c ./some-path-my-config.js
If npm install && npm build
will not suffice for your project,
you define a buildCommand
parameter in your config file
to define the command to run in the two checkouts of your project.
le.exports = {
Custom build command in travis.config.js
ildCommand: `npm install && gulp`,
tUsername: `....`,
ugins: [...]
When you run pr-bot
it checks out two versions of your project.
These are checked out into tempory files under /tmp
and pr-bot
will npm install && npm run build
in each repository.
After this, each plugin defined in your config file will be called
with a beforePath
and afterPath
. This allows plugins to compare
files or anything else they want.
Plugins are expected to return a promise
that resolves to an object
with a prettyLog
parameter and a markdownLog
parameter. The
prettyLog
is used to display plugin output to the console and
markdownLog
is used to print to the GitHub comment raised against
the Pull Request.
You can build custom plugins, the key things to note are:
Your plugin must:
name
property.run
method with a signature of
run({beforePath, afterPath} = {})
.run
method.And your plugin should:
run
promise with an object
with prettyLog
and markdownLog
string parameters to print out info and if you wish
to mark the Pull Request as a bad PR (set status to failure), you can return
the parameter failPR
with true
.A basic plugin can look like this:
me: 'Example Plugin',
n: () => {
return Promise.resolve({
failPR: false,
prettyLog: 'Hello from example plugin.',
markdownLog: '## Hello from example plugin.'
});
If you want, your custom plugin can also extend the PluginInterface
from the
module with const PluginInterface = require('pr-bot').PluginInterface;
.
When developing on a new version, the default branch on GitHub may not be the branch you want to compare PR's (or locally).
You can compare to other branches using the overrideBaseBranch
config.
le.exports = {
errideBaseBranch: '<name of branch',
.