Skip to content

Commit

Permalink
refactor: update changelog logic to show the markdown as it is
Browse files Browse the repository at this point in the history
instead of trying to parse into a structured format
  • Loading branch information
kabaros committed Jan 24, 2025
1 parent 60cdfae commit cd51dcb
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 142 deletions.
5 changes: 3 additions & 2 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
"build": "cross-env NODE_ENV=production webpack --mode production --progress --config ./webpack.config.js",
"start": "cross-env NODE_ENV=development webpack serve",
"test": "cross-env NODE_ENV=test jest",
"format": "yarn format:js && yarn format:text",
"format": "yarn format:js && yarn format:text && yarn format:css",
"format:staged": "yarn format:js --staged && yarn format:text --staged",
"format:js": "d2-style apply js",
"format:text": "d2-style apply text"
"format:text": "d2-style apply text",
"format:css": "d2-style apply css"
},
"dependencies": {
"@auth0/auth0-react": "^1.6.0",
Expand Down
41 changes: 4 additions & 37 deletions client/src/components/Versions/VersionsTable/VersionsTable.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import ReactMarkdown from 'react-markdown'
import { useAuth0 } from '@auth0/auth0-react'
import { Divider } from '@dhis2/ui'
import PropTypes from 'prop-types'
import { useCallback, useEffect, useState } from 'react'
import { getFormattedChangeType } from '../../../utils/changelog'
import styles from './VersionsTable.module.css'
import config from 'config'
import { renderDhisVersionsCompatibility } from 'src/lib/render-dhis-versions-compatibility'
Expand Down Expand Up @@ -84,42 +84,9 @@ const VersionsTable = ({
</div>
</div>

<ul className={styles.changesBullets}>
{changes?.map((change, i) => {
return (
// todo: find a better key than i
<li key={i}>
<strong>
{getFormattedChangeType(change)}
</strong>
{change.isTranslation ? (
<span
className={styles.translation}
>
Translations sync
</span>
) : (
change.text
)}
{change.link ? (
<>
{' '}
(
<a
className={styles.link}
rel="noreferrer"
target="_blank"
href={change.link}
>
{'link'}
</a>
)
</>
) : null}
</li>
)
})}
</ul>
<div className={styles.changeSummary}>
<ReactMarkdown>{changes}</ReactMarkdown>
</div>
<Divider className={styles.versionDivider} />
</li>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@
color: var(--colors-grey700);
}

.changeSummary :global(a),
a.link {
text-decoration: underline;
}

a.link:hover,
a.link:focus {
.changeSummary :global(a):hover,
a.link:focus,
.changeSummary :global(a):focus {
text-decoration: none;
}

Expand Down Expand Up @@ -46,12 +49,12 @@ a.link:focus {
margin-bottom: var(--spacers-dp16) !important;
}

.changesBullets {
margin-top: var(--spacers-dp12);
padding-left: var(--spacers-dp24);
font-size: 0.9em;
.changeSummary :global(ul) {
font-size: 0.8em;
list-style: disc;
padding-inline-start: var(--spacers-dp24);
}
.changesBullets :global(li) {
list-style-type: disc;
margin-bottom: var(--spacers-dp8);
.changeSummary :global(h3) {
font-size: 0.8em;
margin-bottom: 0.5em;
}
3 changes: 2 additions & 1 deletion client/src/pages/AppView/AppView.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ const AppView = ({ match }) => {
})

const changelogByVersion = changelog?.data?.reduce?.((acc, item) => {
acc[item.version] = item.changeSummary
acc[item.version] = item.rawChangeSummary

return acc
}, {})

Expand Down
4 changes: 2 additions & 2 deletions client/src/pages/AppView/AppView.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ describe('AppView', () => {
getAllByTestId('version-list-item')

expect(firstVersion).toHaveTextContent(
'Fix: enable ou tree and levels/groups with user orgunits and display translated title (link)'
'### Bug Fixes * enable ou tree and levels/groups with user orgunits and display translated title (DHIS2-18066) ([#3241](https://github.com/dhis2/data-visualizer-app/issues/3241)) ([ef314a5](https://github.com/dhis2/data-visualizer-app/commit/ef314a594ce9cb6146755c52291f72135052d397))'
)

expect(secondVersion).toHaveTextContent(
'Fix: handle single value vis-type as highcharts chart instance (link)'
'### Bug Fixes * handle single value vis-type as highcharts chart instance ([#3289](https://github.com/dhis2/data-visualizer-app/issues/3289)) ([83d0e6c](https://github.com/dhis2/data-visualizer-app/commit/83d0e6c33ea5314e849fb1f5842d4b3b61e74c41))'
)

expect(otherVersions).toHaveLength(3)
Expand Down
78 changes: 18 additions & 60 deletions client/src/utils/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,12 @@ class Changelog {
*
* @example [{
version: '100.2.0',
changeSummary: [
{
type: 'Bug Fixes',
text: 'use form container component for styling consistency',
linkText: 'c74a4ca',
link: 'https://github.com/dhis2/login-app/commit/c74a4ca08f102e8f8c27065e079a066315577a7d',
},
{
type: 'Features',
text: 'add email verification pages',
linkText: '916dac3',
link: 'https://github.com/dhis2/login-app/commit/916dac36a03ade4a05383af0be454517a165ed8c',
}
],
]
rawChangeSummary: `
### Bug Fixes
* first bug fix ([c74a4ca](https://github.com/dhis2/login-app/commit/c74a4ca08f102e8f8c27065e079a066315577a7d))
* second bug fix`
}]
*/
data = []

Expand Down Expand Up @@ -55,45 +46,22 @@ class Changelog {

const versions = []

let lastLogType = ''
let lastVersion

lines.forEach((line) => {
// version header
if (line.match(/^\#{1,2}\s/)) {
const versionName = this.#getVersion(line)
versions.push({ version: versionName, changeSummary: [] })
}

// logType: Features, Bug Fixes etc...

if (line.match(/^\#{3}\s/)) {
const logType = this.#getLogType(line)

lastLogType = logType

if (logType === 'BREAKING CHANGES') {
const lastVersion = versions[versions.length - 1]
lastVersion.isBreaking = true
versions[versions.length - 1] = lastVersion
if (line.match(/^#{1,2}\s/)) {
lastVersion = {
version: this.#getVersion(line),
changeSummary: [],
rawChangeSummary: '',
}
}

// single *: commit description
if (line.match(/^\*\s/)) {
const link = this.#getLink(line)
const changeSummary = {
type: lastLogType,
text: line
?.replace(/^\*\s/, '')
.replace(/\(.+\)$/, '')
.trim(),
...link,
}

if (line.includes('**translations:**')) {
changeSummary.isTranslation = true
versions.push(lastVersion)
} else {
if (lastVersion) {
lastVersion.rawChangeSummary =
lastVersion.rawChangeSummary + '\n' + line
}

versions[versions.length - 1].changeSummary.push(changeSummary)
}
})

Expand All @@ -104,16 +72,6 @@ class Changelog {
const matches = /(?<version>\d+\.\d+\.\d+)/.exec(line)
return matches?.groups?.version
}

#getLogType = (line) => {
const matches = /^\#{3} (?<logType>.+)/.exec(line)
return matches?.groups?.logType
}

#getLink = (line) => {
const matches = /\(\[(?<linkText>.+)\]\((?<link>.+)\)\)$/.exec(line)
return matches?.groups
}
}

export const getFormattedChangeType = ({ type, isTranslation }) => {
Expand Down
86 changes: 54 additions & 32 deletions client/test/changelog/changelog.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,66 @@ const changelogContents = fs.readFileSync(
)

describe('changelog', () => {
it('should parse the log', () => {
const result = new Changelog(changelogContents)
it('should parse the change log and save the raw changes in a version', () => {
const result =
new Changelog(`# [100.2.0](https://github.com/dhis2/login-app/compare/v100.1.15...v100.2.0) (2024-12-16)
expect(result.data[0]).toEqual({
version: '100.2.0',
changeSummary: [
{
type: 'Bug Fixes',
text: 'use form container component for styling consistency',
linkText: 'c74a4ca',
link: 'https://github.com/dhis2/login-app/commit/c74a4ca08f102e8f8c27065e079a066315577a7d',
},
{ type: 'Bug Fixes', text: 'second bug fix' },
{
type: 'Features',
text: 'add email verification pages',
linkText: '916dac3',
link: 'https://github.com/dhis2/login-app/commit/916dac36a03ade4a05383af0be454517a165ed8c',
},
{ type: 'Features', text: 'second feature' },
{ type: 'Features', text: 'third feature' },
],
})
})
### Bug Fixes
it('should highlight translation changes', () => {
const result = new Changelog(changelogContents)
const translations = result.data.filter((r) =>
r.changeSummary.find((e) => e.isTranslation)
* first bug fix ([c74a4ca](https://github.com/dhis2/login-app/commit/c74a4ca08f102e8f8c27065e079a066315577a7d))
* second bug fix
### Features
* first feature ([916dac3](https://github.com/dhis2/login-app/commit/916dac36a03ade4a05383af0be454517a165ed8c))
* second feature
* third feature
## [100.1.15](https://github.com/dhis2/login-app/compare/v100.1.14...v100.1.15) (2024-12-08)
### Bug Fixes
* **translations:** sync translations from transifex (main) ([0da02ed](https://github.com/dhis2/login-app/commit/0da02edc0dcd82067180549c0c726b817990a5c7))
## [100.1.14](https://github.com/dhis2/login-app/compare/v100.1.13...v100.1.14) (2024-10-06)
### Bug Fixes
* another bug
`)

expect(result.data[0].rawChangeSummary.replace(/\n/gm, '')).toMatch(
'### Bug Fixes* first bug fix ([c74a4ca](https://github.com/dhis2/login-app/commit/c74a4ca08f102e8f8c27065e079a066315577a7d))* second bug fix### Features* first feature ([916dac3](https://github.com/dhis2/login-app/commit/916dac36a03ade4a05383af0be454517a165ed8c))* second feature* third feature'
)
expect(translations).toHaveLength(9)
expect(result.data[1].rawChangeSummary.replace(/\n/gm, '')).toMatch(
'### Bug Fixes* **translations:** sync translations from transifex (main) ([0da02ed](https://github.com/dhis2/login-app/commit/0da02edc0dcd82067180549c0c726b817990a5c7))'
)
expect(result.data[2].rawChangeSummary.replace(/\n/gm, '')).toMatch(
'### Bug Fixes* another bug'
)
expect(result.data.length).toEqual(3)
})
it('should highlight breaking changes', () => {

it('should parse the version and the log', () => {
const result = new Changelog(changelogContents)
const changes = result.data.filter((r) => r.isBreaking)
expect(changes).toHaveLength(1)
expect(changes[0].version).toEqual('100.0.0')

expect(result.data[0].version).toEqual('100.2.0')
expect(result.data[0].rawChangeSummary).toMatch(`
### Bug Fixes
* use form container component for styling consistency ([c74a4ca](https://github.com/dhis2/login-app/commit/c74a4ca08f102e8f8c27065e079a066315577a7d))
* second bug fix
### Features
* add email verification pages ([916dac3](https://github.com/dhis2/login-app/commit/916dac36a03ade4a05383af0be454517a165ed8c))
* second feature
* third feature
`)
})

it('should not fail with invalid changelog', () => {
const result = new Changelog('invalid changelog')
expect(result.data).toHaveLength(0)
Expand Down

0 comments on commit cd51dcb

Please sign in to comment.