Skip to content

feat(commit): view commits #258

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

Closed
wants to merge 19 commits into from
Closed
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
14 changes: 14 additions & 0 deletions routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ import {
IssueListScreen,
PullListScreen,
PullDiffScreen,
CommitScreen,
CommitListScreen,
ReadMeScreen,
} from 'repository';

Expand Down Expand Up @@ -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 }) => ({
Expand Down
18 changes: 17 additions & 1 deletion src/auth/screens/events.screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,9 @@ class Events extends Component {
);
case 'PushEvent':
return (
<LinkBranchDescription>
<LinkBranchDescription
onPress={() => this.navigateToCommitList(userEvent)}
>
{' '}
{userEvent.payload.ref.replace('refs/heads/', '')}{' '}
</LinkBranchDescription>
Expand Down Expand Up @@ -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:
Expand Down
57 changes: 57 additions & 0 deletions src/components/commit-list-item.component.js
Original file line number Diff line number Diff line change
@@ -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 = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should not go here since we're not using @flow. Thoughts @Antoine38660 @housseindjirdeh ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope quite a few components are using flow types :) I think it's definitely nice to have and hopefully we can increase type coverage throughout the app.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But, we don't have @flow on top...so flow should not be checking anything. Or am I just missing something here?

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) =>
<TouchableHighlight
onPress={() =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please move this arrow function out of this prop? Maybe you can create a function outside of the component and call it here instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice I'm fine either way honestly, but I do see the benefit of having methods separate 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having an arrow function inside a prop may become a perf issue.

navigation.navigate('Commit', {
commit,
})}
underlayColor={colors.greyLight}
>
<View style={styles.container}>
<ListItem
containerStyle={styles.listItemContainer}
title={commit.commit.message.split('\n')[0]}
titleNumberOfLines={1}
subtitle={
`${commit.sha.substring(0, 7)} - ${commit.commit.author.name}` || ''
}
leftIcon={{
name: 'git-commit',
size: 36,
color: colors.grey,
type: 'octicon',
}}
hideChevron
titleStyle={styles.title}
/>
</View>
</TouchableHighlight>;
1 change: 1 addition & 0 deletions src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
57 changes: 56 additions & 1 deletion src/components/issue-description.component.js
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -91,16 +113,34 @@ 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,
locale: string,
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)
Expand All @@ -111,9 +151,11 @@ export class IssueDescription extends Component {
const {
diff,
issue,
commits,
isMergeable,
isMerged,
isPendingDiff,
isPendingCommit,
isPendingCheckMerge,
onRepositoryPress,
userHasPushPermission,
Expand Down Expand Up @@ -174,10 +216,23 @@ export class IssueDescription extends Component {

{issue.pull_request && (
<DiffBlocksContainer>
{isPendingCommit && (
<ActivityIndicator animating={isPendingCommit} size="small" />
)}

{isPendingDiff && (
<ActivityIndicator animating={isPendingDiff} size="small" />
)}

{!isPendingCommit && (
<TouchableHighlight
onPress={() => this.navigateToCommitList()}
underlayColor={colors.greyLight}
>
<Text>{`${commits.length} commits`}</Text>
</TouchableHighlight>
)}

{!isPendingDiff &&
(lineAdditions !== 0 || lineDeletions !== 0) && (
<DiffBlocks
Expand Down
24 changes: 24 additions & 0 deletions src/issue/issue.action.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,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,
Expand Down Expand Up @@ -128,6 +129,29 @@ export const getIssueComments = issueCommentsURL => {
};
};

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;
Expand Down
21 changes: 21 additions & 0 deletions src/issue/issue.reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -21,6 +22,7 @@ const initialState = {
events: [],
pr: {},
diff: '',
commits: [],
isMerged: false,
isPendingComments: false,
isPendingEvents: false,
Expand All @@ -30,6 +32,7 @@ const initialState = {
isEditingIssue: false,
isChangingLockStatus: false,
isPendingDiff: false,
isPendingCommits: false,
isPendingCheckMerge: false,
isPendingMerging: false,
isPendingIssue: false,
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/issue/issue.type.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Loading