The extensions that were in Toolshed's own repository, a folder each: brreg, dashboard-icons, databricks, docker, github, homebrew, norway, projects, scripts, secrets, wikipedia and yr. Toolshed installs them from here, in Settings → Extensions → From a repository, and the README says how
This commit is contained in:
44 files changed
+7978
-1
No files matched your search
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" viewBox="0 0 512 512"><path d="M256 6.3C114.6 6.3 0 120.9 0 262.3c0 113.3 73.3 209 175 242.9 12.8 2.2 17.6-5.4 17.6-12.2 0-6.1-.3-26.2-.3-47.7-64.3 11.8-81-15.7-86.1-30.1-2.9-7.4-15.4-30.1-26.2-36.2-9-4.8-21.8-16.6-.3-17 20.2-.3 34.6 18.6 39.4 26.2 23 38.7 59.8 27.8 74.6 21.1 2.2-16.6 9-27.8 16.3-34.2-57-6.4-116.5-28.5-116.5-126.4 0-27.8 9.9-50.9 26.2-68.8-2.6-6.4-11.5-32.6 2.6-67.8 0 0 21.4-6.7 70.4 26.2 20.5-5.8 42.2-8.6 64-8.6s43.5 2.9 64 8.6c49-33.3 70.4-26.2 70.4-26.2 14.1 35.2 5.1 61.4 2.6 67.8 16.3 17.9 26.2 40.6 26.2 68.8 0 98.2-59.8 120-116.8 126.4 9.3 8 17.3 23.4 17.3 47.4 0 34.2-.3 61.8-.3 70.4 0 6.7 4.8 14.7 17.6 12.2C438.7 471.3 512 375.3 512 262.3c0-141.4-114.6-256-256-256" style="fill-rule:evenodd;clip-rule:evenodd;fill:#fff"/></svg>
|
||||
|
After Width: | Height: | Size: 819 B |
@@ -0,0 +1,45 @@
|
||||
-- Says when the checks of a pull request of yours pass or fail, through gh. Toolshed runs it
|
||||
-- every minute, while it's turned on. What's been said is remembered, a commit's checks said once;
|
||||
-- the first time it runs, what's there already is noted.
|
||||
|
||||
local query = [[
|
||||
query {
|
||||
viewer {
|
||||
pullRequests(states: OPEN, first: 50) {
|
||||
nodes {
|
||||
number title url
|
||||
repository { nameWithOwner }
|
||||
commits(last: 1) { nodes { commit { oid statusCheckRollup { state } } } }
|
||||
}
|
||||
}
|
||||
}
|
||||
}]]
|
||||
|
||||
-- The checks' states that are an end, as GitHub names them.
|
||||
local ended = { SUCCESS = "say.passed", FAILURE = "say.failed", ERROR = "say.failed" }
|
||||
|
||||
local seen = toolshed.memory()
|
||||
local first = seen == nil
|
||||
seen = seen or {}
|
||||
|
||||
-- A failure ends this run; Toolshed runs it again a while later.
|
||||
local data = toolshed.json.decode(toolshed.exec({ "gh", "api", "graphql", "-f", "query=" .. query })).data
|
||||
|
||||
local now = {}
|
||||
for _, pr in ipairs(data.viewer.pullRequests.nodes) do
|
||||
local commit = pr.commits.nodes[1] and pr.commits.nodes[1].commit
|
||||
local state = commit and commit.statusCheckRollup and commit.statusCheckRollup.state
|
||||
if state then
|
||||
local was = seen[pr.url]
|
||||
now[pr.url] = { oid = commit.oid, state = state }
|
||||
local changed = not was or was.oid ~= commit.oid or was.state ~= state
|
||||
if not first and changed and ended[state] then
|
||||
local said = { repo = pr.repository.nameWithOwner, number = pr.number, title = pr.title }
|
||||
local data = { repo = pr.repository.nameWithOwner, number = tostring(math.floor(pr.number)), url = pr.url .. "/checks" }
|
||||
toolshed.notify(toolshed.t(ended[state], said), { tool = "pr", stay = state ~= "SUCCESS", actions = {
|
||||
{ title = toolshed.t("action.web"), action = "web", data = data },
|
||||
} })
|
||||
end
|
||||
end
|
||||
end
|
||||
toolshed.remember(now)
|
||||
+495
@@ -0,0 +1,495 @@
|
||||
-- GitHub, through the gh CLI, which signs in as it's set up to, so the extension never sees a
|
||||
-- token. "gh" offers Repos, Pull requests and Reviews: "gh toolshed" (or "gh repos toolshed")
|
||||
-- finds the repos you can reach, Enter opening one you've cloned, with the command the Open with
|
||||
-- setting names or in Finder, or cloning it in the background, saying when it's done; "gh prs"
|
||||
-- lists your open pull requests with how their checks and reviews stand, and "gh reviews" those
|
||||
-- you're asked to review; Enter opens one on GitHub. Within 15 seconds, reviews.lua says when
|
||||
-- you're asked to review one, and every minute checks.lua when the checks of yours pass or fail. Its text is in
|
||||
-- locales/.
|
||||
|
||||
local home = os.getenv("HOME")
|
||||
local cache = toolshed.cache_dir()
|
||||
local repos_file = cache .. "/repos.tsv"
|
||||
-- Listing every repo takes GitHub a few seconds a hundred, so it's done in the background once
|
||||
-- what's known is this old, searches using it meanwhile.
|
||||
local stale_seconds = 6 * 3600
|
||||
-- Pull requests change by the minute but not by the keystroke: asked again once this old.
|
||||
local prs_seconds = 30
|
||||
-- Looking through the repo folders for clones is cheap, but not on every keystroke.
|
||||
local clones_seconds = 10
|
||||
-- Search shows at most this many, as a launcher list shows no more.
|
||||
local most = 40
|
||||
-- Where repos are usually kept, as lazysecrets looks for them: those that hold repos are the
|
||||
-- folders setting's default.
|
||||
local usual_folders = { "git", "repo", "repos", "projects", "code", "source", "src" }
|
||||
|
||||
local quoted = toolshed.shell_quote
|
||||
|
||||
local modified = toolshed.file.modified
|
||||
|
||||
local read = toolshed.file.read
|
||||
|
||||
local function reason(err)
|
||||
return (tostring(err):gsub("^.-gh: ", ""):gsub("%s+", " "))
|
||||
end
|
||||
|
||||
local function problem(text)
|
||||
return { title = text, icon = "info", actions = {} }
|
||||
end
|
||||
|
||||
local function copy(text)
|
||||
toolshed.clipboard.copy(text)
|
||||
return toolshed.t("copied", { text = text })
|
||||
end
|
||||
|
||||
local function ago(iso)
|
||||
local y, mo, d, h, mi, s = (iso or ""):match("^(%d+)-(%d+)-(%d+)T(%d+):(%d+):(%d+)")
|
||||
if not y then return "" end
|
||||
-- GitHub's times are UTC; os.time reads a table as local time, so the difference is put back.
|
||||
local utc = os.time({ year = y, month = mo, day = d, hour = h, min = mi, sec = s })
|
||||
local offset = os.time() - os.time(os.date("!*t"))
|
||||
local seconds = math.max(0, os.time() - (utc + offset))
|
||||
if seconds < 3600 then return toolshed.t("ago.minutes", { count = math.floor(seconds / 60) }) end
|
||||
if seconds < 86400 then return toolshed.t("ago.hours", { count = math.floor(seconds / 3600) }) end
|
||||
return toolshed.t("ago.days", { count = math.floor(seconds / 86400) })
|
||||
end
|
||||
|
||||
-- Repo folders ---------------------------------------------------------------------------------
|
||||
|
||||
-- holds_repos says a folder has a repo one or two levels down, as repos are kept.
|
||||
local function holds_repos(path)
|
||||
local ok, out = pcall(toolshed.exec, { "find", path, "-mindepth", "2", "-maxdepth", "3", "-name", ".git", "-print", "-quit" })
|
||||
return ok and out:find("%S") ~= nil
|
||||
end
|
||||
|
||||
-- detected are the usual folders that hold repos, as ~/git, found as the extension loads so the
|
||||
-- setting starts out with them rather than empty.
|
||||
local function detected()
|
||||
local found = {}
|
||||
for _, name in ipairs(usual_folders) do
|
||||
if holds_repos(home .. "/" .. name) then table.insert(found, "~/" .. name) end
|
||||
end
|
||||
return found
|
||||
end
|
||||
|
||||
-- folders are where repos are kept: those the setting names, or else those found. A clone goes
|
||||
-- into the first.
|
||||
local function folders(settings)
|
||||
local chosen = {}
|
||||
local named = settings.folders or {}
|
||||
if #named == 0 then named = detected() end
|
||||
for _, f in ipairs(named) do table.insert(chosen, (f:gsub("^~", home))) end
|
||||
if #chosen == 0 then chosen = { home .. "/git" } end
|
||||
return chosen
|
||||
end
|
||||
|
||||
local clones_known, clones_at = nil, 0
|
||||
|
||||
-- github_name is the "owner/name" a remote's address points to on GitHub: git@github.com:o/n.git,
|
||||
-- https://github.com/o/n or a host alias of GitHub's in ~/.ssh/config (github.com-work:o/n).
|
||||
local function github_name(url)
|
||||
local rest = url:gsub("^[%w+.-]+://", ""):gsub("^[^@/]*@", "")
|
||||
local host, path = rest:match("^([^/:]+)[:/]+(.+)$")
|
||||
if not host or not host:lower():find("github") then return nil end
|
||||
local owner, name = path:gsub("%.git$", ""):gsub("/$", ""):match("^([^/]+)/([^/]+)$")
|
||||
return owner and (owner .. "/" .. name):lower()
|
||||
end
|
||||
|
||||
-- origin is the address of a clone's origin remote, read from its .git/config.
|
||||
local function origin(path)
|
||||
local config = read(path .. "/.git/config")
|
||||
if not config then return nil end
|
||||
local section = config:match('%[remote "origin"%]([^%[]*)')
|
||||
return section and section:match("\n%s*url%s*=%s*(%S+)")
|
||||
end
|
||||
|
||||
-- clones are the repos in the folders, one or two levels down, by the GitHub repo their origin
|
||||
-- remote points to: a folder named like a repo but cloned from elsewhere isn't its clone.
|
||||
local function clones(settings)
|
||||
if clones_known and os.time() - clones_at < clones_seconds then return clones_known end
|
||||
local found = {}
|
||||
for _, root in ipairs(folders(settings)) do
|
||||
local ok, out = pcall(toolshed.exec, { "find", root, "-mindepth", "2", "-maxdepth", "3", "-name", ".git" })
|
||||
if ok then
|
||||
for git in out:gmatch("[^\n]+") do
|
||||
local path = git:gsub("/%.git$", "")
|
||||
local name = github_name(origin(path) or "")
|
||||
if name and not found[name] then found[name] = path end
|
||||
end
|
||||
end
|
||||
end
|
||||
clones_known, clones_at = found, os.time()
|
||||
return found
|
||||
end
|
||||
|
||||
local function clone_of(settings, full_name)
|
||||
return clones(settings)[full_name:lower()]
|
||||
end
|
||||
|
||||
-- Repos ----------------------------------------------------------------------------------------
|
||||
|
||||
local function index_in_background()
|
||||
local jq = '.[] | [.full_name, (.description // "" | gsub("\\\\s+"; " ")), .language // "", .private, .fork, .archived, .pushed_at] | @tsv'
|
||||
toolshed.activities.set { key = "index", title = toolshed.t("jobs.index.title"), description = toolshed.t("jobs.index.description"), quiet = true, timeout = 300, run = { "sh", "-c", "gh api " ..
|
||||
quoted("user/repos?per_page=100&affiliation=owner,collaborator,organization_member") .. " --paginate --jq " .. quoted(jq) ..
|
||||
" > " .. quoted(repos_file .. ".tmp") .. " && mv " .. quoted(repos_file .. ".tmp") .. " " .. quoted(repos_file) } }
|
||||
end
|
||||
|
||||
local repos_known = { at = nil, list = {} }
|
||||
|
||||
-- repos are those you can reach, or nil and what to say instead: that they're being listed, or
|
||||
-- why that failed.
|
||||
local function repos()
|
||||
local at = modified(repos_file)
|
||||
if not at then
|
||||
local last = toolshed.activities.get("index")
|
||||
if last and (last.state == "failed" or last.state == "timed-out") then
|
||||
return nil, toolshed.t("error.repos", { reason = reason(last.reason) })
|
||||
end
|
||||
index_in_background()
|
||||
return nil, toolshed.t("listing")
|
||||
end
|
||||
if os.time() - at > stale_seconds then index_in_background() end
|
||||
if repos_known.at == at then return repos_known.list end
|
||||
local list = {}
|
||||
for line in (read(repos_file) or ""):gmatch("[^\n]+") do
|
||||
local name, description, language, private, fork, archived, pushed = line:match("^([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*)\t?(.*)$")
|
||||
if name then
|
||||
table.insert(list, { name = name, description = description, language = language, private = private == "true",
|
||||
fork = fork == "true", archived = archived == "true", pushed = pushed })
|
||||
end
|
||||
end
|
||||
repos_known = { at = at, list = list }
|
||||
return list
|
||||
end
|
||||
|
||||
local function repo_jig(settings, r)
|
||||
local path = clone_of(settings, r.name)
|
||||
local tags = {}
|
||||
if path then table.insert(tags, { text = toolshed.t("tag.cloned"), tint = "green", icon = "circle-check" }) end
|
||||
if r.private then table.insert(tags, { text = toolshed.t("tag.private"), icon = "lock" }) end
|
||||
if r.fork then table.insert(tags, { text = toolshed.t("tag.fork"), icon = "git-branch" }) end
|
||||
if r.archived then table.insert(tags, { text = toolshed.t("tag.archived"), tint = "orange" }) end
|
||||
local about = {}
|
||||
if r.description ~= "" then table.insert(about, r.description) end
|
||||
if r.language ~= "" then table.insert(about, r.language) end
|
||||
-- Enter opens what's cloned and clones what isn't.
|
||||
local actions = path and { "open", "web", "copy-ssh", "copy-https", "finder", "copy-path" } or { "clone", "web", "copy-ssh", "copy-https" }
|
||||
if not path and #folders(settings) > 1 then table.insert(actions, 2, "clone-into") end
|
||||
return {
|
||||
key = r.name, title = r.name:match("([^/]+)$"), subtitle = (r.name:match("^([^/]+)") .. " · " .. table.concat(about, " · ")):gsub(" · $", ""),
|
||||
tags = tags, tool = "repo", action = actions[1], actions = actions, data = { name = r.name, path = path },
|
||||
}
|
||||
end
|
||||
|
||||
local function repo_rows(settings, typed)
|
||||
local list, why = repos()
|
||||
if not list then return { problem(why) } end
|
||||
local matched = {}
|
||||
for _, r in ipairs(list) do
|
||||
local score = typed == "" and 0.5 or toolshed.match(typed, r.name)
|
||||
if score > 0 then
|
||||
-- What's cloned is what you work on, so it's first among equals; what's archived, last.
|
||||
if clone_of(settings, r.name) then score = score + 0.05 end
|
||||
if r.archived then score = score - 0.1 end
|
||||
table.insert(matched, { score = score, r = r })
|
||||
end
|
||||
end
|
||||
table.sort(matched, function(a, b)
|
||||
if a.score ~= b.score then return a.score > b.score end
|
||||
return (a.r.pushed or "") > (b.r.pushed or "")
|
||||
end)
|
||||
local jigs = {}
|
||||
for i = 1, math.min(#matched, most) do table.insert(jigs, repo_jig(settings, matched[i].r)) end
|
||||
return jigs
|
||||
end
|
||||
|
||||
-- with fills a command from the settings in for a repo's folder: "code {path}".
|
||||
local function with(command, path)
|
||||
return (command:gsub("{path}", function() return quoted(path) end))
|
||||
end
|
||||
|
||||
-- target_of is where a repo is cloned: by its name in the folder, or under its owner there when
|
||||
-- that name is taken, by another repo of the name cloned from elsewhere.
|
||||
local function target_of(settings, name, into)
|
||||
local folder = into or folders(settings)[1]
|
||||
local target = folder .. "/" .. name:match("([^/]+)$")
|
||||
if modified(target) then target = folder .. "/" .. name end
|
||||
return target
|
||||
end
|
||||
|
||||
local function shown(path)
|
||||
return (path:gsub("^" .. home:gsub("%p", "%%%0"), "~"))
|
||||
end
|
||||
|
||||
-- clone clones a repo in the background, shown while it runs and saying when it's done or why
|
||||
-- it failed, then runs the After cloning command. GIT_TERMINAL_PROMPT=0 makes git fail rather
|
||||
-- than wait for a password no one can type.
|
||||
local function clone(ctx, into)
|
||||
local name = ctx.data.name
|
||||
local target = target_of(ctx.settings, name, into)
|
||||
local said = { repo = name, path = shown(target) }
|
||||
toolshed.activities.set {
|
||||
key = "clone-" .. name:lower():gsub("[^%w_-]", "-"), tool = "repo",
|
||||
title = toolshed.t("cloning", said), icon = "download",
|
||||
run = { "env", "GIT_TERMINAL_PROMPT=0", "gh", "repo", "clone", name, target, "--", "--progress" },
|
||||
timeout = 3600,
|
||||
ending = { done = toolshed.t("cloned", said), failed = toolshed.t("error.clone", said) },
|
||||
after = { action = "cloned", data = { name = name, path = target } },
|
||||
}
|
||||
return toolshed.t("cloning", said)
|
||||
end
|
||||
|
||||
-- cloned runs as a clone ends: what's cloned is looked for again, and After cloning runs.
|
||||
local function cloned(ctx)
|
||||
clones_known = nil
|
||||
local after = (ctx.settings.after_clone or ""):gsub("^%s+", ""):gsub("%s+$", "")
|
||||
if ctx.data.activity.state == "done" and after ~= "" then
|
||||
toolshed.exec({ "sh", "-c", with(after, ctx.data.path) .. " >/dev/null 2>&1 &" })
|
||||
end
|
||||
end
|
||||
|
||||
-- open_clone opens a cloned repo with the Open with setting's command, or in Finder.
|
||||
local function open_clone(settings, path)
|
||||
local command = (settings.open_with or ""):gsub("^%s+", ""):gsub("%s+$", "")
|
||||
if command == "" then
|
||||
toolshed.open(path)
|
||||
else
|
||||
toolshed.exec({ "sh", "-c", with(command, path) })
|
||||
end
|
||||
end
|
||||
|
||||
-- Pull requests --------------------------------------------------------------------------------
|
||||
|
||||
local pr_query = [[
|
||||
query($q: String!) {
|
||||
search(query: $q, type: ISSUE, first: 50) {
|
||||
nodes {
|
||||
... on PullRequest {
|
||||
number title url isDraft updatedAt mergeable reviewDecision
|
||||
author { login }
|
||||
repository { nameWithOwner }
|
||||
commits(last: 1) { nodes { commit { statusCheckRollup { state } } } }
|
||||
}
|
||||
}
|
||||
}
|
||||
}]]
|
||||
|
||||
local searches = {
|
||||
prs = "is:open is:pr author:@me archived:false sort:updated-desc",
|
||||
reviews = "is:open is:pr review-requested:@me archived:false sort:updated-desc",
|
||||
}
|
||||
local prs_known = {}
|
||||
|
||||
local function pull_requests(which)
|
||||
local known = prs_known[which]
|
||||
if known and os.time() - known.at < prs_seconds then return known.list end
|
||||
local out = toolshed.json.decode(toolshed.exec({ "gh", "api", "graphql", "-F", "q=" .. searches[which], "-f", "query=" .. pr_query }))
|
||||
local list = {}
|
||||
for _, pr in ipairs(((out.data or {}).search or {}).nodes or {}) do
|
||||
if pr.number then table.insert(list, pr) end
|
||||
end
|
||||
prs_known[which] = { at = os.time(), list = list }
|
||||
return list
|
||||
end
|
||||
|
||||
-- checks says how a pull request's checks went, as a word and a tint.
|
||||
local function checks(pr)
|
||||
local commit = (((pr.commits or {}).nodes or {})[1] or {}).commit or {}
|
||||
local state = (commit.statusCheckRollup or {}).state
|
||||
if state == "SUCCESS" then return "passing", "green" end
|
||||
if state == "FAILURE" or state == "ERROR" then return "failing", "red" end
|
||||
if state == "PENDING" or state == "EXPECTED" then return "running", "orange" end
|
||||
return nil
|
||||
end
|
||||
|
||||
local review_tints = { APPROVED = "green", CHANGES_REQUESTED = "red", REVIEW_REQUIRED = "gray" }
|
||||
|
||||
local function pr_tags(pr)
|
||||
local tags = {}
|
||||
local how, tint = checks(pr)
|
||||
if how then table.insert(tags, { text = toolshed.t("checks." .. how), tint = tint }) end
|
||||
if review_tints[pr.reviewDecision] then
|
||||
table.insert(tags, { text = toolshed.t("review." .. pr.reviewDecision), tint = review_tints[pr.reviewDecision] })
|
||||
end
|
||||
if pr.isDraft then table.insert(tags, { text = toolshed.t("tag.draft") }) end
|
||||
if pr.mergeable == "CONFLICTING" then table.insert(tags, { text = toolshed.t("tag.conflicts"), tint = "red" }) end
|
||||
return tags
|
||||
end
|
||||
|
||||
-- pr_jig is a pull request as a row, which opens on GitHub: its tags say how it stands.
|
||||
local function pr_jig(pr, by)
|
||||
local about = { pr.repository.nameWithOwner .. "#" .. math.floor(pr.number), ago(pr.updatedAt) }
|
||||
if by and pr.author then table.insert(about, 2, pr.author.login) end
|
||||
return {
|
||||
key = pr.url, title = pr.title, subtitle = table.concat(about, " · "), icon = "git-pull-request", tags = pr_tags(pr), tool = "pr",
|
||||
action = "web", actions = { "web", "copy-url", "checkout" },
|
||||
data = { repo = pr.repository.nameWithOwner, number = tostring(math.floor(pr.number)), url = pr.url },
|
||||
}
|
||||
end
|
||||
|
||||
-- The words that filter pull requests by how they stand.
|
||||
local pr_words = {
|
||||
failing = function(pr) return checks(pr) == "failing" end,
|
||||
passing = function(pr) return checks(pr) == "passing" end,
|
||||
running = function(pr) return checks(pr) == "running" end,
|
||||
draft = function(pr) return pr.isDraft end,
|
||||
approved = function(pr) return pr.reviewDecision == "APPROVED" end,
|
||||
changes = function(pr) return pr.reviewDecision == "CHANGES_REQUESTED" end,
|
||||
conflicts = function(pr) return pr.mergeable == "CONFLICTING" end,
|
||||
}
|
||||
|
||||
local function pr_rows(which, typed)
|
||||
local ok, list = pcall(pull_requests, which)
|
||||
if not ok then return { problem(toolshed.t("error.prs", { reason = reason(list) })) } end
|
||||
local only, words = {}, {}
|
||||
for word in typed:lower():gmatch("%S+") do
|
||||
if pr_words[word] then table.insert(only, pr_words[word]) else table.insert(words, word) end
|
||||
end
|
||||
local named = table.concat(words, " ")
|
||||
local jigs = {}
|
||||
for _, pr in ipairs(list) do
|
||||
local fits = named == "" or toolshed.match(named, pr.repository.nameWithOwner .. " " .. pr.title) > 0
|
||||
for _, keep in ipairs(only) do fits = fits and keep(pr) end
|
||||
if fits then table.insert(jigs, pr_jig(pr, which == "reviews")) end
|
||||
end
|
||||
if #jigs == 0 then table.insert(jigs, problem(toolshed.t(#list == 0 and ("none." .. which) or "none.like"))) end
|
||||
return jigs
|
||||
end
|
||||
|
||||
-- gh -------------------------------------------------------------------------------------------
|
||||
|
||||
local verbs = {
|
||||
{ name = "repos", icon = "git-branch" },
|
||||
{ name = "prs", icon = "git-pull-request" },
|
||||
{ name = "reviews", icon = "eye" },
|
||||
}
|
||||
|
||||
-- The other names the verbs go by, as gh's own commands are named.
|
||||
local aliases = { repo = "repos", pr = "prs", pull = "prs", pulls = "prs", review = "reviews" }
|
||||
|
||||
local function verb_rows(word)
|
||||
local rows = {}
|
||||
for _, v in ipairs(verbs) do
|
||||
local fits = v.name:sub(1, #word) == word
|
||||
for alias, of in pairs(aliases) do
|
||||
if of == v.name and alias:sub(1, #word) == word then fits = true end
|
||||
end
|
||||
if fits then
|
||||
table.insert(rows, {
|
||||
key = v.name, title = toolshed.t("verb." .. v.name .. ".title"), subtitle = toolshed.t("verb." .. v.name .. ".description"),
|
||||
icon = v.icon, prefix = v.name .. " ", actions = {},
|
||||
})
|
||||
end
|
||||
end
|
||||
return rows
|
||||
end
|
||||
|
||||
-- listed is what's typed after gh: a verb and what to look for, or straight away a repo. A word
|
||||
-- on its own also offers the verbs it could become ("pr" → prs).
|
||||
local function listed(rest, settings)
|
||||
local word, typed = rest:match("^(%S+)%s*(.-)%s*$")
|
||||
if not word then return verb_rows("") end
|
||||
word = word:lower()
|
||||
local verb = aliases[word] or word
|
||||
if verb == "repos" then return repo_rows(settings, typed) end
|
||||
if verb == "prs" or verb == "reviews" then return pr_rows(verb, typed) end
|
||||
local rows = typed == "" and verb_rows(word) or {}
|
||||
for _, row in ipairs(repo_rows(settings, rest:match("^%s*(.-)%s*$"))) do table.insert(rows, row) end
|
||||
return rows
|
||||
end
|
||||
|
||||
return toolshed.toolbox {
|
||||
key = "github",
|
||||
title = "GitHub",
|
||||
description = "i18n:toolbox.description",
|
||||
icon = "assets/github.svg",
|
||||
tint = "gray",
|
||||
requires = { { command = "gh" } },
|
||||
settings = {
|
||||
{
|
||||
key = "folders", title = "i18n:setting.folders.title", description = "i18n:setting.folders.description",
|
||||
type = "folders", default = detected(),
|
||||
},
|
||||
{
|
||||
key = "open_with", title = "i18n:setting.open_with.title", description = "i18n:setting.open_with.description",
|
||||
type = "text", default = "", placeholder = "code {path}",
|
||||
},
|
||||
{
|
||||
key = "after_clone", title = "i18n:setting.after_clone.title", description = "i18n:setting.after_clone.description",
|
||||
type = "text", default = "", placeholder = "code {path}",
|
||||
},
|
||||
},
|
||||
background_jobs = {
|
||||
{ file = "reviews.lua", title = "i18n:jobs.reviews.title", description = "i18n:jobs.reviews.description", icon = "bell-ring", every = 15 },
|
||||
{ file = "checks.lua", title = "i18n:jobs.checks.title", description = "i18n:jobs.checks.description", icon = "circle-check", every = 60 },
|
||||
},
|
||||
-- Made from the settings, so Clone Into lists the repo folders as they're set.
|
||||
tools = function(settings)
|
||||
local into = {}
|
||||
for _, folder in ipairs(folders(settings)) do
|
||||
table.insert(into, { title = (folder:gsub("^" .. home:gsub("%p", "%%%0"), "~")), value = folder })
|
||||
end
|
||||
local repo_actions = {
|
||||
{ key = "open", title = "i18n:action.open", icon = "folder-open", run = function(ctx)
|
||||
local path = ctx.data.path or clone_of(ctx.settings, ctx.data.name)
|
||||
if not path then error(toolshed.t("error.not-cloned", { repo = ctx.data.name })) end
|
||||
open_clone(ctx.settings, path)
|
||||
end },
|
||||
{ key = "clone", title = "i18n:action.clone", icon = "download", run = function(ctx) return clone(ctx) end },
|
||||
{ key = "cloned", title = "i18n:action.cloned", run = cloned },
|
||||
{ key = "web", title = "i18n:action.web", icon = "external-link", run = function(ctx)
|
||||
toolshed.open("https://github.com/" .. ctx.data.name)
|
||||
end },
|
||||
{ key = "copy-ssh", title = "i18n:action.copy-ssh", icon = "copy", run = function(ctx)
|
||||
return copy("git@github.com:" .. ctx.data.name .. ".git")
|
||||
end },
|
||||
{ key = "copy-https", title = "i18n:action.copy-https", icon = "copy", run = function(ctx)
|
||||
return copy("https://github.com/" .. ctx.data.name .. ".git")
|
||||
end },
|
||||
{ key = "finder", title = "i18n:action.finder", icon = "folder-open", run = function(ctx)
|
||||
toolshed.open(clone_of(ctx.settings, ctx.data.name) or ctx.data.path)
|
||||
end },
|
||||
{ key = "copy-path", title = "i18n:action.copy-path", icon = "copy", run = function(ctx)
|
||||
return copy(ctx.data.path or clone_of(ctx.settings, ctx.data.name))
|
||||
end },
|
||||
}
|
||||
-- With one repo folder, Clone puts it there already.
|
||||
if #into > 1 then
|
||||
table.insert(repo_actions, 3, { key = "clone-into", title = "i18n:action.clone-into", icon = "download", variants = into, run = function(ctx)
|
||||
return clone(ctx, ctx.variant)
|
||||
end })
|
||||
end
|
||||
return {
|
||||
{
|
||||
key = "search",
|
||||
title = "i18n:tool.search.title",
|
||||
description = "i18n:tool.search.description",
|
||||
words = { "gh", "github" },
|
||||
keywords = { "github", "repo", "clone", "pull request", "review" },
|
||||
examples = { "gh toolshed", "gh prs", "gh prs failing", "gh reviews" },
|
||||
items = true,
|
||||
search = function(rest, settings) return listed(rest, settings) end,
|
||||
-- Its rows are the other tools' (a repo, a pull request), which do what they're chosen for.
|
||||
actions = { { key = "none", title = "i18n:tool.search.title", run = function() end } },
|
||||
},
|
||||
{
|
||||
key = "repo", title = "i18n:tool.repo.title", hidden = true, items = true,
|
||||
actions = repo_actions,
|
||||
},
|
||||
{
|
||||
key = "pr", title = "i18n:tool.pr.title", hidden = true, items = true,
|
||||
actions = {
|
||||
{ key = "web", title = "i18n:action.web", icon = "external-link", run = function(ctx) toolshed.open(ctx.data.url) end },
|
||||
{ key = "copy-url", title = "i18n:action.copy-url", icon = "copy", run = function(ctx) return copy(ctx.data.url) end },
|
||||
{ key = "checkout", title = "i18n:action.checkout", icon = "git-branch", run = function(ctx)
|
||||
local path = clone_of(ctx.settings, ctx.data.repo)
|
||||
if not path then error(toolshed.t("error.not-cloned", { repo = ctx.data.repo })) end
|
||||
toolshed.exec({ "sh", "-c", "cd " .. quoted(path) .. " && gh pr checkout " .. quoted(ctx.data.number) })
|
||||
return toolshed.t("checked-out", { number = ctx.data.number, repo = ctx.data.repo })
|
||||
end },
|
||||
},
|
||||
},
|
||||
}
|
||||
end,
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
[toolbox.description]
|
||||
other = "Your GitHub repos, to open or clone, your pull requests and those you're asked to review, with how their checks and reviews stand, through the gh CLI."
|
||||
|
||||
[setting.folders.title]
|
||||
other = "Repo folders"
|
||||
|
||||
[setting.folders.description]
|
||||
other = "Where your repos are, one or two levels down; a clone goes into the first. To start with, those of ~/git, ~/repos, ~/projects, ~/code, ~/source and ~/src that hold repos."
|
||||
|
||||
[tool.search.title]
|
||||
other = "GitHub"
|
||||
|
||||
[tool.search.description]
|
||||
other = "Repos, Pull requests and Reviews: gh toolshed finds a repo, gh prs your pull requests, gh reviews those you're asked to review."
|
||||
|
||||
[tool.repo.title]
|
||||
other = "Repo"
|
||||
|
||||
[tool.pr.title]
|
||||
other = "Pull Request"
|
||||
|
||||
[verb.repos.title]
|
||||
other = "Repos"
|
||||
|
||||
[verb.repos.description]
|
||||
other = "The repos you can reach, to open or clone"
|
||||
|
||||
[verb.prs.title]
|
||||
other = "Pull requests"
|
||||
|
||||
[verb.prs.description]
|
||||
other = "Your open pull requests; failing, draft or approved filters them"
|
||||
|
||||
[verb.reviews.title]
|
||||
other = "Reviews"
|
||||
|
||||
[verb.reviews.description]
|
||||
other = "Pull requests you're asked to review"
|
||||
|
||||
[action.open]
|
||||
other = "Open"
|
||||
|
||||
[action.web]
|
||||
other = "Open on GitHub"
|
||||
|
||||
[action.copy-ssh]
|
||||
other = "Copy SSH Address"
|
||||
|
||||
[action.copy-https]
|
||||
other = "Copy HTTPS Address"
|
||||
|
||||
[action.finder]
|
||||
other = "Show in Finder"
|
||||
|
||||
[action.copy-url]
|
||||
other = "Copy Link"
|
||||
|
||||
[action.checkout]
|
||||
other = "Check Out"
|
||||
|
||||
[listing]
|
||||
other = "Listing your repos, which takes a few seconds the first time"
|
||||
|
||||
[error.repos]
|
||||
other = "Couldn't list your repos: {{.reason}}"
|
||||
|
||||
[error.prs]
|
||||
other = "Couldn't get the pull requests: {{.reason}}"
|
||||
|
||||
[error.not-cloned]
|
||||
other = "{{.repo}} isn't cloned"
|
||||
|
||||
[tag.cloned]
|
||||
other = "Cloned"
|
||||
|
||||
[tag.private]
|
||||
other = "Private"
|
||||
|
||||
[tag.fork]
|
||||
other = "Fork"
|
||||
|
||||
[tag.archived]
|
||||
other = "Archived"
|
||||
|
||||
[tag.draft]
|
||||
other = "Draft"
|
||||
|
||||
[tag.conflicts]
|
||||
other = "Conflicts"
|
||||
|
||||
[checks.passing]
|
||||
other = "Checks pass"
|
||||
|
||||
[checks.failing]
|
||||
other = "Checks fail"
|
||||
|
||||
[checks.running]
|
||||
other = "Checks running"
|
||||
|
||||
[checks.skipped]
|
||||
other = "Skipped"
|
||||
|
||||
[review.APPROVED]
|
||||
other = "Approved"
|
||||
|
||||
[review.CHANGES_REQUESTED]
|
||||
other = "Changes requested"
|
||||
|
||||
[review.REVIEW_REQUIRED]
|
||||
other = "Review required"
|
||||
|
||||
[ago.minutes]
|
||||
other = "{{.count}} min ago"
|
||||
|
||||
[ago.hours]
|
||||
other = "{{.count}} h ago"
|
||||
|
||||
[ago.days]
|
||||
other = "{{.count}} d ago"
|
||||
|
||||
[copied]
|
||||
other = "Copied {{.text}}"
|
||||
|
||||
[checked-out]
|
||||
other = "Checked out #{{.number}} in {{.repo}}"
|
||||
|
||||
[action.clone]
|
||||
other = "Clone"
|
||||
|
||||
[action.clone-into]
|
||||
other = "Clone Into"
|
||||
|
||||
[setting.open_with.title]
|
||||
other = "Open with"
|
||||
|
||||
[setting.open_with.description]
|
||||
other = "A command that opens a cloned repo, {path} being its folder: code {path}. Empty, Finder opens it."
|
||||
|
||||
[setting.after_clone.title]
|
||||
other = "After cloning"
|
||||
|
||||
[setting.after_clone.description]
|
||||
other = "A command run when a clone is done, {path} being its folder: code {path}. Empty, nothing runs."
|
||||
|
||||
[action.copy-path]
|
||||
other = "Copy Path"
|
||||
|
||||
[action.cloned]
|
||||
other = "Cloned"
|
||||
|
||||
[cloning]
|
||||
other = "Cloning {{.repo}} into {{.path}}"
|
||||
|
||||
[cloned]
|
||||
other = "Cloned {{.repo}} into {{.path}}"
|
||||
|
||||
[error.clone]
|
||||
other = "Couldn't clone {{.repo}}"
|
||||
|
||||
[none.prs]
|
||||
other = "You have no open pull requests"
|
||||
|
||||
[none.reviews]
|
||||
other = "No one is waiting for your review"
|
||||
|
||||
[none.like]
|
||||
other = "No pull requests like that"
|
||||
|
||||
[say.review]
|
||||
other = "Review requested: {{.repo}}#{{.number}} {{.title}}"
|
||||
|
||||
[say.passed]
|
||||
other = "Checks passed: {{.repo}}#{{.number}} {{.title}}"
|
||||
|
||||
[say.failed]
|
||||
other = "Checks failed: {{.repo}}#{{.number}} {{.title}}"
|
||||
|
||||
[jobs.index.title]
|
||||
other = "Lists your repos"
|
||||
|
||||
[jobs.index.description]
|
||||
other = "Keeps the list of repos you can reach up to date"
|
||||
|
||||
[jobs.reviews.title]
|
||||
other = "Review requests"
|
||||
|
||||
[jobs.reviews.description]
|
||||
other = "Says when you're asked to review a pull request"
|
||||
|
||||
[jobs.checks.title]
|
||||
other = "Checks"
|
||||
|
||||
[jobs.checks.description]
|
||||
other = "Says when the checks of your pull requests pass or fail"
|
||||
@@ -0,0 +1,194 @@
|
||||
[toolbox.description]
|
||||
other = "Repoene dine på GitHub, å åpne eller klone, pull requestene dine og dem du er bedt om å se gjennom, med hvordan sjekker og gjennomganger står, gjennom gh CLI."
|
||||
|
||||
[setting.folders.title]
|
||||
other = "Repomapper"
|
||||
|
||||
[setting.folders.description]
|
||||
other = "Hvor repoene dine ligger, ett eller to nivåer ned; en klone havner i den første. Til å begynne med: de av ~/git, ~/repos, ~/projects, ~/code, ~/source og ~/src som har repoer."
|
||||
|
||||
[tool.search.title]
|
||||
other = "GitHub"
|
||||
|
||||
[tool.search.description]
|
||||
other = "Repoer, pull requester og gjennomganger: gh toolshed finner et repo, gh prs pull requestene dine, gh reviews dem du er bedt om å se gjennom."
|
||||
|
||||
[tool.repo.title]
|
||||
other = "Repo"
|
||||
|
||||
[tool.pr.title]
|
||||
other = "Pull request"
|
||||
|
||||
[verb.repos.title]
|
||||
other = "Repoer"
|
||||
|
||||
[verb.repos.description]
|
||||
other = "Repoene du har tilgang til, å åpne eller klone"
|
||||
|
||||
[verb.prs.title]
|
||||
other = "Pull requester"
|
||||
|
||||
[verb.prs.description]
|
||||
other = "Dine åpne pull requester; failing, draft eller approved filtrerer dem"
|
||||
|
||||
[verb.reviews.title]
|
||||
other = "Gjennomganger"
|
||||
|
||||
[verb.reviews.description]
|
||||
other = "Pull requester du er bedt om å se gjennom"
|
||||
|
||||
[action.open]
|
||||
other = "Åpne"
|
||||
|
||||
[action.web]
|
||||
other = "Åpne på GitHub"
|
||||
|
||||
[action.copy-ssh]
|
||||
other = "Kopier SSH-adresse"
|
||||
|
||||
[action.copy-https]
|
||||
other = "Kopier HTTPS-adresse"
|
||||
|
||||
[action.finder]
|
||||
other = "Vis i Finder"
|
||||
|
||||
[action.copy-url]
|
||||
other = "Kopier lenke"
|
||||
|
||||
[action.checkout]
|
||||
other = "Sjekk ut"
|
||||
|
||||
[listing]
|
||||
other = "Henter repoene dine, som tar noen sekunder første gang"
|
||||
|
||||
[error.repos]
|
||||
other = "Klarte ikke å hente repoene: {{.reason}}"
|
||||
|
||||
[error.prs]
|
||||
other = "Klarte ikke å hente pull requestene: {{.reason}}"
|
||||
|
||||
[error.not-cloned]
|
||||
other = "{{.repo}} er ikke klonet"
|
||||
|
||||
[tag.cloned]
|
||||
other = "Klonet"
|
||||
|
||||
[tag.private]
|
||||
other = "Privat"
|
||||
|
||||
[tag.fork]
|
||||
other = "Fork"
|
||||
|
||||
[tag.archived]
|
||||
other = "Arkivert"
|
||||
|
||||
[tag.draft]
|
||||
other = "Utkast"
|
||||
|
||||
[tag.conflicts]
|
||||
other = "Konflikter"
|
||||
|
||||
[checks.passing]
|
||||
other = "Sjekker OK"
|
||||
|
||||
[checks.failing]
|
||||
other = "Sjekker feiler"
|
||||
|
||||
[checks.running]
|
||||
other = "Sjekker kjører"
|
||||
|
||||
[checks.skipped]
|
||||
other = "Hoppet over"
|
||||
|
||||
[review.APPROVED]
|
||||
other = "Godkjent"
|
||||
|
||||
[review.CHANGES_REQUESTED]
|
||||
other = "Endringer ønsket"
|
||||
|
||||
[review.REVIEW_REQUIRED]
|
||||
other = "Trenger gjennomgang"
|
||||
|
||||
[ago.minutes]
|
||||
other = "for {{.count}} min siden"
|
||||
|
||||
[ago.hours]
|
||||
other = "for {{.count}} t siden"
|
||||
|
||||
[ago.days]
|
||||
other = "for {{.count}} d siden"
|
||||
|
||||
[copied]
|
||||
other = "Kopierte {{.text}}"
|
||||
|
||||
[checked-out]
|
||||
other = "Sjekket ut #{{.number}} i {{.repo}}"
|
||||
|
||||
[action.clone]
|
||||
other = "Klon"
|
||||
|
||||
[action.clone-into]
|
||||
other = "Klon til"
|
||||
|
||||
[setting.open_with.title]
|
||||
other = "Åpne med"
|
||||
|
||||
[setting.open_with.description]
|
||||
other = "En kommando som åpner et klonet repo, der {path} er mappen: code {path}. Tom: Finder åpner det."
|
||||
|
||||
[setting.after_clone.title]
|
||||
other = "Etter kloning"
|
||||
|
||||
[setting.after_clone.description]
|
||||
other = "En kommando som kjøres når en kloning er ferdig, der {path} er mappen: code {path}. Tom: ingenting kjøres."
|
||||
|
||||
[action.copy-path]
|
||||
other = "Kopier sti"
|
||||
|
||||
[action.cloned]
|
||||
other = "Klonet"
|
||||
|
||||
[cloning]
|
||||
other = "Kloner {{.repo}} til {{.path}}"
|
||||
|
||||
[cloned]
|
||||
other = "Klonet {{.repo}} til {{.path}}"
|
||||
|
||||
[error.clone]
|
||||
other = "Klarte ikke å klone {{.repo}}"
|
||||
|
||||
[none.prs]
|
||||
other = "Du har ingen åpne pull requester"
|
||||
|
||||
[none.reviews]
|
||||
other = "Ingen venter på at du skal se gjennom"
|
||||
|
||||
[none.like]
|
||||
other = "Ingen slike pull requester"
|
||||
|
||||
[say.review]
|
||||
other = "Ber om gjennomgang: {{.repo}}#{{.number}} {{.title}}"
|
||||
|
||||
[say.passed]
|
||||
other = "Sjekkene gikk gjennom: {{.repo}}#{{.number}} {{.title}}"
|
||||
|
||||
[say.failed]
|
||||
other = "Sjekkene feilet: {{.repo}}#{{.number}} {{.title}}"
|
||||
|
||||
[jobs.index.title]
|
||||
other = "Lister repoene dine"
|
||||
|
||||
[jobs.index.description]
|
||||
other = "Holder listen over repoene du har tilgang til oppdatert"
|
||||
|
||||
[jobs.reviews.title]
|
||||
other = "Forespørsler om gjennomgang"
|
||||
|
||||
[jobs.reviews.description]
|
||||
other = "Sier fra når du blir bedt om å se gjennom en pull request"
|
||||
|
||||
[jobs.checks.title]
|
||||
other = "Sjekker"
|
||||
|
||||
[jobs.checks.description]
|
||||
other = "Sier fra når sjekkene til pull requestene dine går gjennom eller feiler"
|
||||
@@ -0,0 +1,34 @@
|
||||
-- Says when you're asked to review a pull request, through gh. Toolshed runs it every 15 seconds,
|
||||
-- while it's turned on: GitHub can't push to a Mac, and a search that often uses a fraction of
|
||||
-- what GraphQL allows an hour. What's been said is remembered, so nothing is said twice; the first time
|
||||
-- it runs, what's there already is noted.
|
||||
|
||||
local query = [[
|
||||
query {
|
||||
search(query: "is:pr is:open review-requested:@me", type: ISSUE, first: 50) {
|
||||
nodes { ... on PullRequest { number title url repository { nameWithOwner } } }
|
||||
}
|
||||
}]]
|
||||
|
||||
local seen = toolshed.memory()
|
||||
local first = seen == nil
|
||||
seen = seen or {}
|
||||
|
||||
-- A failure ends this run; Toolshed runs it again a while later.
|
||||
local data = toolshed.json.decode(toolshed.exec({ "gh", "api", "graphql", "-f", "query=" .. query })).data
|
||||
|
||||
local now = {}
|
||||
for _, pr in ipairs(data.search.nodes) do
|
||||
if pr.url then
|
||||
now[pr.url] = true
|
||||
if not first and not seen[pr.url] then
|
||||
local said = { repo = pr.repository.nameWithOwner, number = pr.number, title = pr.title }
|
||||
local data = { repo = pr.repository.nameWithOwner, number = tostring(math.floor(pr.number)), url = pr.url }
|
||||
toolshed.notify(toolshed.t("say.review", said), { tool = "pr", stay = true, actions = {
|
||||
{ title = toolshed.t("action.web"), action = "web", data = data },
|
||||
{ title = toolshed.t("action.copy-url"), action = "copy-url", data = data },
|
||||
} })
|
||||
end
|
||||
end
|
||||
end
|
||||
toolshed.remember(now)
|
||||
Reference in new issue
Block a user