Ian Jones

Ian Jones

// Name: tana-github
import "@johnlindquist/kit";
const { Octokit } = await npm("octokit");
const UrlPattern = await npm("url-pattern");
const client = new Octokit({
auth: await env("GITHUB_PULLREQUEST_TOKEN"),
});
const repoPattern = new UrlPattern(
"(http(s)\\://)(:subdomain.):domain.:tld(\\::port)(/:owner)(/:repo)/pull(/:id)"
);
const tab = await getActiveTab("Brave");
const { owner, repo, id } = repoPattern.match(tab);
const res = await client.rest.pulls.get({
owner,
repo,
pull_number: id,
});
const { title, user, html_url } = res.data;
await copy(`%%tana%%
- ${title} #pull request
- Pull Request URL:: ${html_url}
- Github User:: ${user.login}
`);

// Name: Copy text sans brackets
// Description: Remove wiki links from selected text
// Shortcut: cmd + [
// Author: Ian Jones
// Twitter: @_jonesian
import "@johnlindquist/kit"
const text = await getSelectedText()
const newText = text.split("\n").map(text => {
return text.split(' ').map((word, i, arr) => {
if(!word) {
return
}
const FULL_BRACES_MATCH = /\[\[(.*?)\]\]/
const LEFT_MATCH = /\[\[/
const RIGHT_MATCH = /\]\]/
const [_, fullMatch] = word.match(FULL_BRACES_MATCH) ?? []
const [leftMatch] = word.match(LEFT_MATCH) ?? []
const [rightMatch] = word.match(RIGHT_MATCH) ?? []
if(!!fullMatch){
return fullMatch
} else if (!!leftMatch) {
const restOfArr = arr.slice(i + 1)
const restOfLink = restOfArr.reduce((acc, curr) => {
if(acc.endFound){
return acc
}
const [rightMatch] = curr.match(RIGHT_MATCH) ?? []
return {endFound: !!rightMatch, str: acc.str + " " + curr}
}, {endFound: false, str: ''}).str
const [_, match] = (word + restOfLink).match(FULL_BRACES_MATCH) ?? []
return match
} else if (rightMatch){
return
}else {
return word
}
}).join(' ')
}).join("\n")
if(newText){
await copy(newText)
}