diff --git a/CHANGELOG.md b/CHANGELOG.md index 5aa6422..96a43d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,23 @@ # Changelog +## [1.4.0] +### Added +- Add the workflow name and link to the output. +``` +Update a draft + Mirror to Gitlab (https://github.com/abskmj/notes/actions/runs/174602505) + ✔ gitlab 17s + ✔ Complete job 0s + Deploy to GH Pages (https://github.com/abskmj/notes/actions/runs/174602501) + ✔ deploy 15s + ✔ Complete job 0s +``` +### Fixed +- Fix repository owner and name detection for some remote URLs using a regular expression. +``` +/github.com[/:](.*?)\/(.*?)\.git$/g +``` + ## [1.3.0] ### Added - Add needed scope for the Github personal token to the documentation. diff --git a/lib/gh.js b/lib/gh.js index 41af6df..7a6551a 100644 --- a/lib/gh.js +++ b/lib/gh.js @@ -21,27 +21,31 @@ module.exports.getRepo = (repo) => { } const http = axios.create(options) + const getRuns = async (branch) => { const res = await http.get(`/runs?branch=${branch}`) - if (res && res.data && res.data.workflow_runs) { - return res.data.workflow_runs - } else { - throw UnexpectedResponseError(res) - } + if (res && res.data && res.data.workflow_runs) return res.data.workflow_runs + else throw UnexpectedResponseError(res) } const getJobs = async (run) => { const res = await http.get(`/runs/${run}/jobs`) - if (res && res.data && res.data.jobs) { - return res.data.jobs - } else { - throw UnexpectedResponseError(res) - } + if (res && res.data && res.data.jobs) return res.data.jobs + else throw UnexpectedResponseError(res) } + + const getWorkflow = async (workflow) => { + const res = await http.get(`/workflows/${workflow}`) + + if (res && res.data && res.data.name) return res.data + else throw UnexpectedResponseError(res) + } + return { getRuns, - getJobs + getJobs, + getWorkflow } } diff --git a/lib/git.js b/lib/git.js index ba96731..1d17022 100644 --- a/lib/git.js +++ b/lib/git.js @@ -1,6 +1,17 @@ const git = require('simple-git')() +const getRepo = async () => { + const remotes = await git.getRemotes(true) + const gh = remotes.find((remote) => remote.refs.push.includes('github.com')) + + const mataches = gh.refs.push.matchAll(/github.com[/:](.*?)\/(.*?)\.git$/g) + + for (const match of mataches) { + return `${match[1]}/${match[2]}` + } +} + module.exports.getInfo = async () => { const info = {} @@ -12,13 +23,7 @@ module.exports.getInfo = async () => { info.hash = log.latest.hash info.author = log.latest.author_email - const remotes = await git.getRemotes(true) - const gh = remotes.find((remote) => remote.refs.push.includes('github.com')) - - info.repo = gh.refs.push - .replace('https://github.com/', '') - .replace('git@github.com:', '') - .replace(/\.git$/, '') + info.repo = await getRepo() console.log(info) diff --git a/lib/hukum.js b/lib/hukum.js index 2d78e6c..24a8c1d 100644 --- a/lib/hukum.js +++ b/lib/hukum.js @@ -19,10 +19,17 @@ module.exports.start = async () => { const triggeredRuns = runs.filter((run) => run.head_branch === gitInfo.branch && run.head_sha === gitInfo.hash) + // add workflow info + for (let index = 0; index < triggeredRuns.length; index++) { + const run = triggeredRuns[index] + run.workflow = await repo.getWorkflow(run.workflow_id) + } + if (triggeredRuns.length === 1) { const run = triggeredRuns[0] - console.log('\n ', link(run.head_commit.message, run.html_url)) + console.log('\n ', run.head_commit.message) + console.log(' ', link(run.workflow.name, run.html_url)) while (true) { let jobsComplete = true @@ -32,10 +39,10 @@ module.exports.start = async () => { jobs.map((job) => { jobsComplete = jobsComplete && job.status === 'completed' - printer.printItem(job, job.id, ' ') + printer.printItem(job, job.id, ' ') job.steps.map((step) => { - printer.printItem(step, step.number, ' ') + printer.printItem(step, step.number, ' ') }) }) @@ -45,7 +52,7 @@ module.exports.start = async () => { } } else if (triggeredRuns.length > 1) { const run = triggeredRuns[0] - console.log('\n ', link(run.head_commit.message, run.html_url)) + console.log('\n ', run.head_commit.message) while (true) { let jobsComplete = true @@ -53,6 +60,8 @@ module.exports.start = async () => { for (let index = 0; index < triggeredRuns.length; index++) { const run = triggeredRuns[index] + printer.printItem(link(run.workflow.name, run.html_url), run.workflow_id, ' ') + const jobs = await repo.getJobs(run.id) jobs.map((job) => { @@ -70,7 +79,7 @@ module.exports.start = async () => { const step = job.steps.find((step) => step.status === 'in_progress') if (step) printer.printItem(step, stepId, ' ') - else printer.printItem({}, stepId, ' ') + else printer.printItem(' ', stepId, ' ') } }) } diff --git a/lib/print.js b/lib/print.js index e654ca2..ef44b64 100644 --- a/lib/print.js +++ b/lib/print.js @@ -39,6 +39,7 @@ module.exports.printItem = (item, id, indent) => { colors.grey(`${figures.ellipsis} ${item.name}`) ) } else { - draft(indent, ' ') + if (item) draft(indent, item) + else draft(indent, ' ') } }