Coveralls logob
Coveralls logo
  • Home
  • Features
  • Pricing
  • Docs
  • Sign In

atom / github / 2542

5 Dec 2018 - 23:18 coverage increased (+0.4%) to 85.952%
2542

Pull #1822

travis-ci

9181eb84f9c35729a3bad740fb7f9d93?size=18&default=identiconweb-flow
commit pipeline tests
Pull Request #1822: [wip] Fix: git tab keeps popping open when there's a merge conflict

3117 of 3837 branches covered (81.24%)

Branch coverage included in aggregate %.

3 of 4 new or added lines in 3 files covered. (75.0%)

7 existing lines in 2 files now uncovered.

7260 of 8236 relevant lines covered (88.15%)

512.39 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.89
/lib/controllers/status-bar-tile-controller.js
1
import React, {Fragment} from 'react';
2
import PropTypes from 'prop-types';
3

4
import BranchView from '../views/branch-view';
5
import BranchMenuView from '../views/branch-menu-view';
6
import PushPullView from '../views/push-pull-view';
7
import ChangedFilesCountView from '../views/changed-files-count-view';
8
import GithubTileView from '../views/github-tile-view';
9
import Tooltip from '../atom/tooltip';
10
import Commands, {Command} from '../atom/commands';
11
import ObserveModel from '../views/observe-model';
12
import RefHolder from '../models/ref-holder';
13
import yubikiri from 'yubikiri';
14

