Github Plugin

Name

Github Issue Link

Description

Easily create links to Github issues

Icon

confirmation_number

Instructions

This plugin will allow you to easily create a reference to a GitHub issue. Given an issue number it will get the issue title and a link to the issue itself on GitHub.

This is primarily meant to set up Tasks in Amplenote that link to the corresponding issue on Github, but it is not limited to replacing text in a Task.

Usage
1. On the page where the task will go, add the owner/repo of the project in question, with a label of Github Project:
e.g. Github Project: darthmachina/amplenote-github
2. Wherever you want the title and link, type the issue number
3. Select the issue number
4. From the toolbar select Github Issue Link from the right most button menu


5. Sit back and watch as your number magically becomes some text and a link to Github!
e.g. created from my Note Reminder plugin repo:


Just to note, this does support the field syntax from the View Master plugin so two colons are allowed. i.e.. Github Project:: darthmachina/amplenote-github

linkVersion History

1.0.0

Initial public release

1.0.1

Added support inline field ::syntax

{
// --------------------------------------------------------------------------------------
constants: {
version: "1.0.1",
githubSlugRegex: /github project\s*:{1,2}\s*([a-z\/\-]+)/mi
},
 
// --------------------------------------------------------------------------
// https://www.amplenote.com/help/developing_amplenote_plugins#replaceText
replaceText: {
async run(app, text) {
if (text.indexOf('.') > -1 || isNaN(Number(text))) {
app.alert("You must select only a valid integer for the issue number");
return null
}
 
// Find project slug from note
const note = await app.notes.find(app.context.noteUUID);
const content = await note.content();
const project = this.constants.githubSlugRegex.exec(content);
if (!project || project.length != 2) {
app.alert("'Github Project:' must be specified on the note");
return null;
}
 
// Fetch issue information
const issue = await this._getIssueFromGithub(project[1], text);
if (!issue) {
app.alert("Error getting Issue from GitHub");
return null;
}
 
app.context.replaceSelection(`${issue.title} [Github](https://github.com/${project[1]}/issues/${text})`);
return null;
},
},
 
// --------------------------------------------------------------------------
async _getIssueFromGithub(projectSlug, issueId) {
console.log(`_getIssueFromGithub: ${projectSlug}, ${issueId}`);
const response = await fetch(
`https://api.github.com/repos/${projectSlug}/issues/${issueId}`,
{ method: 'GET', headers: {"Content-Type": "application/json"} }
);
 
if (!response.ok) {
console.error(`Github error: ${response.status}`);
return null
} else {
return await response.json();
}
},
}