Skip to content

Commit

Permalink
Move function to filter versions based on the diff requirements to `u…
Browse files Browse the repository at this point in the history
…tils`
  • Loading branch information
Lucas Bento committed Jun 11, 2019
1 parent 7cbf274 commit bcee9e0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
16 changes: 3 additions & 13 deletions src/components/common/Diff/DiffComment.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import React from 'react'
import styled from 'styled-components'
import semver from 'semver'
import { versions } from '../../../releases'
import { removeAppPathPrefix } from '../../../utils'
import { removeAppPathPrefix, getVersionsInDiff } from '../../../utils'
import Markdown from '../Markdown'

const Container = styled.div`
Expand All @@ -19,22 +17,14 @@ const LINE_CHANGE_TYPES = {
NEUTRAL: 'N'
}

const releasedVersions = versions.map(version => ({
...require(`../../../releases/${version}`).default,
version
}))

const getLineNumberWithType = ({ lineChangeType, lineNumber }) =>
`${LINE_CHANGE_TYPES[lineChangeType.toUpperCase()]}${lineNumber}`

const getComments = ({ newPath, fromVersion, toVersion }) => {
const newPathSanitized = removeAppPathPrefix(newPath)
const cleanedToVersion = semver.valid(semver.coerce(toVersion))

const versionsInDiff = releasedVersions.filter(
({ version, comments }) =>
semver.lte(version, cleanedToVersion) &&
semver.gt(version, fromVersion) &&
const versionsInDiff = getVersionsInDiff({ fromVersion, toVersion }).filter(
({ comments }) =>
comments.some(({ fileName }) => fileName === newPathSanitized)
)

Expand Down
17 changes: 17 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
import semver from 'semver'
import { versions } from './releases'

const releasedVersions = versions.map(version => ({
...require(`./releases/${version}`).default,
version
}))

export const RELEASES_URL =
'https://raw.githubusercontent.com/react-native-community/rn-diff-purge/master/RELEASES'

export const removeAppPathPrefix = path => path.replace(/RnDiffApp\//, '')

export const getVersionsInDiff = ({ fromVersion, toVersion }) => {
const cleanedToVersion = semver.valid(semver.coerce(toVersion))

return releasedVersions.filter(
({ version }) =>
semver.lte(version, cleanedToVersion) && semver.gt(version, fromVersion)
)
}

0 comments on commit bcee9e0

Please sign in to comment.