Skip to content

Commit

Permalink
README driven development
Browse files Browse the repository at this point in the history
  • Loading branch information
bkeepers committed Sep 7, 2017
0 parents commit 6f192bf
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
15 changes: 15 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ISC License

Copyright (c) 2017 Brandon Keepers

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Probot: metadata

A [Probot](https://github.com/probot/probot) extension to store metadata on an Issue and Pull Request.

## Usage

```js
const metadata = require('probot-metadata');

// where `context` is either a Probot `Context`, or an object with `owner`, `repo`, and `number values`
metadata.set(context, key, value);
const value = await metadata.get(context, key)
```

## Example

```js
const metadata = require('probot-metadata');

module.exports = robot => {
robot.on('issue_comment.created', context => {
match = context.payload.comment.body.match('/snooze (.*)')
if(match) {
metadata.set(context, 'snooze', match[1]);
}
})
}
```

## How it works

This extension is what you might call "a hack". GitHub doesn't have an API for storing metadata on Issues and Pull Requests, but it does have rather large comment fields. GitHub renders the comments as Markdown and will strip any unsupported HTML (including HTML comments like `<!-- I can put whatever I want here -->`), but still serves up the raw comment body through the API. This extension takes advantage of this "feature" to store JSON values on Issues and Pull Requests as HTML comments.

It will update the body of the original post and append an HTML comment with JSON values for each key. For example:

```markdown
This is the body of the original post

<!-- probot = {"json": "here"} -->
```
22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "probot-kv",
"version": "1.0.0",
"description": "Hack to key/value support to GitHub Issues & Pull Requests",
"main": "index.js",
"scripts": {
"test": "mocha"
},
"repository": {
"type": "git",
"url": "git+https://github.com/probot/kv.git"
},
"keywords": [
"probot"
],
"author": "Brandon Keepers",
"license": "ISC",
"bugs": {
"url": "https://github.com/probot/kv/issues"
},
"homepage": "https://github.com/probot/kv#readme"
}

0 comments on commit 6f192bf

Please sign in to comment.