Skip to content

Commit a7dec31

Browse files
committed
feat(commit): show commits in repository screen
1 parent 7071077 commit a7dec31

File tree

6 files changed

+79
-10
lines changed

6 files changed

+79
-10
lines changed

src/components/commit-list-item.component.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ const styles = StyleSheet.create({
1818
borderBottomWidth: 1,
1919
borderBottomColor: colors.greyLight,
2020
},
21-
closedIssue: {
22-
backgroundColor: colors.greyVeryLight,
23-
opacity: 0.6,
24-
},
2521
listItemContainer: {
2622
flex: 1,
2723
borderBottomWidth: 0,
@@ -30,10 +26,6 @@ const styles = StyleSheet.create({
3026
color: colors.primaryDark,
3127
...fonts.fontPrimary,
3228
},
33-
badge: {
34-
alignItems: 'flex-end',
35-
justifyContent: 'center',
36-
},
3729
});
3830

3931
export const CommitListItem = ({ commit, navigation }: Props) =>
@@ -47,9 +39,11 @@ export const CommitListItem = ({ commit, navigation }: Props) =>
4739
<View style={styles.container}>
4840
<ListItem
4941
containerStyle={styles.listItemContainer}
50-
title={commit.message}
42+
title={commit.commit.message.split('\n')[0]}
5143
titleNumberOfLines={1}
52-
subtitle={commit.sha.substring(0, 7) + ' - ' + commit.author.name || ''} // eslint-disable-line prefer-template
44+
subtitle={
45+
`${commit.sha.substring(0, 7)} - ${commit.commit.author.name}` || ''
46+
}
5347
leftIcon={{
5448
name: 'git-commit',
5549
size: 36,

src/locale/languages/en.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ export const en = {
174174
noContributorsMessage: 'No contributors found',
175175
sourceTitle: 'SOURCE',
176176
readMe: 'README',
177+
viewCommit: 'View Commits',
177178
viewSource: 'View Code',
178179
issuesTitle: 'ISSUES',
179180
noIssuesMessage: 'No issues',

src/repository/repository.action.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
GET_REPOSITORY_CONTENTS,
1818
GET_REPOSITORY_FILE,
1919
GET_REPOSITORY_ISSUES,
20+
GET_REPOSITORY_COMMITS,
2021
GET_REPO_STARRED_STATUS,
2122
GET_COMMIT,
2223
GET_COMMIT_DIFF,
@@ -142,6 +143,28 @@ export const getIssues = url => {
142143
};
143144
};
144145

146+
export const getCommits = url => {
147+
return (dispatch, getState) => {
148+
const accessToken = getState().auth.accessToken;
149+
150+
dispatch({ type: GET_REPOSITORY_COMMITS.PENDING });
151+
152+
fetchUrl(url, accessToken)
153+
.then(data => {
154+
dispatch({
155+
type: GET_REPOSITORY_COMMITS.SUCCESS,
156+
payload: data,
157+
});
158+
})
159+
.catch(error => {
160+
dispatch({
161+
type: GET_REPOSITORY_COMMITS.ERROR,
162+
payload: error,
163+
});
164+
});
165+
};
166+
};
167+
145168
const getCommitFromUrl = url => {
146169
return (dispatch, getState) => {
147170
const accessToken = getState().auth.accessToken;
@@ -276,9 +299,14 @@ export const getRepositoryInfo = url => {
276299
'{/number}',
277300
'?state=all&per_page=100'
278301
);
302+
const commitsUrl = getState().repository.repository.commits_url.replace(
303+
'{/sha}',
304+
'?state=all&per_page=100'
305+
);
279306

280307
dispatch(getContributors(contributorsUrl));
281308
dispatch(getIssues(issuesUrl));
309+
dispatch(getCommits(commitsUrl));
282310
dispatch(
283311
checkRepoStarred(
284312
`https://api.github.com/user/starred/${repo.owner.login}/${repo.name}`

src/repository/repository.reducer.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
GET_REPOSITORY_CONTENTS,
55
GET_REPOSITORY_FILE,
66
GET_REPOSITORY_ISSUES,
7+
GET_REPOSITORY_COMMITS,
78
GET_REPO_STARRED_STATUS,
89
FORK_REPO_STATUS,
910
CHANGE_STAR_STATUS,
@@ -25,6 +26,7 @@ const initialState = {
2526
contents: {},
2627
fileContent: '',
2728
issues: [],
29+
commits: [],
2830
commit: {},
2931
diff: {},
3032
readMe: '',
@@ -38,6 +40,7 @@ const initialState = {
3840
isPendingRepository: false,
3941
isPendingContributors: false,
4042
isPendingContents: false,
43+
isPendingCommits: false,
4144
isPendingCommit: false,
4245
isPendingCommitDiff: false,
4346
isPendingFile: false,
@@ -148,6 +151,23 @@ export const repositoryReducer = (state = initialState, action = {}) => {
148151
error: action.payload,
149152
isPendingIssues: false,
150153
};
154+
case GET_REPOSITORY_COMMITS.PENDING:
155+
return {
156+
...state,
157+
isPendingCommits: true,
158+
};
159+
case GET_REPOSITORY_COMMITS.SUCCESS:
160+
return {
161+
...state,
162+
commits: action.payload,
163+
isPendingCommits: false,
164+
};
165+
case GET_REPOSITORY_COMMITS.ERROR:
166+
return {
167+
...state,
168+
error: action.payload,
169+
isPendingCommits: false,
170+
};
151171
case GET_REPO_STARRED_STATUS.PENDING:
152172
return {
153173
...state,

src/repository/repository.type.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export const GET_COMMIT = createActionSet('GET_COMMIT');
1111
export const GET_COMMIT_DIFF = createActionSet('GET_COMMIT_DIFF');
1212
export const GET_REPOSITORY_FILE = createActionSet('GET_REPOSITORY_FILE');
1313
export const GET_REPOSITORY_ISSUES = createActionSet('GET_REPOSITORY_ISSUES');
14+
export const GET_REPOSITORY_COMMITS = createActionSet('GET_REPOSITORY_COMMITS');
1415
export const GET_REPO_STARRED_STATUS = createActionSet(
1516
'GET_REPO_STARRED_STATUS'
1617
);

src/repository/screens/repository.screen.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
getRepositoryInfo,
2424
getContributors,
2525
getIssues,
26+
getCommits,
2627
changeStarStatusRepo,
2728
forkRepo,
2829
subscribeToRepo,
@@ -35,6 +36,7 @@ const mapStateToProps = state => ({
3536
repository: state.repository.repository,
3637
contributors: state.repository.contributors,
3738
issues: state.repository.issues,
39+
commits: state.repository.commits,
3840
starred: state.repository.starred,
3941
forked: state.repository.forked,
4042
subscribed: state.repository.subscribed,
@@ -50,6 +52,7 @@ const mapDispatchToProps = dispatch => ({
5052
getRepositoryInfoByDispatch: url => dispatch(getRepositoryInfo(url)),
5153
getContributorsByDispatch: url => dispatch(getContributors(url)),
5254
getIssuesByDispatch: url => dispatch(getIssues(url)),
55+
getCommitsByDispatch: url => dispatch(getCommits(url)),
5356
changeStarStatusRepoByDispatch: (owner, repo, starred) =>
5457
dispatch(changeStarStatusRepo(owner, repo, starred)),
5558
forkRepoByDispatch: (owner, repo) => dispatch(forkRepo(owner, repo)),
@@ -69,12 +72,14 @@ class Repository extends Component {
6972
// selectRepositoryByDispatch: Function,
7073
getRepositoryInfoByDispatch: Function,
7174
// getIssuesByDispatch: Function,
75+
// getCommitsByDispatch: Function,
7276
changeStarStatusRepoByDispatch: Function,
7377
forkRepoByDispatch: Function,
7478
// repositoryName: string,
7579
repository: Object,
7680
contributors: Array,
7781
issues: Array,
82+
commits: Array,
7883
starred: boolean,
7984
// forked: boolean,
8085
isPendingRepository: boolean,
@@ -191,6 +196,7 @@ class Repository extends Component {
191196
repository,
192197
contributors,
193198
issues,
199+
commits,
194200
starred,
195201
language,
196202
isPendingRepository,
@@ -335,6 +341,25 @@ class Repository extends Component {
335341
})}
336342
underlayColor={colors.greyLight}
337343
/>
344+
{commits.length > 0 &&
345+
<ListItem
346+
title={translate('repository.main.viewCommit', language)}
347+
titleStyle={styles.listTitle}
348+
leftIcon={{
349+
name: 'git-commit',
350+
color: colors.grey,
351+
type: 'octicon',
352+
}}
353+
onPress={() =>
354+
this.props.navigation.navigate('CommitList', {
355+
commits,
356+
title: translate(
357+
'repository.commitList.title',
358+
this.props.language
359+
),
360+
})}
361+
underlayColor={colors.greyLight}
362+
/>}
338363
<ListItem
339364
title={translate('repository.main.viewSource', language)}
340365
titleStyle={styles.listTitle}

0 commit comments

Comments
 (0)