Skip to content

Commit d1bb088

Browse files
authored
feat(commit): view commits (#851)
* feat(commits): migrate #258 changes * feat(commits): fix i18n * fix(issue): fix issue description styles * feat(commit): Show author and committer, both clickable * chore(i18n): update translation files
1 parent 85ea4e2 commit d1bb088

37 files changed

+852
-21
lines changed

routes.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ import {
5050
IssueListScreen,
5151
PullListScreen,
5252
PullDiffScreen,
53+
CommitScreen,
54+
CommitListScreen,
5355
ReadMeScreen,
5456
} from 'repository';
5557

@@ -164,6 +166,18 @@ const sharedRoutes = {
164166
title: navigation.state.params.title,
165167
}),
166168
},
169+
CommitList: {
170+
screen: CommitListScreen,
171+
navigationOptions: ({ navigation }) => ({
172+
title: navigation.state.params.title,
173+
}),
174+
},
175+
Commit: {
176+
screen: CommitScreen,
177+
navigationOptions: ({ navigation }) => ({
178+
title: navigation.state.params.title,
179+
}),
180+
},
167181
EditIssueComment: {
168182
screen: EditIssueCommentScreen,
169183
navigationOptions: ({ navigation }) => ({

src/auth/screens/events.screen.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ class Events extends Component {
488488
const actor = this.getActorLink(userEvent);
489489
const repo = this.getRepoLink(userEvent);
490490
const ref = (
491-
<LinkBranchDescription>
491+
<LinkBranchDescription onPress={() => this.navigateToCommitList(userEvent)}>
492492
{userEvent.payload.ref.replace('refs/heads/', '')}
493493
</LinkBranchDescription>
494494
);
@@ -543,6 +543,21 @@ class Events extends Component {
543543
});
544544
};
545545

546+
navigateToCommitList = userEvent => {
547+
if (userEvent.payload.commits > 1) {
548+
this.props.navigation.navigate('CommitList', {
549+
commits: userEvent.payload.commits,
550+
title: t('Commits', this.props.locale),
551+
locale: this.props.locale,
552+
});
553+
} else {
554+
this.props.navigation.navigate('Commit', {
555+
commit: userEvent.payload.commits[0],
556+
title: userEvent.payload.commits[0].sha.substring(0, 7),
557+
});
558+
}
559+
};
560+
546561
navigateToIssue = userEvent => {
547562
this.props.navigation.navigate('Issue', {
548563
issue:
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import React from 'react';
2+
import { StyleSheet, TouchableHighlight, View } from 'react-native';
3+
import { ListItem } from 'react-native-elements';
4+
import { colors, fonts } from 'config';
5+
6+
type Props = {
7+
commit: Object,
8+
navigation: Object,
9+
};
10+
11+
const styles = StyleSheet.create({
12+
container: {
13+
flexDirection: 'row',
14+
alignItems: 'center',
15+
justifyContent: 'center',
16+
paddingRight: 10,
17+
paddingVertical: 5,
18+
borderBottomWidth: 1,
19+
borderBottomColor: colors.greyLight,
20+
},
21+
listItemContainer: {
22+
flex: 1,
23+
borderBottomWidth: 0,
24+
},
25+
title: {
26+
color: colors.primaryDark,
27+
...fonts.fontPrimary,
28+
},
29+
});
30+
31+
export const CommitListItem = ({ commit, navigation }: Props) =>
32+
<TouchableHighlight
33+
onPress={() =>
34+
navigation.navigate('Commit', {
35+
commit,
36+
})}
37+
underlayColor={colors.greyLight}
38+
>
39+
<View style={styles.container}>
40+
<ListItem
41+
containerStyle={styles.listItemContainer}
42+
title={commit.commit.message.split('\n')[0]}
43+
titleNumberOfLines={1}
44+
subtitle={
45+
`${commit.sha.substring(0, 7)} - ${commit.commit.author.name}` || ''
46+
}
47+
leftIcon={{
48+
name: 'git-commit',
49+
size: 36,
50+
color: colors.grey,
51+
type: 'octicon',
52+
}}
53+
hideChevron
54+
titleStyle={styles.title}
55+
/>
56+
</View>
57+
</TouchableHighlight>;

src/components/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export * from './code-line.component';
44
export * from './error-screen';
55
export * from './comment-input.component';
66
export * from './comment-list-item.component';
7+
export * from './commit-list-item.component';
78
export * from './diff-blocks.component';
89
export * from './entity-info.component';
910
export * from './issue-description.component';

src/components/issue-description.component.js

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import React, { Component } from 'react';
2-
import { ActivityIndicator } from 'react-native';
2+
import {
3+
Text,
4+
ActivityIndicator,
5+
TouchableHighlight,
6+
} from 'react-native';
37
import { ListItem } from 'react-native-elements';
8+
49
import Parse from 'parse-diff';
510
import styled from 'styled-components';
611

@@ -56,8 +61,9 @@ const IssueTitle = styled(ListItem).attrs({
5661

5762
const DiffBlocksContainer = styled.View`
5863
flex-direction: row;
59-
align-items: center;
60-
justify-content: flex-end;
64+
align-items: stretch;
65+
justify-content: space-between;
66+
padding-left: 10;
6167
padding-right: 10;
6268
padding-bottom: 10;
6369
`;
@@ -85,16 +91,35 @@ export class IssueDescription extends Component {
8591
issue: Object,
8692
repository: Object,
8793
diff: string,
94+
commits: Array,
8895
isMergeable: boolean,
8996
isMerged: boolean,
9097
isPendingDiff: boolean,
98+
isPendingCommit: boolean,
9199
isPendingCheckMerge: boolean,
92100
onRepositoryPress: Function,
93101
userHasPushPermission: boolean,
94102
locale: string,
95103
navigation: Object,
96104
};
97105

106+
navigateToCommitList = () => {
107+
const { commits, locale } = this.props;
108+
109+
if (commits.length > 1) {
110+
this.props.navigation.navigate('CommitList', {
111+
title: t('Commits', locale),
112+
commits,
113+
locale,
114+
});
115+
} else {
116+
this.props.navigation.navigate('Commit', {
117+
commit: commits[0],
118+
title: commits[0].sha.substring(0, 7),
119+
});
120+
}
121+
};
122+
98123
renderLabelButtons = labels => {
99124
return labels
100125
.slice(0, 3)
@@ -105,10 +130,12 @@ export class IssueDescription extends Component {
105130
const {
106131
diff,
107132
issue,
133+
commits,
108134
repository,
109135
isMergeable,
110136
isMerged,
111137
isPendingDiff,
138+
isPendingCommit,
112139
isPendingCheckMerge,
113140
onRepositoryPress,
114141
userHasPushPermission,
@@ -168,10 +195,23 @@ export class IssueDescription extends Component {
168195

169196
{issue.pull_request && (
170197
<DiffBlocksContainer>
198+
{isPendingCommit && (
199+
<ActivityIndicator animating={isPendingCommit} size="small" />
200+
)}
201+
171202
{isPendingDiff && (
172203
<ActivityIndicator animating={isPendingDiff} size="small" />
173204
)}
174205

206+
{!isPendingCommit && (
207+
<TouchableHighlight
208+
onPress={() => this.navigateToCommitList()}
209+
underlayColor={colors.greyLight}
210+
>
211+
<Text>{`${commits.length} commits`}</Text>
212+
</TouchableHighlight>
213+
)}
214+
175215
{!isPendingDiff &&
176216
(lineAdditions !== 0 || lineDeletions !== 0) && (
177217
<DiffBlocks

src/issue/issue.action.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
EDIT_ISSUE_BODY,
1818
CHANGE_LOCK_STATUS,
1919
GET_ISSUE_DIFF,
20+
GET_ISSUE_COMMITS,
2021
GET_ISSUE_MERGE_STATUS,
2122
GET_PULL_REQUEST_FROM_URL,
2223
MERGE_PULL_REQUEST,
@@ -128,6 +129,29 @@ export const getIssueComments = issueCommentsURL => {
128129
};
129130
};
130131

132+
export const getCommits = url => {
133+
return (dispatch, getState) => {
134+
const accessToken = getState().auth.accessToken;
135+
136+
dispatch({ type: GET_ISSUE_COMMITS.PENDING });
137+
138+
return v3
139+
.getJson(url, accessToken)
140+
.then(data => {
141+
dispatch({
142+
type: GET_ISSUE_COMMITS.SUCCESS,
143+
payload: data,
144+
});
145+
})
146+
.catch(error => {
147+
dispatch({
148+
type: GET_ISSUE_COMMITS.ERROR,
149+
payload: error,
150+
});
151+
});
152+
};
153+
};
154+
131155
export const postIssueComment = (body, owner, repoName, issueNum) => {
132156
return (dispatch, getState) => {
133157
const accessToken = getState().auth.accessToken;

src/issue/issue.reducer.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
EDIT_ISSUE_BODY,
88
CHANGE_LOCK_STATUS,
99
GET_ISSUE_DIFF,
10+
GET_ISSUE_COMMITS,
1011
GET_ISSUE_MERGE_STATUS,
1112
GET_PULL_REQUEST_FROM_URL,
1213
MERGE_PULL_REQUEST,
@@ -21,6 +22,7 @@ export const initialState = {
2122
events: [],
2223
pr: {},
2324
diff: '',
25+
commits: [],
2426
isMerged: false,
2527
isPendingComments: false,
2628
isPendingEvents: false,
@@ -30,6 +32,7 @@ export const initialState = {
3032
isEditingIssue: false,
3133
isChangingLockStatus: false,
3234
isPendingDiff: false,
35+
isPendingCommits: false,
3336
isPendingCheckMerge: false,
3437
isPendingMerging: false,
3538
isPendingIssue: false,
@@ -210,6 +213,24 @@ export const issueReducer = (state = initialState, action = {}) => {
210213
error: action.payload,
211214
isPendingDiff: false,
212215
};
216+
case GET_ISSUE_COMMITS.PENDING:
217+
return {
218+
...state,
219+
commits: [],
220+
isPendingCommits: true,
221+
};
222+
case GET_ISSUE_COMMITS.SUCCESS:
223+
return {
224+
...state,
225+
commits: action.payload,
226+
isPendingCommits: false,
227+
};
228+
case GET_ISSUE_COMMITS.ERROR:
229+
return {
230+
...state,
231+
error: action.payload,
232+
isPendingCommits: false,
233+
};
213234
case GET_ISSUE_MERGE_STATUS.PENDING:
214235
return {
215236
...state,

src/issue/issue.type.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const EDIT_ISSUE = createActionSet('EDIT_ISSUE');
88
export const EDIT_ISSUE_BODY = createActionSet('EDIT_ISSUE_BODY');
99
export const CHANGE_LOCK_STATUS = createActionSet('CHANGE_LOCK_STATUS');
1010
export const GET_ISSUE_DIFF = createActionSet('GET_ISSUE_DIFF');
11+
export const GET_ISSUE_COMMITS = createActionSet('GET_ISSUE_COMMITS');
1112
export const GET_ISSUE_MERGE_STATUS = createActionSet('GET_ISSUE_MERGE_STATUS');
1213
export const GET_PULL_REQUEST_FROM_URL = createActionSet(
1314
'GET_PULL_REQUEST_FROM_URL'

0 commit comments

Comments
 (0)