issue-metadata
v0.2.3
Published
A NodeJS module to store metadata on GitHub Issues and Pull Requests.
Downloads
132
Readme
Issue Metadata
How to use
Creating the Metadata controller instance
import MetadataController from "issue-metadata";
const controller = new MetadataController('my_metadata_ID', {
owner: 'my_name',
repo: 'my_repo',
headers: {
authorization: `Bearer my_GITHUB_API_TOKEN`,
},
});
Store metadata on issue
await controller.setMetadata(1, 'foo', 'bar');
// In body of issue #1:
// <!-- my_metadata_ID = {"foo":"bar"} -->
await controller.setMetadata(1, { foo: 'bar' });
// In body of issue #1:
// <!-- my_metadata_ID = {"foo":"bar"} -->
await controller.setMetadata(1, 'complex', [{ bar: 'baz' }]);
// In body of issue #1:
// <!-- my_metadata_ID = {"complex":[{"bar":"baz"}]} -->
Get metadata stored on issue
// In body of issue #1:
// <!-- my_metadata_ID = {"foo":"bar"} -->
let metadata = await controller.getMetadata(1, 'foo');
// metadata === "bar"
// In body of issue #1:
// <!-- my_metadata_ID = {"foo":"bar"} -->
metadata = await controller.getMetadata(1);
// metadata === {foo: "bar"}
// In body of issue #1:
// <!-- my_metadata_ID = {"complex":[{"bar":"baz"}]} -->
metadata = await controller.getMetadata(1, 'complex');
// metadata === [{ bar: 'baz' }]
[!IMPORTANT]
In current implementation when setting metadata, it always overrides the previous metadata. For example:
// <!-- my_metadata_ID = {"foo":"bar", "complex":[{"bar":"baz"}]} --> await controller.setMetadata(1, 'complex', [{ foo: 'bar' }]); // In body of issue #1: // <!-- my_metadata_ID = {"foo":"bar", "complex":[{"foo":"bar"}]} -->