diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..fc852b2 --- /dev/null +++ b/LICENSE @@ -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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..e9316ef --- /dev/null +++ b/README.md @@ -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 ``), 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 + + +``` diff --git a/package.json b/package.json new file mode 100644 index 0000000..78b3d5d --- /dev/null +++ b/package.json @@ -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" +}