forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-tab-container.js
73 lines (67 loc) · 2.13 KB
/
git-tab-container.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import React from 'react';
import PropTypes from 'prop-types';
import yubikiri from 'yubikiri';
import {nullCommit} from '../models/commit';
import {nullBranch} from '../models/branch';
import ObserveModel from '../views/observe-model';
import GitTabController from '../controllers/git-tab-controller';
const DEFAULT_REPO_DATA = {
repository: null,
username: '',
email: '',
lastCommit: nullCommit,
recentCommits: [],
isMerging: false,
isRebasing: false,
hasUndoHistory: false,
currentBranch: nullBranch,
unstagedChanges: [],
stagedChanges: [],
mergeConflicts: [],
workingDirectoryPath: null,
mergeMessage: null,
fetchInProgress: true,
};
export default class GitTabContainer extends React.Component {
static propTypes = {
repository: PropTypes.object.isRequired,
}
fetchData = repository => {
return yubikiri({
repository,
username: repository.getConfig('user.name').then(n => n || ''),
email: repository.getConfig('user.email').then(n => n || ''),
lastCommit: repository.getLastCommit(),
recentCommits: repository.getRecentCommits({max: 10}),
isMerging: repository.isMerging(),
isRebasing: repository.isRebasing(),
hasUndoHistory: repository.hasDiscardHistory(),
currentBranch: repository.getCurrentBranch(),
unstagedChanges: repository.getUnstagedChanges(),
stagedChanges: repository.getStagedChanges(),
mergeConflicts: repository.getMergeConflicts(),
workingDirectoryPath: repository.getWorkingDirectoryPath(),
mergeMessage: async query => {
const isMerging = await query.isMerging;
return isMerging ? repository.getMergeMessage() : null;
},
fetchInProgress: false,
});
}
render() {
return (
<ObserveModel model={this.props.repository} fetchData={this.fetchData}>
{data => {
const dataProps = data || DEFAULT_REPO_DATA;
return (
<GitTabController
{...dataProps}
{...this.props}
repositoryDrift={this.props.repository !== dataProps.repository}
/>
);
}}
</ObserveModel>
);
}
}