Skip to content

Instantly share code, notes, and snippets.

@davish
Created February 23, 2022 03:40
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davish/90935658e1a43dc4e0e22e61b3eaf2eb to your computer and use it in GitHub Desktop.
Save davish/90935658e1a43dc4e0e22e61b3eaf2eb to your computer and use it in GitHub Desktop.
module.exports = async (params) => {
const {app} = params;
let file = app.workspace.getMostRecentLeaf()?.view?.file;
if (!file) {
return;
}
let frontmatter = app.metadataCache.getFileCache(file)?.frontmatter;
let repo = frontmatter["gh-repo"]
if (!repo) {
return;
}
const url = `https://api.github.com/repos/${repo}/issues`
const text = await request({ url, method: "GET" });
let issues = null;
try {
issues = JSON.parse(text)
} catch (e) {
return;
}
let fileContent = await app.vault.cachedRead(file)
const marker = (number) => `gh${number}`
return issues
.filter(issue => fileContent.indexOf(marker(issue.number)) === -1)
.map(issue => `- [ ] ([${marker(issue.number)}](${issue.html_url})) ${issue.title}`)
.join('\n')
}
@davish
Copy link
Author

davish commented Mar 19, 2022

This is awesome, @amichuda! Thanks for sharing :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment