Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix older versions of react native changelog URLs #389

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
export const DEFAULT_APP_NAME = 'RnDiffApp'
export const DEFAULT_APP_PACKAGE = 'com.rndiffapp'

export const FIRST_PRE_060_VERSION = '0.60'
export const FIRST_PRE_070_VERSION = '0.70'

export const PACKAGE_NAMES = {
RN: 'react-native',
RNM: 'react-native-macos',
Expand Down
27 changes: 27 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
DEFAULT_APP_PACKAGE,
PACKAGE_NAMES,
RN_CHANGELOG_URLS,
FIRST_PRE_060_VERSION,
FIRST_PRE_070_VERSION,
} from './constants'
import versions from './releases'

Expand Down Expand Up @@ -127,6 +129,27 @@ export const getVersionsContentInDiff = ({
})
}

const getOldVersionsChangelogURL = ({
version,
packageName,
}: {
version: string
packageName: string
}) => {
const urlOldVersion = RN_CHANGELOG_URLS[packageName].replace('/CHANGELOG.md', '')
let formattedVersion = version.replaceAll('.', '')

if (version.split('.').length === 2) formattedVersion += '0'

if (version < FIRST_PRE_060_VERSION) {
return `${urlOldVersion}/CHANGELOG-pre-060.md#v${formattedVersion}`
}

if (version < FIRST_PRE_070_VERSION) {
return `${urlOldVersion}/CHANGELOG-pre-070.md#v${formattedVersion}`
}
}

export const getChangelogURL = ({
version,
packageName,
Expand All @@ -138,6 +161,10 @@ export const getChangelogURL = ({
return `${RN_CHANGELOG_URLS[packageName]}v${version}`
}

if (version < FIRST_PRE_070_VERSION) {
return getOldVersionsChangelogURL({ packageName, version })
}

return `${RN_CHANGELOG_URLS[packageName]}#v${version.replaceAll('.', '')}`
}

Expand Down