https://github.com/unix/cobot
A user-experience-focused middleware for building Gitlab applications
https://github.com/unix/cobot
Last synced: 9 months ago
JSON representation
A user-experience-focused middleware for building Gitlab applications
- Host: GitHub
- URL: https://github.com/unix/cobot
- Owner: unix
- License: mit
- Created: 2019-03-11T10:58:15.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-09T16:43:00.000Z (about 3 years ago)
- Last Synced: 2025-03-18T00:43:39.388Z (9 months ago)
- Language: TypeScript
- Homepage: https://cobot.lambdas.dev/
- Size: 143 KB
- Stars: 14
- Watchers: 3
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## cobot
A user-experience-focused middleware for building Gitlab applications. [more examples](https://github.com/unix/cobot/blob/master/examples/).
Support frameworks: [Express](https://github.com/expressjs/express) / [Koa](https://github.com/koajs/koa).
### Why cobot?
- NO APIS
- Friendly user experience design
- Include `.d.ts`, support for automatic completion in editor.
- Semantic actions.
### How to use
1. install robot: `yarn add cobot` or `npm i cobot`.
2. import to your nodejs server:
```ts
// express
import cobot, { BotEvents } from 'cobot'
app.use(cobot.express())
// koa2
app.use(cobot.koa())
```
3. set webhook on gitlab: `Settings > integrations > url('http://{yourhost}/{any}') > Add webhook`. you can fill in any api with your nodjes server, robot automatically identifies requests from webhooks.
### Example
#### 1. Print `ok` when webhook is triggered.
```ts
const bot = cobot.lift()
bot.on(BotEvents.MergeRequest, context => console.log('ok'))
```
#### 2. Reply `thanks your issue` when a new issue opened.
```ts
const bot = cobot.lift()
bot.on(BotEvents.IssueOnOpen, context => {
context.actions.reply('thanks your issue')
})
```
#### 3. Use await/async in callback
```ts
const bot = cobot.lift()
bot.on(BotEvents.MergeRequest, async(context) => {
const notes = await context.actions.findNotes()
console.log(notes)
})
```
#### 4. Don't worry about interfaces and methods

### Support events
```ts
BotEvents = [
'CommentOnIssue',
'CommentOnCommit',
'CommentOnSnippet',
'CommentOnMergeRequest',
'MergeRequest',
'WikiCreate',
'WikiUpdate',
'WikiDelete',
'WikiOnAnyAction',
'PipelineOnRunning',
'PipelineOnPending',
'PipelineOnSuccess',
'PipelineOnFailed',
'PipelineOnCanceled',
'PipelineOnSkipped',
'PipelineOnAnyStatus',
'BuildOnAnyStatus',
'Push',
'Tag',
'IssueOnAnyAction',
'IssueOnOpen',
'IssueOnUpdate',
'IssueOnClose',
'IssueOnReopen',
]
```
### LICENSE
[MIT](LICENSE)