diff --git a/routes.js b/routes.js index 1d1fde161..7a0a9ee84 100644 --- a/routes.js +++ b/routes.js @@ -49,6 +49,8 @@ import { IssueListScreen, PullListScreen, PullDiffScreen, + CommitScreen, + CommitListScreen, ReadMeScreen, } from 'repository'; @@ -164,6 +166,18 @@ const sharedRoutes = { title: navigation.state.params.title, }), }, + CommitList: { + screen: CommitListScreen, + navigationOptions: ({ navigation }) => ({ + title: navigation.state.params.title, + }), + }, + Commit: { + screen: CommitScreen, + navigationOptions: ({ navigation }) => ({ + title: navigation.state.params.title, + }), + }, EditIssueComment: { screen: EditIssueCommentScreen, navigationOptions: ({ navigation }) => ({ diff --git a/src/auth/screens/events.screen.js b/src/auth/screens/events.screen.js index 655ea589e..7cb1d9936 100644 --- a/src/auth/screens/events.screen.js +++ b/src/auth/screens/events.screen.js @@ -284,7 +284,9 @@ class Events extends Component { ); case 'PushEvent': return ( - + this.navigateToCommitList(userEvent)} + > {' '} {userEvent.payload.ref.replace('refs/heads/', '')}{' '} @@ -456,6 +458,20 @@ class Events extends Component { }); }; + navigateToCommitList = userEvent => { + if (userEvent.payload.commits > 1) { + this.props.navigation.navigate('CommitList', { + commits: userEvent.payload.commits, + title: translate('repository.commitList.title', this.props.language), + }); + } else { + this.props.navigation.navigate('Commit', { + commit: userEvent.payload.commits[0], + title: userEvent.payload.commits[0].sha.substring(0, 7), + }); + } + }; + navigateToIssue = userEvent => { this.props.navigation.navigate('Issue', { issue: diff --git a/src/components/commit-list-item.component.js b/src/components/commit-list-item.component.js new file mode 100644 index 000000000..545e53597 --- /dev/null +++ b/src/components/commit-list-item.component.js @@ -0,0 +1,57 @@ +import React from 'react'; +import { StyleSheet, TouchableHighlight, View } from 'react-native'; +import { ListItem } from 'react-native-elements'; +import { colors, fonts } from 'config'; + +type Props = { + commit: Object, + navigation: Object, +}; + +const styles = StyleSheet.create({ + container: { + flexDirection: 'row', + alignItems: 'center', + justifyContent: 'center', + paddingRight: 10, + paddingVertical: 5, + borderBottomWidth: 1, + borderBottomColor: colors.greyLight, + }, + listItemContainer: { + flex: 1, + borderBottomWidth: 0, + }, + title: { + color: colors.primaryDark, + ...fonts.fontPrimary, + }, +}); + +export const CommitListItem = ({ commit, navigation }: Props) => + + navigation.navigate('Commit', { + commit, + })} + underlayColor={colors.greyLight} + > + + + + ; diff --git a/src/components/index.js b/src/components/index.js index 3446b7af1..dddca7615 100644 --- a/src/components/index.js +++ b/src/components/index.js @@ -3,6 +3,7 @@ export * from './loading-indicators'; export * from './code-line.component'; export * from './comment-input.component'; export * from './comment-list-item.component'; +export * from './commit-list-item.component'; export * from './diff-blocks.component'; export * from './entity-info.component'; export * from './issue-description.component'; diff --git a/src/components/issue-description.component.js b/src/components/issue-description.component.js index f5a24c91b..a7437e355 100644 --- a/src/components/issue-description.component.js +++ b/src/components/issue-description.component.js @@ -1,6 +1,12 @@ import React, { Component } from 'react'; -import { StyleSheet, ActivityIndicator } from 'react-native'; +import { + Text, + StyleSheet, + ActivityIndicator, + TouchableHighlight, +} from 'react-native'; import { ListItem } from 'react-native-elements'; + import Parse from 'parse-diff'; import styled from 'styled-components/native'; @@ -40,6 +46,22 @@ const RepoLink = styled(ListItem).attrs({ ...fonts.fontPrimarySemiBold, fontSize: normalize(10), }, + listItemContainer: { + borderBottomWidth: 0, + flex: 1, + }, + diffBlocksContainer: { + flexDirection: 'row', + alignItems: 'stretch', + justifyContent: 'space-between', + paddingRight: 10, + paddingLeft: 10, + paddingBottom: 10, + }, + badge: { + alignItems: 'flex-end', + justifyContent: 'center', + }, leftIconContainerStyle: { flex: 0, }, @@ -91,9 +113,11 @@ export class IssueDescription extends Component { props: { issue: Object, diff: string, + commits: Array, isMergeable: boolean, isMerged: boolean, isPendingDiff: boolean, + isPendingCommit: boolean, isPendingCheckMerge: boolean, onRepositoryPress: Function, userHasPushPermission: boolean, @@ -101,6 +125,22 @@ export class IssueDescription extends Component { navigation: Object, }; + navigateToCommitList = () => { + const { commits, locale } = this.props; + + if (commits.length > 1) { + this.props.navigation.navigate('CommitList', { + title: translate('repository.commitList.title', locale), + commits, + }); + } else { + this.props.navigation.navigate('Commit', { + commit: commits[0], + title: commits[0].sha.substring(0, 7), + }); + } + }; + renderLabelButtons = labels => { return labels .slice(0, 3) @@ -111,9 +151,11 @@ export class IssueDescription extends Component { const { diff, issue, + commits, isMergeable, isMerged, isPendingDiff, + isPendingCommit, isPendingCheckMerge, onRepositoryPress, userHasPushPermission, @@ -174,10 +216,23 @@ export class IssueDescription extends Component { {issue.pull_request && ( + {isPendingCommit && ( + + )} + {isPendingDiff && ( )} + {!isPendingCommit && ( + this.navigateToCommitList()} + underlayColor={colors.greyLight} + > + {`${commits.length} commits`} + + )} + {!isPendingDiff && (lineAdditions !== 0 || lineDeletions !== 0) && ( { }; }; +export const getCommits = url => { + return (dispatch, getState) => { + const accessToken = getState().auth.accessToken; + + dispatch({ type: GET_ISSUE_COMMITS.PENDING }); + + return v3 + .getJson(url, accessToken) + .then(data => { + dispatch({ + type: GET_ISSUE_COMMITS.SUCCESS, + payload: data, + }); + }) + .catch(error => { + dispatch({ + type: GET_ISSUE_COMMITS.ERROR, + payload: error, + }); + }); + }; +}; + export const postIssueComment = (body, owner, repoName, issueNum) => { return (dispatch, getState) => { const accessToken = getState().auth.accessToken; diff --git a/src/issue/issue.reducer.js b/src/issue/issue.reducer.js index 4c9f7c118..63d100b6e 100644 --- a/src/issue/issue.reducer.js +++ b/src/issue/issue.reducer.js @@ -7,6 +7,7 @@ import { EDIT_ISSUE_BODY, CHANGE_LOCK_STATUS, GET_ISSUE_DIFF, + GET_ISSUE_COMMITS, GET_ISSUE_MERGE_STATUS, GET_PULL_REQUEST_FROM_URL, MERGE_PULL_REQUEST, @@ -21,6 +22,7 @@ const initialState = { events: [], pr: {}, diff: '', + commits: [], isMerged: false, isPendingComments: false, isPendingEvents: false, @@ -30,6 +32,7 @@ const initialState = { isEditingIssue: false, isChangingLockStatus: false, isPendingDiff: false, + isPendingCommits: false, isPendingCheckMerge: false, isPendingMerging: false, isPendingIssue: false, @@ -210,6 +213,24 @@ export const issueReducer = (state = initialState, action = {}) => { error: action.payload, isPendingDiff: false, }; + case GET_ISSUE_COMMITS.PENDING: + return { + ...state, + commits: [], + isPendingCommits: true, + }; + case GET_ISSUE_COMMITS.SUCCESS: + return { + ...state, + commits: action.payload, + isPendingCommits: false, + }; + case GET_ISSUE_COMMITS.ERROR: + return { + ...state, + error: action.payload, + isPendingCommits: false, + }; case GET_ISSUE_MERGE_STATUS.PENDING: return { ...state, diff --git a/src/issue/issue.type.js b/src/issue/issue.type.js index ad22aab85..8b786c68d 100644 --- a/src/issue/issue.type.js +++ b/src/issue/issue.type.js @@ -8,6 +8,7 @@ export const EDIT_ISSUE = createActionSet('EDIT_ISSUE'); export const EDIT_ISSUE_BODY = createActionSet('EDIT_ISSUE_BODY'); export const CHANGE_LOCK_STATUS = createActionSet('CHANGE_LOCK_STATUS'); export const GET_ISSUE_DIFF = createActionSet('GET_ISSUE_DIFF'); +export const GET_ISSUE_COMMITS = createActionSet('GET_ISSUE_COMMITS'); export const GET_ISSUE_MERGE_STATUS = createActionSet('GET_ISSUE_MERGE_STATUS'); export const GET_PULL_REQUEST_FROM_URL = createActionSet( 'GET_PULL_REQUEST_FROM_URL' diff --git a/src/issue/screens/issue.screen.js b/src/issue/screens/issue.screen.js index 3d953bf83..371ecafc7 100644 --- a/src/issue/screens/issue.screen.js +++ b/src/issue/screens/issue.screen.js @@ -28,6 +28,7 @@ import { getIssueComments, postIssueComment, getIssueFromUrl, + getCommits, deleteIssueComment, getIssueEvents, } from '../issue.action'; @@ -39,11 +40,13 @@ const mapStateToProps = state => ({ contributors: state.repository.contributors, issue: state.issue.issue, diff: state.issue.diff, + commits: state.issue.commits, pr: state.issue.pr, isMerged: state.issue.isMerged, comments: state.issue.comments, events: state.issue.events, isPendingDiff: state.issue.isPendingDiff, + isPendingCommits: state.issue.isPendingCommits, isPendingCheckMerge: state.issue.isPendingCheckMerge, isPendingComments: state.issue.isPendingComments, isPendingEvents: state.issue.isPendingEvents, @@ -60,6 +63,7 @@ const mapDispatchToProps = dispatch => getContributors, postIssueComment, getIssueFromUrl, + getCommits, deleteIssueComment, getIssueEvents, }, @@ -119,9 +123,11 @@ class Issue extends Component { getContributors: Function, postIssueComment: Function, getIssueFromUrl: Function, + getCommits: Function, getIssueEvents: Function, deleteIssueComment: Function, diff: string, + commits: Array, issue: Object, pr: Object, isMerged: boolean, @@ -132,6 +138,7 @@ class Issue extends Component { events: Array, isPendingIssue: boolean, isPendingDiff: boolean, + isPendingCommits: boolean, isPendingCheckMerge: boolean, isPendingComments: boolean, isPendingEvents: boolean, @@ -190,6 +197,8 @@ class Issue extends Component { getRepository, getContributors, getIssueFromUrl, + getCommits, + issue, getIssueEvents, } = this.props; @@ -198,10 +207,17 @@ class Issue extends Component { const issueRepository = issueURL .replace(`${v3.root}/repos/`, '') .replace(/([^/]+\/[^/]+)\/issues\/\d+$/, '$1'); + const pullRequestCommitsURL = `${issueURL.replace( + 'issues', + 'pulls' + )}/commits`; Promise.all([ getIssueFromUrl(issueURL), getIssueComments(`${issueURL}/comments`), + (issue || params.issue).pull_request + ? getCommits(pullRequestCommitsURL) + : Promise.resolve(), ]) .then(() => { const issue = this.props.issue; @@ -288,8 +304,10 @@ class Issue extends Component { issue, pr, diff, + commits, isMerged, isPendingDiff, + isPendingCommits, isPendingCheckMerge, locale, navigation, @@ -299,9 +317,11 @@ class Issue extends Component { this.onRepositoryPress(url)} onLinkPress={node => this.onLinkPress(node)} diff --git a/src/locale/languages/en.js b/src/locale/languages/en.js index dfca89f11..97c3b0ac1 100644 --- a/src/locale/languages/en.js +++ b/src/locale/languages/en.js @@ -191,6 +191,7 @@ export const en = { noContributorsMessage: 'No contributors found', sourceTitle: 'SOURCE', readMe: 'README', + viewCommit: 'View Commits', viewSource: 'View Code', issuesTitle: 'ISSUES', noIssuesMessage: 'No issues', @@ -210,6 +211,17 @@ export const en = { codeList: { title: 'Code', }, + commitList: { + title: 'Commits', + noCommit: 'No commit found!', + }, + commit: { + numFilesChanged: '{{numFilesChanged}} files', + new: 'NEW', + deleted: 'DELETED', + fileRenamed: 'File renamed without any changes', + byConnector: 'By {{contributor}}', + }, issueList: { title: 'Issues', openButton: 'Open', diff --git a/src/repository/repository.action.js b/src/repository/repository.action.js index b6534e025..28265105d 100644 --- a/src/repository/repository.action.js +++ b/src/repository/repository.action.js @@ -1,4 +1,5 @@ import { + fetchDiff, fetchReadMe, fetchSearch, fetchChangeStarStatusRepo, @@ -15,7 +16,10 @@ import { GET_REPOSITORY_FILE, GET_REPOSITORY_ISSUES, GET_REPO_README_STATUS, + GET_REPOSITORY_COMMITS, GET_REPO_STARRED_STATUS, + GET_COMMIT, + GET_COMMIT_DIFF, FORK_REPO_STATUS, CHANGE_STAR_STATUS, GET_REPOSITORY_README, @@ -166,6 +170,83 @@ export const checkReadMe = url => { }; }; +export const getCommits = url => { + return (dispatch, getState) => { + const accessToken = getState().auth.accessToken; + + dispatch({ type: GET_REPOSITORY_COMMITS.PENDING }); + + v3 + .getJson(url, accessToken) + .then(data => { + dispatch({ + type: GET_REPOSITORY_COMMITS.SUCCESS, + payload: data, + }); + }) + .catch(error => { + dispatch({ + type: GET_REPOSITORY_COMMITS.ERROR, + payload: error, + }); + }); + }; +}; + +export const getCommitFromUrl = url => { + return (dispatch, getState) => { + const accessToken = getState().auth.accessToken; + + dispatch({ type: GET_COMMIT.PENDING }); + + v3 + .getJson(url, accessToken) + .then(data => { + dispatch({ + type: GET_COMMIT.SUCCESS, + payload: data, + }); + }) + .catch(error => { + dispatch({ + type: GET_COMMIT.ERROR, + payload: error, + }); + }); + }; +}; + +export const getCommitDiffFromUrl = url => { + return (dispatch, getState) => { + const accessToken = getState().auth.accessToken; + + dispatch({ type: GET_COMMIT_DIFF.PENDING }); + + fetchDiff(url, accessToken) + .then(data => { + dispatch({ + type: GET_COMMIT_DIFF.SUCCESS, + payload: data, + }); + }) + .catch(error => { + dispatch({ + type: GET_COMMIT_DIFF.ERROR, + payload: error, + }); + }); + }; +}; + +export const getCommitDetails = commit => { + return dispatch => { + const url = commit.url || commit.commit.url; + + dispatch(getCommitFromUrl(url)); + dispatch(getCommitDiffFromUrl(url)); + }; +}; + export const checkRepoStarred = url => { return (dispatch, getState) => { const accessToken = getState().auth.accessToken; @@ -242,9 +323,14 @@ export const getRepositoryInfo = url => { '{/number}', '?state=all&per_page=100' ); + const commitsUrl = getState().repository.repository.commits_url.replace( + '{/sha}', + '?state=all&per_page=100' + ); dispatch(getContributors(contributorsUrl)); dispatch(getIssues(issuesUrl)); + dispatch(getCommits(commitsUrl)); dispatch( checkReadMe( `${v3.root}/repos/${repo.owner.login}/${repo.name}/readme?ref=master` diff --git a/src/repository/repository.reducer.js b/src/repository/repository.reducer.js index 4a4478b4d..94c53ebf5 100644 --- a/src/repository/repository.reducer.js +++ b/src/repository/repository.reducer.js @@ -5,11 +5,14 @@ import { GET_REPOSITORY_FILE, GET_REPOSITORY_ISSUES, GET_REPO_README_STATUS, + GET_REPOSITORY_COMMITS, GET_REPO_STARRED_STATUS, FORK_REPO_STATUS, CHANGE_STAR_STATUS, GET_REPOSITORY_README, GET_REPOSITORY_LABELS, + GET_COMMIT, + GET_COMMIT_DIFF, SEARCH_OPEN_ISSUES, SEARCH_CLOSED_ISSUES, SEARCH_OPEN_PULLS, @@ -24,6 +27,9 @@ const initialState = { contents: {}, fileContent: '', issues: [], + commits: [], + commit: {}, + diff: '', readMe: '', hasReadMe: false, starred: false, @@ -36,6 +42,9 @@ const initialState = { isPendingRepository: false, isPendingContributors: false, isPendingContents: false, + isPendingCommits: false, + isPendingCommit: false, + isPendingDiff: false, isPendingFile: false, isPendingIssues: false, isPendingCheckReadMe: false, @@ -162,6 +171,24 @@ export const repositoryReducer = (state = initialState, action = {}) => { error: action.payload, isPendingCheckReadMe: false, }; + case GET_REPOSITORY_COMMITS.PENDING: + return { + ...state, + commits: [], + isPendingCommits: true, + }; + case GET_REPOSITORY_COMMITS.SUCCESS: + return { + ...state, + commits: action.payload, + isPendingCommits: false, + }; + case GET_REPOSITORY_COMMITS.ERROR: + return { + ...state, + error: action.payload, + isPendingCommits: false, + }; case GET_REPO_STARRED_STATUS.PENDING: return { ...state, @@ -343,6 +370,41 @@ export const repositoryReducer = (state = initialState, action = {}) => { error: action.payload, isPendingSearchClosedPulls: false, }; + case GET_COMMIT.PENDING: + return { + ...state, + commit: {}, + isPendingCommit: true, + }; + case GET_COMMIT.SUCCESS: + return { + ...state, + commit: action.payload, + isPendingCommit: false, + }; + case GET_COMMIT.ERROR: + return { + ...state, + error: action.payload, + isPendingCommit: false, + }; + case GET_COMMIT_DIFF.PENDING: + return { + ...state, + isPendingDiff: true, + }; + case GET_COMMIT_DIFF.SUCCESS: + return { + ...state, + diff: action.payload, + isPendingDiff: false, + }; + case GET_COMMIT_DIFF.ERROR: + return { + ...state, + error: action.payload, + isPendingDiff: false, + }; default: return state; } diff --git a/src/repository/repository.type.js b/src/repository/repository.type.js index 85412ba04..bd1014f75 100644 --- a/src/repository/repository.type.js +++ b/src/repository/repository.type.js @@ -7,9 +7,12 @@ export const GET_REPOSITORY_CONTRIBUTORS = createActionSet( export const GET_REPOSITORY_CONTENTS = createActionSet( 'GET_REPOSITORY_CONTENTS' ); +export const GET_COMMIT = createActionSet('GET_COMMIT'); +export const GET_COMMIT_DIFF = createActionSet('GET_COMMIT_DIFF'); export const GET_REPOSITORY_FILE = createActionSet('GET_REPOSITORY_FILE'); export const GET_REPOSITORY_ISSUES = createActionSet('GET_REPOSITORY_ISSUES'); export const GET_REPO_README_STATUS = createActionSet('GET_REPO_README_STATUS'); +export const GET_REPOSITORY_COMMITS = createActionSet('GET_REPOSITORY_COMMITS'); export const GET_REPO_STARRED_STATUS = createActionSet( 'GET_REPO_STARRED_STATUS' ); diff --git a/src/repository/screens/commit-list.screen.js b/src/repository/screens/commit-list.screen.js new file mode 100644 index 000000000..e503ffc5b --- /dev/null +++ b/src/repository/screens/commit-list.screen.js @@ -0,0 +1,55 @@ +import React, { Component } from 'react'; +import { FlatList, View, StyleSheet, Text } from 'react-native'; +import { ViewContainer, CommitListItem } from 'components'; +import { translate } from 'utils'; +import { normalize } from 'config'; + +const styles = StyleSheet.create({ + marginSpacing: { + marginTop: 40, + }, + noCommit: { + fontSize: normalize(18), + textAlign: 'center', + }, +}); + +class CommitList extends Component { + props: { + language: string, + navigation: Object, + }; + + keyExtractor = item => { + return item.id; + }; + + renderItem = ({ item }) => + ; + + render() { + const { language, navigation } = this.props; + const commits = navigation.state.params.commits; + + return ( + + {commits.length > 0 && + } + + {commits.length === 0 && + + + {translate('repository.commitList.noCommit', language)} + + } + + ); + } +} + +export const CommitListScreen = CommitList; diff --git a/src/repository/screens/commit.screen.js b/src/repository/screens/commit.screen.js new file mode 100644 index 000000000..d5121beab --- /dev/null +++ b/src/repository/screens/commit.screen.js @@ -0,0 +1,280 @@ +/* eslint-disable react/no-array-index-key */ +import React, { Component } from 'react'; +import { connect } from 'react-redux'; +import { View, ScrollView, Text, FlatList, StyleSheet } from 'react-native'; +import { Card } from 'react-native-elements'; +import { + ViewContainer, + DiffBlocks, + CodeLine, + LoadingContainer, +} from 'components'; +import Parse from 'parse-diff'; +import { translate } from 'utils'; +import { colors, fonts, normalize } from 'config'; +import { getCommitDetails } from '../repository.action'; + +const mapStateToProps = state => ({ + language: state.auth.language, + commit: state.repository.commit, + diff: state.repository.diff, + isPendingCommit: state.repository.isPendingCommit, + isPendingDiff: state.repository.isPendingDiff, +}); + +const mapDispatchToProps = dispatch => ({ + getCommitDetailsByDispatch: commit => dispatch(getCommitDetails(commit)), +}); + +const styles = StyleSheet.create({ + fileChangeContainer: { + padding: 0, + marginTop: 12, + marginBottom: 12, + }, + fileTitleContainer: { + flexDirection: 'row', + paddingVertical: 15, + backgroundColor: colors.greyVeryLight, + }, + linesChanged: { + flex: 0.3, + paddingLeft: 10, + flexDirection: 'row', + alignItems: 'center', + }, + lineNumbersChanged: { + ...fonts.fontCode, + marginRight: 5, + }, + fileTitle: { + flex: 1, + marginLeft: 10, + }, + codeStyle: { + ...fonts.fontCode, + fontSize: normalize(10), + }, + dividerStyle: { + marginBottom: 0, + }, + noChangesMessage: { + ...fonts.fontPrimarySemiBold, + paddingVertical: 5, + paddingLeft: 10, + }, + newIndicator: { + ...fonts.fontPrimarySemiBold, + color: colors.green, + }, + deletedIndicator: { + ...fonts.fontPrimarySemiBold, + color: colors.red, + }, + headerContainer: { + paddingTop: 15, + paddingHorizontal: 25, + }, + header: { + flex: 1, + paddingTop: 10, + flexDirection: 'row', + alignItems: 'center', + justifyContent: 'space-between', + }, + headerItem: { + flex: 1, + }, + headerText: { + ...fonts.fontPrimarySemiBold, + fontSize: normalize(14), + }, +}); + +class Commit extends Component { + props: { + navigation: Object, + commit: Object, + diff: string, + isPendingCommit: boolean, + isPendingDiff: boolean, + getCommitDetailsByDispatch: Function, + language: string, + }; + + componentDidMount() { + const { navigation, getCommitDetailsByDispatch } = this.props; + const commit = navigation.state.params.commit; + + getCommitDetailsByDispatch(commit); + } + + keyExtractor = (item, index) => { + return index; + }; + + renderHeader = () => { + const { commit, language, isPendingCommit } = this.props; + const message = commit.commit ? commit.commit.message : 'Loading...'; + const committer = commit.author ? commit.author.login : ''; + + if (isPendingCommit || !commit.files) { + return ( + + {message} + + ); + } + + return ( + + + + {message} + + + + + {translate('repository.commit.byConnector', language, { + contributor: committer, + })} + + + + + {translate('repository.commit.numFilesChanged', language, { + numFilesChanged: isPendingCommit ? 0 : commit.files.length, + })} + + + + + + ); + }; + + renderItem = ({ item }) => { + const { language } = this.props; + const filename = item.deleted ? item.from : item.to; + const chunks = item.chunks.map((chunk, index) => { + return ( + + + + + {chunk.changes.map((change, changesIndex) => + + )} + + + ); + }); + + return ( + + + + + {item.additions + item.deletions} + + + + + {item.new && + + + {translate('repository.commit.new', language)} + {'\n'} + + + {item.to} + + } + + {item.deleted && + + + {translate('repository.commit.deleted', language)} + {'\n'} + + + {item.from} + + } + + {!item.new && + !item.deleted && + + {item.from === item.to ? item.to : `${item.from} \n → ${item.to}`} + } + + + {item.chunks.length > 0 && chunks} + + {item.chunks.length === 0 && + !item.new && + !item.deleted && + item.from !== item.to && + + {translate('repository.commit.fileRenamed', language)} + } + + ); + }; + + render() { + const { diff, isPendingCommit, isPendingDiff } = this.props; + const filesChanged = isPendingDiff || diff === {} ? [] : Parse(diff); + + return ( + + {(isPendingCommit || isPendingDiff) && + } + + {!isPendingCommit && + !isPendingDiff && + } + + ); + } +} + +export const CommitScreen = connect(mapStateToProps, mapDispatchToProps)( + Commit +); diff --git a/src/repository/screens/index.js b/src/repository/screens/index.js index 3f2da0103..55dd2c931 100644 --- a/src/repository/screens/index.js +++ b/src/repository/screens/index.js @@ -1,3 +1,5 @@ +export * from './commit.screen'; +export * from './commit-list.screen'; export * from './issue-list.screen'; export * from './pull-diff.screen'; export * from './pull-list.screen'; diff --git a/src/repository/screens/repository.screen.js b/src/repository/screens/repository.screen.js index 21c4e7008..d02377167 100644 --- a/src/repository/screens/repository.screen.js +++ b/src/repository/screens/repository.screen.js @@ -23,6 +23,9 @@ import { translate, openURLInView } from 'utils'; import { colors, fonts } from 'config'; import { getRepositoryInfo, + getContributors, + getIssues, + getCommits, changeStarStatusRepo, forkRepo, subscribeToRepo, @@ -35,6 +38,7 @@ const mapStateToProps = state => ({ repository: state.repository.repository, contributors: state.repository.contributors, issues: state.repository.issues, + commits: state.repository.commits, starred: state.repository.starred, forked: state.repository.forked, subscribed: state.repository.subscribed, @@ -52,6 +56,9 @@ const mapDispatchToProps = dispatch => bindActionCreators( { getRepositoryInfo, + getContributors, + getIssues, + getCommits, changeStarStatusRepo, forkRepo, subscribeToRepo, @@ -74,6 +81,8 @@ const styles = StyleSheet.create({ class Repository extends Component { props: { getRepositoryInfo: Function, + // getIssues: Function, + // getCommits: Function, changeStarStatusRepo: Function, forkRepo: Function, // repositoryName: string, @@ -81,6 +90,7 @@ class Repository extends Component { contributors: Array, hasReadMe: boolean, issues: Array, + commits: Array, starred: boolean, // forked: boolean, isPendingRepository: boolean, @@ -195,6 +205,7 @@ class Repository extends Component { contributors, hasReadMe, issues, + commits, starred, locale, isPendingRepository, @@ -350,6 +361,26 @@ class Repository extends Component { underlayColor={colors.greyLight} /> )} + + {commits.length > 0 && ( + + this.props.navigation.navigate('CommitList', { + commits, + title: translate('repository.commitList.title', locale), + })} + underlayColor={colors.greyLight} + /> + )} +