forked from mirrors/probot
Add eslint-plugin-markdown to lint docs
This commit is contained in:
parent
c13e2831b0
commit
bb8e7136d8
|
@ -19,8 +19,8 @@ module.exports = robot => {
|
|||
const params = context.issue({body: 'Hello World!'})
|
||||
|
||||
// Post a comment on the issue
|
||||
return context.github.issues.createComment(params);
|
||||
});
|
||||
return context.github.issues.createComment(params)
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ A Probot app is just a [Node.js module](https://nodejs.org/api/modules.html) tha
|
|||
```js
|
||||
module.exports = robot => {
|
||||
// your code here
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
The `robot` parameter is an instance of [`Robot`](https://probot.github.io/probot/latest/Robot.html) and gives you access to all of the bot goodness.
|
||||
|
@ -20,9 +20,9 @@ The `robot` parameter is an instance of [`Robot`](https://probot.github.io/probo
|
|||
module.exports = robot => {
|
||||
robot.on('issues.opened', async context => {
|
||||
// A new issue was opened, what should we do with it?
|
||||
robot.log(context);
|
||||
});
|
||||
};
|
||||
robot.log(context)
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
The `context` passed to the event handler includes everything about the event that was triggered, as well as some helpful properties for doing something useful in response to the event. `context.github` is an authenticated GitHub client that can be used to [make API calls](./github-api.md), and allows you to do almost anything programmatically that you can do through a web browser on GitHub.
|
||||
|
@ -38,7 +38,7 @@ module.exports = robot => {
|
|||
const params = context.issue({body: 'Hello World!'})
|
||||
|
||||
// Post a comment on the issue
|
||||
return context.github.issues.createComment(params);
|
||||
});
|
||||
return context.github.issues.createComment(params)
|
||||
})
|
||||
}
|
||||
```
|
||||
|
|
10
docs/http.md
10
docs/http.md
|
@ -9,16 +9,16 @@ Calling `robot.route('/my-app')` will return an [express](http://expressjs.com/)
|
|||
```js
|
||||
module.exports = robot => {
|
||||
// Get an express router to expose new HTTP endpoints
|
||||
const app = robot.route('/my-app');
|
||||
const app = robot.route('/my-app')
|
||||
|
||||
// Use any middleware
|
||||
app.use(require('express').static(__dirname + '/public'));
|
||||
app.use(require('express').static('public'))
|
||||
|
||||
// Add a new route
|
||||
app.get('/hello-world', (req, res) => {
|
||||
res.end('Hello World');
|
||||
});
|
||||
};
|
||||
res.end('Hello World')
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
Visit https://localhost:3000/my-app/hello-world to access the endpoint.
|
||||
|
|
|
@ -7,9 +7,13 @@ next: docs/deployment.md
|
|||
Many GitHub API endpoints are paginated. The `github.paginate` method can be used to get each page of the results.
|
||||
|
||||
```js
|
||||
context.github.paginate(context.github.issues.getAll(context.repo()), res => {
|
||||
res.data.issues.forEach(issue => {
|
||||
robot.console.log('Issue: %s', issue.title);
|
||||
});
|
||||
});
|
||||
module.exports = robot => {
|
||||
robot.on('issues.opened', context => {
|
||||
context.github.paginate(context.github.issues.getAll(context.repo()), res => {
|
||||
res.data.issues.forEach(issue => {
|
||||
robot.console.log('Issue: %s', issue.title)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
```
|
||||
|
|
|
@ -10,22 +10,24 @@ For our testing examples, we use [mocha](https://mochajs.org/) and [expect](http
|
|||
|
||||
```js
|
||||
// Requiring our testing framework
|
||||
const expect = require('expect');
|
||||
const expect = require('expect')
|
||||
// Requiring probot allows us to mock out a robot instance
|
||||
const {createRobot} = require('probot');
|
||||
const {createRobot} = require('probot')
|
||||
// Requireing our app
|
||||
const app = require('')
|
||||
// Create a fixtures folder in your test folder
|
||||
// Then put any larger testing payloads in there
|
||||
const payload = require('./fixtures/payload');
|
||||
const payload = require('./fixtures/payload')
|
||||
|
||||
describe('your-app', () => {
|
||||
let robot;
|
||||
let github;
|
||||
let robot
|
||||
let github
|
||||
|
||||
beforeEach(() => {
|
||||
// Here we create a robot instance
|
||||
robot = createRobot();
|
||||
robot = createRobot()
|
||||
// Here we initialize the app on the robot instance
|
||||
app(robot);
|
||||
app(robot)
|
||||
// This is an easy way to mock out the GitHub API
|
||||
github = {
|
||||
issues: {
|
||||
|
@ -35,18 +37,18 @@ describe('your-app', () => {
|
|||
}
|
||||
}
|
||||
// Passes the mocked out GitHub API into out robot instance
|
||||
robot.auth = () => Promise.resolve(github);
|
||||
});
|
||||
robot.auth = () => Promise.resolve(github)
|
||||
})
|
||||
|
||||
describe('your functionality', () => {
|
||||
it('performs an action', async () => {
|
||||
// Simulates delivery of a payload
|
||||
await robot.receive(payload);
|
||||
await robot.receive(payload)
|
||||
// This test would pass if in your main code you called `context.github.issues.createComment`
|
||||
expect(github.issues.createComment).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
expect(github.issues.createComment).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
})
|
||||
```
|
||||
|
||||
A good testing example from [update-docs](https://github.com/behaviorbot/update-docs) can be found [here](https://github.com/behaviorbot/update-docs/blob/master/test/index.js), and another one from [owners](https://github.com/probot/owners) can be found [here](https://github.com/probot/owners/blob/master/test/owner-notifier.js).
|
||||
|
|
|
@ -12,9 +12,9 @@ Many robots will spend their entire day responding to these actions. `robot.on`
|
|||
module.exports = robot => {
|
||||
robot.on('push', async context => {
|
||||
// Code was pushed to the repo, what should we do with it?
|
||||
robot.log(context);
|
||||
});
|
||||
};
|
||||
robot.log(context)
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
The robot can listen to any of the [GitHub webhook events](https://developer.github.com/webhooks/#events). The `context` object includes everything about the event that was triggered, and `context.payload` has the payload delivered by GitHub.
|
||||
|
@ -25,6 +25,6 @@ Most events also include an "action". For example, the [`issues`](https://develo
|
|||
module.exports = robot => {
|
||||
robot.on('issues.opened', async context => {
|
||||
// An issue was just opened.
|
||||
});
|
||||
};
|
||||
})
|
||||
}
|
||||
```
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -9,7 +9,8 @@
|
|||
},
|
||||
"scripts": {
|
||||
"start": "node ./bin/probot run",
|
||||
"test": "mocha && standard",
|
||||
"test": "mocha && standard && npm run doc-lint",
|
||||
"doc-lint": "standard docs/**/*.md",
|
||||
"doc": "jsdoc -c .jsdoc.json",
|
||||
"postpublish": "script/publish-docs"
|
||||
},
|
||||
|
@ -36,7 +37,8 @@
|
|||
"semver": "^5.4.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint-plugin-standard": "^3.0.1",
|
||||
"eslint": "^4.6.1",
|
||||
"eslint-plugin-markdown": "^1.0.0-beta.6",
|
||||
"expect": "^1.20.2",
|
||||
"jsdoc": "^3.5.4",
|
||||
"jsdoc-strip-async-await": "^0.1.0",
|
||||
|
@ -48,6 +50,9 @@
|
|||
"standard": {
|
||||
"env": [
|
||||
"mocha"
|
||||
],
|
||||
"plugins": [
|
||||
"markdown"
|
||||
]
|
||||
},
|
||||
"engines": {
|
||||
|
|
Loading…
Reference in New Issue