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

feat(commit): view commits #258

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ import {
IssueListScreen,
PullListScreen,
PullDiffScreen,
CommitScreen,
CommitListScreen,
ReadMeScreen,
} from 'repository';

Expand Down Expand Up @@ -158,6 +160,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,
}),
},
PullDiff: {
screen: PullDiffScreen,
navigationOptions: ({ navigation }) => ({
Expand Down
19 changes: 18 additions & 1 deletion src/auth/screens/events.screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,10 @@ class Events extends Component {
);
case 'PushEvent':
return (
<Text style={styles.linkDescription}>
<Text
style={styles.linkDescription}
onPress={() => this.navigateToCommitList(userEvent)}
>
{userEvent.payload.ref.replace('refs/heads/', '')}
</Text>
);
Expand Down Expand Up @@ -464,6 +467,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
44 changes: 41 additions & 3 deletions src/components/issue-description.component.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import React, { Component } from 'react';
import { StyleSheet, View, ActivityIndicator } from 'react-native';
import {
Text,
StyleSheet,
View,
ActivityIndicator,
TouchableHighlight,
} from 'react-native';
import { ListItem, Button } from 'react-native-elements';
Copy link
Member

Choose a reason for hiding this comment

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

I'm sorry, I was fixing merge conflicts here and included this Button as part of the conflict fix. Shouldn't be here since we're leveraging @machour's <Button component. My apologies 😞

Copy link
Member Author

Choose a reason for hiding this comment

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

Np mate, thanks for the conflict fix 😄

import Parse from 'parse-diff';
import moment from 'moment/min/moment-with-locales.min';
Expand Down Expand Up @@ -35,9 +41,10 @@ const styles = StyleSheet.create({
},
diffBlocksContainer: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'flex-end',
alignItems: 'stretch',
justifyContent: 'space-between',
paddingRight: 10,
paddingLeft: 10,
paddingBottom: 10,
},
badge: {
Expand Down Expand Up @@ -67,15 +74,33 @@ export class IssueDescription extends Component {
props: {
issue: Object,
diff: string,
commits: Array,
isMerged: boolean,
isPendingDiff: boolean,
isPendingCommit: boolean,
isPendingCheckMerge: boolean,
onRepositoryPress: Function,
userHasPushPermission: boolean,
language: string,
navigation: Object,
};

navigateToCommitList = () => {
const { commits } = this.props;

if (commits.length > 1) {
this.props.navigation.navigate('CommitList', {
title: translate('repository.commitList.title', this.props.language),
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 @@ -86,8 +111,10 @@ export class IssueDescription extends Component {
const {
diff,
issue,
commits,
isMerged,
isPendingDiff,
isPendingCommit,
isPendingCheckMerge,
onRepositoryPress,
userHasPushPermission,
Expand Down Expand Up @@ -149,9 +176,20 @@ export class IssueDescription extends Component {

{issue.pull_request &&
<View style={styles.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
@@ -1,5 +1,6 @@
import {
fetchDiff,
fetchUrl,
fetchMergeStatus,
fetchCommentHTML,
fetchPostIssueComment,
Expand All @@ -14,6 +15,7 @@ import {
EDIT_ISSUE,
CHANGE_LOCK_STATUS,
GET_ISSUE_DIFF,
GET_ISSUE_COMMITS,
GET_ISSUE_MERGE_STATUS,
MERGE_PULL_REQUEST,
GET_ISSUE_FROM_URL,
Expand Down Expand Up @@ -95,6 +97,28 @@ export const getIssueComments = issueCommentsURL => {
};
};

export const getCommits = url => {
return (dispatch, getState) => {
const accessToken = getState().auth.accessToken;

dispatch({ type: GET_ISSUE_COMMITS.PENDING });

fetchUrl(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 @@ -4,6 +4,7 @@ import {
EDIT_ISSUE,
CHANGE_LOCK_STATUS,
GET_ISSUE_DIFF,
GET_ISSUE_COMMITS,
GET_ISSUE_MERGE_STATUS,
MERGE_PULL_REQUEST,
GET_ISSUE_FROM_URL,
Expand All @@ -14,12 +15,14 @@ const initialState = {
issue: {},
comments: [],
diff: '',
commits: [],
isMerged: false,
isPendingComments: false,
isPostingComment: false,
isEditingIssue: false,
isChangingLockStatus: false,
isPendingDiff: false,
isPendingCommits: false,
isPendingCheckMerge: false,
isPendingMerging: false,
isPendingIssue: false,
Expand Down Expand Up @@ -116,6 +119,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 @@ -5,6 +5,7 @@ export const POST_ISSUE_COMMENT = createActionSet('POST_ISSUE_COMMENT');
export const EDIT_ISSUE = createActionSet('EDIT_ISSUE');
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 MERGE_PULL_REQUEST = createActionSet('MERGE_PULL_REQUEST');
export const GET_ISSUE_FROM_URL = createActionSet('GET_ISSUE_FROM_URL');
Expand Down