Skip to content

Commit

Permalink
Merge pull request #16 from abskmj/release/1.4.0
Browse files Browse the repository at this point in the history
Release/1.4.0
  • Loading branch information
abskmj authored Jul 26, 2020
2 parents f23316c + bee5297 commit 3fd2058
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 24 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
26 changes: 15 additions & 11 deletions lib/gh.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
19 changes: 12 additions & 7 deletions lib/git.js
Original file line number Diff line number Diff line change
@@ -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 = {}

Expand All @@ -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('[email protected]:', '')
.replace(/\.git$/, '')
info.repo = await getRepo()

console.log(info)

Expand Down
19 changes: 14 additions & 5 deletions lib/hukum.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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, ' ')
})
})

Expand All @@ -45,14 +52,16 @@ 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

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) => {
Expand All @@ -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, ' ')
}
})
}
Expand Down
3 changes: 2 additions & 1 deletion lib/print.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, ' ')
}
}

0 comments on commit 3fd2058

Please sign in to comment.