probot / metadata

A Probot extension to store metadata on Issues and Pull Requests

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow .set with an issue before its been created

JasonEtco opened this issue · comments

If I understand the code correctly, calling .set() requires there to be an existing issue. In todo, I end the main handler by creating an issue so if I wanted to store metadata on it I'd have to first make a request to create an issue then call .set()

It would be cool to be able to pass an issue to .set() and have it return that issue + the metadata comment (instead of editing an issue on GitHub).

Proposed API

const myIssue = context.issue({ body: 'Hello! I do not exist yet!' })
const issueWithMetadata = await metadata(context).set('foo', 'bar', myIssue)

console.log(issueWithMetadata)
// { ... body: 'Hello! I do not exist yet!\n\n<!--probot = { json: { todo: { foo: 'bar' } } } -->'

// Now I actually create my issue:
context.github.issues.create(issueWithMetadata)

Let me know what y'all think 🙇

Oooh, that's interesting. Originally I was hoping this package could abstract the implementation details of how metadata was stored so it could change if there was ever a storage API added. That definitely comes at the cost of extra API requests though, so I'm open to adding support for reading/writing metadata without actually making the call to GitHub.

Instead of passing a context that doesn't get used and overloading set and get, what would you think about adding new methods? One option is to call get/set directly on metadata without passing it a context:

# Actually make the API calls
const value = metadata(context).get(key);
metadata(context).set(key, value);

# Just get/set the data
const value = metadata.get(body, key);
const newBody = metadata.set(body, key, value);

I dig that API.

Thinking aloud, what about one API that checks for the first arg's type?

const value = metadata(context).get(key);
metadata(context).set(key, value);

const value = metadata(body).get(key);
const newBody = metadata(body).set(key, value);

If the first argument to metadata() is an object, go the first route. If its a string, go the second route.

commented

Is this still relevant? If so, please comment with any updates or addition details.