Skip to content

Commit

Permalink
feat: parse multiple releases in changelogs (#3351)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsLando authored Oct 18, 2023
1 parent 9f45b50 commit e37d2cf
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 44 deletions.
4 changes: 2 additions & 2 deletions app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import express, { Request, RequestHandler, Response, Router } from 'express'

import { version } from './package.json'
import history from 'connect-history-api-fallback'
import cors from 'cors'
import csrf from 'csurf'
Expand Down Expand Up @@ -1155,7 +1155,7 @@ app.post(

// update versions to actual ones
settings.gateway.versions = {
app: utils.getVersion(),
app: version, // don't use getVersion here as it may include commit sha
driver: libVersion,
server: serverVersion,
}
Expand Down
165 changes: 123 additions & 42 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,44 @@ export default {
log.error(error)
}
},
async getChangelogs(project, prevTag, nextTag, parseChangelog) {
const changelogs = []
try {
const response = await fetch(
`https://api.github.com/repos/zwave-js/${project}/releases`
)
const data = await response.json()
let start = false
let maxParse = 10
for (const release of data) {
if (release.tag_name === prevTag) {
break
}
if (release.tag_name === nextTag) {
start = true
}
if (!start) continue
if (release.draft || release.prerelease) continue
changelogs.push(parseChangelog(release, changelogs.length))
if (--maxParse === 0) break
// if last version is not defined just print the last
if (!prevTag) break
}
} catch (error) {
log.error(error)
}
return changelogs
},
async checkChangelog() {
const settings = useBaseStore().gateway
Expand All @@ -1117,61 +1155,104 @@ export default {
if (settings?.disableChangelog) return
if (versions?.app !== this.appInfo.appVersion) {
const current = await this.getRelease(
const { default: md } = await import('markdown-it')
if (versions?.app !== currentVersion) {
const appChangelogs = await this.getChangelogs(
'zwave-js-ui',
'v' + currentVersion
)
const { default: md } = await import('markdown-it')
current.body = current.body.replace(
new RegExp(
`#+ \\[${currentVersion}\\]\\([^\\)]+\\)`,
'g'
),
`## Z-Wave JS UI [${current.tag_name}](https://github.com/zwave-js/zwave-js-ui/releases/tag/${current.tag_name})`
versions?.app ? 'v' + versions?.app : null,
'v' + currentVersion,
(release, i) => {
release.body = release.body.replace(
new RegExp(
`#+ \\[${release.tag_name.replace(
'v',
''
)}\\]\\([^\\)]+\\)`,
'g'
),
`${i === 0 ? '# UI\n---\n' : ''}## [${
release.tag_name
}](https://github.com/zwave-js/zwave-js-ui/releases/tag/${
release.tag_name
})`
)
let changelog = md()
.render(release.body)
.replace('</h2>', '</h2></br>')
if (i === 0) {
changelog = changelog.replace(
'<h2>',
'</br><h2>'
)
}
return changelog
}
)
let changelog = md()
.render(current.body)
.replace('</h2>', '</h2><br>')
let changelog = appChangelogs.join('</br>')
if (this.appInfo.zwaveVersion !== versions?.zwave) {
// get changelog from github latest release
const zwaveLatest = await this.getRelease(
if (this.appInfo.zwaveVersion !== versions?.driver) {
const driverChangelogs = await this.getChangelogs(
'node-zwave-js',
'v' + this.appInfo.zwaveVersion
versions?.driver ? 'v' + versions?.driver : null,
'v' + this.appInfo.zwaveVersion,
(release, i) => {
const changelog = md()
.render(release.body)
.replace(
/#(\d+)/g,
'<a href="https://github.com/zwave-js/node-zwave-js/pull/$1">#$1</a>'
)
return `${
i === 0
? '</br><h1>Driver</h1><hr><br>'
: ''
}<h2><a target="_blank" href="https://github.com/zwave-js/node-zwave-js/releases/tag/${
release.tag_name
}">${
release.tag_name
}</a></h2></br>${changelog}</br>`
}
)
const zwaveChangelog = md()
.render(zwaveLatest.body)
.replace(
/#(\d+)/g,
'<a href="https://github.com/zwave-js/node-zwave-js/pull/$1">#$1</a>'
)
changelog += `</br><h2>Driver <a target="_blank" href="https://github.com/zwave-js/node-zwave-js/releases/tag/${zwaveLatest.tag_name}">${zwaveLatest.tag_name}</a></h2></br>${zwaveChangelog}`
changelog += driverChangelogs.join('')
}
if (this.appInfo.serverVersion !== versions?.server) {
// get changelog from github latest release
const serverLatest = await this.getRelease(
const serverChangelogs = await this.getChangelogs(
'zwave-js-server',
this.appInfo.serverVersion
versions?.server || null,
this.appInfo.serverVersion,
(release, i) => {
const changelog = md()
.render(release.body)
.replace(
"<h2>What's Changed</h2>",
'<h3>Changes</h3>'
)
.replace(
/#(\d+)/g,
'<a href="https://github.com/zwave-js/zwave-js-server/pull/$1">#$1</a>'
)
return `${
i === 0
? '</br><h1>Server</h1><hr><br>'
: ''
}<h2><a target="_blank" href="https://github.com/zwave-js/zwave-js-server/releases/tag/${
release.tag_name
}">v${
release.tag_name
}</a></h2></br>${changelog}</br>`
}
)
const serverChangelog = md()
.render(serverLatest.body)
.replace(
"<h2>What's Changed</h2>",
'<h3>Changes</h3>'
)
.replace(
/#(\d+)/g,
'<a href="https://github.com/zwave-js/zwave-js-server/pull/$1">#$1</a>'
)
changelog += `</br><h2>Server <a target="_blank" href="https://github.com/zwave-js/zwave-js-server/releases/tag/${serverLatest.tag_name}">v${serverLatest.tag_name}</a></h2></br>${serverChangelog}`
changelog += serverChangelogs.join('')
}
// means we never saw the changelog for this version
Expand Down

0 comments on commit e37d2cf

Please sign in to comment.