Skip to content

Commit

Permalink
Merge pull request #166 from ftonato/fix-get-repository-url
Browse files Browse the repository at this point in the history
(refactor): remove unnecessary logic
  • Loading branch information
saracope authored Apr 16, 2019
2 parents d83dbcb + 24f4b91 commit b10f853
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 36 deletions.
53 changes: 23 additions & 30 deletions src/components/app/app.container.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
import { forEach } from '@code.gov/cautious'
import AppComponent from './app.component'
import { withRouter } from 'react-router-dom'
import { connect } from 'react-redux'
import loadProject from 'actions/load-project'
import updateBrowseParams from 'actions/update-browse-params'
import updateSearchParams from 'actions/update-search-params'
import updateTaskParams from 'actions/update-task-params'
import {
getNormalizedURLSearchParams,
getSection
} from 'utils/url-parsing'
import { getConfigValue, now } from 'utils/other'
import defaultState from 'constants/default-redux-store-state'
import { connect } from 'react-redux'
import { withRouter } from 'react-router-dom'
import { getConfigValue, now } from 'utils/other'
import { getNormalizedURLSearchParams, getSection } from 'utils/url-parsing'
import AppComponent from './app.component'

export const mapStateToProps = () => {
return {
plugins: getConfigValue('plugins'),
plugins: getConfigValue('plugins')
}
}

Expand All @@ -28,15 +24,13 @@ export const mapDispatchToProps = dispatch => {
if (section === 'browse' || section === 'search') {
const filters = []
forEach(['agencies', 'languages', 'licenses', 'usageTypes'], key => {
console.log("key:", key)
if (parsed[key]) {
const values = parsed[key]
if (values) {
console.log("values:", values)
values.forEach(value => {
filters.push({ category: key, value, modified: now() })
})
}
console.log('key:', key)
const values = parsed[key]
if (values) {
console.log('values:', values)
values.forEach(value => {
filters.push({ category: key, value, modified: now() })
})
}
})
const params = { filters }
Expand All @@ -55,28 +49,27 @@ export const mapDispatchToProps = dispatch => {
} else if (section === 'tasks') {
const filters = []
forEach(['agencies', 'languages', 'skillLevels', 'timeRequired', 'usageTypes'], key => {
if (parsed[key]) {
const values = parsed[key]
if (values) {
values.forEach(value => {
filters.push({ category: key, value, modified: now() })
})
}
const values = parsed[key]
if (values) {
values.forEach(value => {
filters.push({ category: key, value, modified: now() })
})
}
})
const params = { filters }
forEach(['page', 'size'], key => {
params[key] = parsed[key] || defaultState.taskParams[key]
})
dispatch(updateTaskParams(params))
} else {
}
}

}
}
}

const AppContainer = connect(mapStateToProps, mapDispatchToProps)(AppComponent);
const AppContainer = connect(
mapStateToProps,
mapDispatchToProps
)(AppComponent)

export default withRouter(AppContainer);
export default withRouter(AppContainer)
11 changes: 5 additions & 6 deletions src/utils/repo-parsing.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ export function parseLanguages(repo) {
const languages = get(repo, 'languages')
if (Array.isArray(languages)) {
return filter(languages, Boolean)
} else {
return []
}
return []
}

export function parseEmail(repo) {
Expand All @@ -48,19 +47,19 @@ export function parseEmail(repo) {
}

export function parseRepositoryURL(repo) {
let url = get(repo, 'repositoryURL')
const url = get(repo, 'repositoryURL')
if (Boolean(url)) {

if (url.startsWith('git://github.com/')) {
url = url.replace('git://github.com/', 'https://github.com/')
return url.replace('git://github.com/', 'https://github.com/')
}

if (url.startsWith('git@github.com:')) {
url = url.replace('git@github.com:', 'https://github.com/')
return url.replace('git@github.com:', 'https://github.com/')
}

if (url.startsWith('https://github.com') && url.endsWith('.git')) {
url = url.replace('.git', '')
return url.replace('.git', '')
}

return url
Expand Down

0 comments on commit b10f853

Please sign in to comment.