15
export default class StatusBarTileController extends React.Component {
16
  static propTypes = {
17
    workspace: PropTypes.object.isRequired,
18
    notificationManager: PropTypes.object.isRequired,
19
    commandRegistry: PropTypes.object.isRequired,
20
    tooltips: PropTypes.object.isRequired,
21
    confirm: PropTypes.func.isRequired,
22
    repository: PropTypes.object.isRequired,
23
    toggleGitTab: PropTypes.func,
24
    toggleGithubTab: PropTypes.func,
25
  }
26

27
  constructor(props) {
28
    super(props);
88×
29

30
    this.refBranchViewRoot = new RefHolder();
88×
31
  }
32

33
  getChangedFilesCount(data) {
34
    const {stagedFiles, unstagedFiles, mergeConflictFiles} = data.statusesForChangedFiles;
244×
35
    const changedFiles = new Set();
244×
36

37
    for (const filePath in unstagedFiles) {
244×
38
      changedFiles.add(filePath);
68×
39
    }
40
    for (const filePath in stagedFiles) {
244×
41
      changedFiles.add(filePath);
40×
42
    }
43
    for (const filePath in mergeConflictFiles) {
244×
UNCOV
44
      changedFiles.add(filePath);
!
45
    }
46

47
    return changedFiles.size;
244×
48
  }
49

50
  fetchData = repository => {
51
    return yubikiri({
259×
52
      currentBranch: repository.getCurrentBranch(),
53
      branches: repository.getBranches(),
54
      statusesForChangedFiles: repository.getStatusesForChangedFiles(),
55
      currentRemote: async query => repository.getRemoteForBranch((await query.currentBranch).getName()),
259×
56
      aheadCount: async query => repository.getAheadCount((await query.currentBranch).getName()),
259×
57
      behindCount: async query => repository.getBehindCount((await query.currentBranch).getName()),
259×
58
      originExists: async () => (await repository.getRemotes()).withName('origin').isPresent(),
259×
59
    });
60
  }
61

62
  render() {
63
    return (
122×
64
      <ObserveModel model={this.props.repository} fetchData={this.fetchData}>
65
        {data => (data ? this.renderWithData(data) : null)}
366×
66
      </ObserveModel>
67
    );
68
  }
69

70
  renderWithData(data) {
71
    let changedFilesCount, mergeConflictsPresent;
72
    if (data.statusesForChangedFiles) {
Branches [[1, 1]] missed. 244×
73
      changedFilesCount = this.getChangedFilesCount(data);
244×
74
      mergeConflictsPresent = Object.keys(data.statusesForChangedFiles.mergeConflictFiles).length > 0;
244×
75
    }
76

77
    const repoProps = {
244×
78
      repository: this.props.repository,
79
      currentBranch: data.currentBranch,
80
      branches: data.branches,
81
      currentRemote: data.currentRemote,
82
      aheadCount: data.aheadCount,
83
      behindCount: data.behindCount,
84
      originExists: data.originExists,
85
      changedFilesCount,
86
      mergeConflictsPresent,
87
    };
88

89
    return (
244×
90
      <Fragment>
91
        {this.renderTiles(repoProps)}
92
        <GithubTileView didClick={this.props.toggleGithubTab} />
93
        <ChangedFilesCountView
94
          didClick={this.props.toggleGitTab}
95
          changedFilesCount={repoProps.changedFilesCount}
96
          mergeConflictsPresent={repoProps.mergeConflictsPresent}
97
        />
98
      </Fragment>
99
    );
100
  }
101

102
  renderTiles(repoProps) {
103
    if (!this.props.repository.showStatusBarTiles()) {
244×
104
      return null;
60×
105
    }
106

107
    const operationStates = this.props.repository.getOperationStates();
184×
108
    const pushInProgress = operationStates.isPushInProgress();
184×
109
    const pullInProgress = operationStates.isPullInProgress();
184×
110
    const fetchInProgress = operationStates.isFetchInProgress();
184×
111

112
    return (
184×
113
      <Fragment>
114
        <Commands registry={this.props.commandRegistry} target="atom-workspace">
115
          <Command command="github:fetch" callback={this.fetch(repoProps)} />
116
          <Command command="github:pull" callback={this.pull(repoProps)} />
117
          <Command
118
            command="github:push"
119
            callback={() => this.push(repoProps)({force: false, setUpstream: !repoProps.currentRemote.isPresent()})}
1×
120
          />
121
          <Command
122
            command="github:force-push"
123
            callback={() => this.push(repoProps)({force: true, setUpstream: !repoProps.currentRemote.isPresent()})}
1×
124
          />
125
        </Commands>
126
        <BranchView
127
          refRoot={this.refBranchViewRoot.setter}
128
          workspace={this.props.workspace}
129
          checkout={this.checkout}
130
          currentBranch={repoProps.currentBranch}
131
        />
132
        <Tooltip
133
          manager={this.props.tooltips}
134
          target={this.refBranchViewRoot}
135
          trigger="click"
136
          className="github-StatusBarTileController-tooltipMenu">
137
          <BranchMenuView
138
            workspace={this.props.workspace}
139
            notificationManager={this.props.notificationManager}
140
            commandRegistry={this.props.commandRegistry}
141
            checkout={this.checkout}
142
            branches={repoProps.branches}
143
            currentBranch={repoProps.currentBranch}
144
          />
145
        </Tooltip>
146
        <PushPullView
147
          isSyncing={fetchInProgress || pullInProgress || pushInProgress}
148
          isFetching={fetchInProgress}
149
          isPulling={pullInProgress}
150
          isPushing={pushInProgress}
151
          push={this.push(repoProps)}
152
          pull={this.pull(repoProps)}
153
          fetch={this.fetch(repoProps)}
154
          tooltipManager={this.props.tooltips}
155
          currentBranch={repoProps.currentBranch}
156
          currentRemote={repoProps.currentRemote}
157
          behindCount={repoProps.behindCount}
158
          aheadCount={repoProps.aheadCount}
159
          originExists={repoProps.originExists}
160
        />
161
      </Fragment>
162
    );
163
  }
164

165
  handleOpenGitTimingsView = e => {
166
    e && e.preventDefault();
Branches [[4, 0], [4, 1]] missed. !
167
    this.props.workspace.open('atom-github://debug/timings');
!
168
  }
169

170
  checkout = (branchName, options) => {
171
    return this.props.repository.checkout(branchName, options);
6×
172
  }
173

174
  push(data) {
175
    return ({force, setUpstream} = {}) => {
188×
176
      return this.props.repository.push(data.currentBranch.getName(), {
6×
177
        force,
178
        setUpstream,
179
        refSpec: data.currentBranch.getRefSpec('PUSH'),
180
      });
181
    };
182
  }
183

184
  pull(data) {
185
    return () => {
370×
186
      return this.props.repository.pull(data.currentBranch.getName(), {
5×
187
        refSpec: data.currentBranch.getRefSpec('PULL'),
188
      });
189
    };
190
  }
191

192
  fetch(data) {
193
    return () => {
369×
194
      const upstream = data.currentBranch.getUpstream();
3×
195
      return this.props.repository.fetch(upstream.getRemoteRef(), {
3×
196
        remoteName: upstream.getRemoteName(),
197
      });
198
    };
199
  }
200
}
Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
BLOG · TWITTER · Legal & Privacy · Supported CI Services · What's a CI service? · Automated Testing

© 2019 Coveralls, LLC