Skip to content

Commit 6b31acd

Browse files
authored
Merge pull request #360 from blakef/feat-changelog-link
2 parents 47f0991 + 325b2e2 commit 6b31acd

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

src/__tests__/utils.spec.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { PACKAGE_NAMES } from '../constants'
22
import '../releases/__mocks__/index'
3-
import { getVersionsContentInDiff } from '../utils'
3+
import { getVersionsContentInDiff, getChangelogURL } from '../utils'
44

55
describe('getVersionsContentInDiff', () => {
66
it('returns the versions in the provided range', () => {
@@ -37,3 +37,31 @@ describe('getVersionsContentInDiff', () => {
3737
expect(versions).toEqual([{ version: '0.59' }, { version: '0.58' }])
3838
})
3939
})
40+
41+
describe('getChangelogURL', () => {
42+
const { RN, RNM, RNW } = PACKAGE_NAMES
43+
test.each([
44+
[
45+
RN,
46+
'0.71.7',
47+
'https://github.com/facebook/react-native/blob/main/CHANGELOG.md#v0717',
48+
],
49+
[
50+
RN,
51+
'0.71.6',
52+
'https://github.com/facebook/react-native/blob/main/CHANGELOG.md#v0716',
53+
],
54+
[
55+
RNM,
56+
'0.71.5',
57+
'https://github.com/microsoft/react-native-macos/releases/tag/v0.71.5',
58+
],
59+
[
60+
RNW,
61+
'0.71.4',
62+
'https://github.com/microsoft/react-native-windows/releases/tag/react-native-windows_v0.71.4',
63+
],
64+
])('getChangelogURL("%s", "%s") -> %s', (packageName, version, url) => {
65+
expect(getChangelogURL({ packageName, version })).toEqual(url)
66+
})
67+
})

src/components/common/DiffViewer.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Alert } from 'antd'
44
import { motion, AnimatePresence, AnimateSharedLayout } from 'framer-motion'
55
import { withChangeSelect } from 'react-diff-view'
66
import 'react-diff-view/style/index.css'
7-
import { getTransitionDuration } from '../../utils'
7+
import { getTransitionDuration, getChangelogURL } from '../../utils'
88
import DiffSection from './Diff/DiffSection'
99
import DiffLoading from './Diff/DiffLoading'
1010
import UsefulContentSection from './UsefulContentSection'
@@ -26,6 +26,11 @@ const TopContainer = styled.div`
2626
justify-content: flex-end;
2727
`
2828

29+
const Link = styled.a`
30+
padding: 4px 15px;
31+
color: #1677ff;
32+
`
33+
2934
const getDiffKey = ({ oldRevision, newRevision }) =>
3035
`${oldRevision}${newRevision}`
3136

@@ -127,6 +132,16 @@ const DiffViewer = ({
127132

128133
const [, jumpToAnchorOnce] = useReducer(jumpToAnchor, false)
129134

135+
let changelog
136+
if (!toVersion.includes('-rc')) {
137+
const href = getChangelogURL({ packageName, version: toVersion })
138+
changelog = (
139+
<Link href={href} target="_blank" rel="noreferrer">
140+
changelog
141+
</Link>
142+
)
143+
}
144+
130145
useEffect(() => {
131146
if (!isDone) {
132147
resetCompletedDiffs()
@@ -175,6 +190,8 @@ const DiffViewer = ({
175190
/>
176191

177192
<TopContainer>
193+
{changelog}
194+
178195
<BinaryDownload
179196
diff={diff}
180197
fromVersion={fromVersion}

src/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export const getChangelogURL = ({ version, packageName }) => {
100100
return `${RN_CHANGELOG_URLS[packageName]}v${version}`
101101
}
102102

103-
return `${RN_CHANGELOG_URLS[packageName]}#v${version.replace('.', '')}0`
103+
return `${RN_CHANGELOG_URLS[packageName]}#v${version.replaceAll('.', '')}`
104104
}
105105

106106
// If the browser is headless (running puppeteer) then it doesn't have any duration

0 commit comments

Comments
 (0)