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')
}
@amichuda
Copy link

Hi! I'm trying to get this to work and I got as far as this running and outputting something in the console, but I'm not sure how to get this pasted into the currently active file with the gh-repo yaml. Can you help me out here?

@davish
Copy link
Author

davish commented Mar 15, 2022

You need to hook this up to the QuickAdd plugin. The documentation is kind of scattered, but I'd recommend watching the video in the README (https://github.com/chhoumann/quickadd) to get an idea of how to use it. I'll post my configuration below:

Screen Shot 2022-03-14 at 8 34 30 PM

In addition to adding this as a "Choice", you'll also need to download this file into your vault, and add it as a macro. QuickAdd has some documentation on how to do that.

I hope that helps @amichuda!

@amichuda
Copy link

This was the missing step, thank you!

@amichuda
Copy link

Wanted to leave this here in case it was interested. I adapted your code to make a general "GitHub Inbox" of all your repos that puts them in a file with headings.

https://gist.github.com/amichuda/bb5405031c302f657d0bfb950fa98a11

@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