Skip to content

Commit e651bea

Browse files
authored
Merge pull request #424 from telamonian/add-user-settings
Adds user setings: historyCount controls number of logs shown
2 parents 5b3f9d3 + c6a4319 commit e651bea

File tree

12 files changed

+136
-31
lines changed

12 files changed

+136
-31
lines changed

.travis.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ cache:
55
pip: true
66
directories:
77
- /home/travis/.yarn-cache/
8+
install: pip install pytest "jupyterlab~=1.0"
89
script:
9-
- pip install 'jupyterlab~=1.0'
1010
- python setup.py sdist
11-
- pip install --find-links=dist jupyterlab_git[test]
12-
- pytest jupyterlab_git
13-
- jlpm run test
11+
- pip install jupyterlab_git[test] --find-links=dist --no-deps --no-cache-dir -v
12+
- pip install jupyterlab_git[test] --find-links=dist -v
13+
- jupyter labextension list
1414
- jupyter lab build
15+
- pytest jupyterlab_git -r ap
16+
- jlpm run test
1517
- python -m jupyterlab.browser_check
1618
- jlpm run lint
1719
- python tests/test-browser/run_browser_test.py

MANIFEST.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ graft tests
1414
prune tests/build
1515

1616
# Javascript files
17+
graft schema
1718
graft src
1819
graft style
1920
prune **/node_modules
@@ -24,4 +25,4 @@ global-exclude *~
2425
global-exclude *.pyc
2526
global-exclude *.pyo
2627
global-exclude .git
27-
global-exclude .ipynb_checkpoints
28+
global-exclude .ipynb_checkpoints

jupyterlab_git/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Copyright (c) Project Jupyter.
22
# Distributed under the terms of the Modified BSD License.
33

4-
version_info = (0, 8, 2)
4+
version_info = (0, 9, 0)
55
__version__ = ".".join(map(str, version_info))

jupyterlab_git/git.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,12 @@ def status(self, current_path):
233233
"message": my_error.decode("utf-8"),
234234
}
235235

236-
def log(self, current_path):
236+
def log(self, current_path, history_count=10):
237237
"""
238238
Execute git log command & return the result.
239239
"""
240240
p = Popen(
241-
["git", "log", "--pretty=format:%H%n%an%n%ar%n%s", "-10"],
241+
["git", "log", "--pretty=format:%H%n%an%n%ar%n%s", ("-%d" % history_count)],
242242
stdout=PIPE,
243243
stderr=PIPE,
244244
cwd=os.path.join(self.root_dir, current_path),

jupyterlab_git/handlers.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,16 @@ def post(self):
5151
POST request handler, calls individual handlers for
5252
'git show_top_level', 'git branch', 'git log', and 'git status'
5353
"""
54-
current_path = self.get_json_body()["current_path"]
54+
body = self.get_json_body()
55+
current_path = body["current_path"]
56+
history_count = body["history_count"]
57+
5558
show_top_level = self.git.show_top_level(current_path)
5659
if show_top_level["code"] != 0:
5760
self.finish(json.dumps(show_top_level))
5861
else:
5962
branch = self.git.branch(current_path)
60-
log = self.git.log(current_path)
63+
log = self.git.log(current_path, history_count)
6164
status = self.git.status(current_path)
6265

6366
result = {

jupyterlab_git/tests/test_handlers.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import json
12
from mock import Mock, ANY, patch
23

3-
from jupyterlab_git.handlers import GitUpstreamHandler, GitPushHandler, setup_handlers
4+
from jupyterlab_git.handlers import GitAllHistoryHandler, GitUpstreamHandler, GitPushHandler, setup_handlers
45

56

67
def test_mapping_added():
@@ -17,7 +18,7 @@ def test_mapping_added():
1718
@patch('jupyterlab_git.handlers.GitUpstreamHandler.get_json_body', Mock(return_value={'current_path': 'test_path'}))
1819
@patch('jupyterlab_git.handlers.GitUpstreamHandler.git')
1920
@patch('jupyterlab_git.handlers.GitUpstreamHandler.finish')
20-
def test_push_handler_localbranch(mock_finish, mock_git):
21+
def test_upstream_handler_localbranch(mock_finish, mock_git):
2122
# Given
2223
mock_git.get_current_branch.return_value = 'foo'
2324
mock_git.get_upstream_branch.return_value = 'bar'
@@ -31,6 +32,42 @@ def test_push_handler_localbranch(mock_finish, mock_git):
3132
mock_finish.assert_called_with('{"upstream": "bar"}')
3233

3334

35+
@patch('jupyterlab_git.handlers.GitAllHistoryHandler.__init__', Mock(return_value=None))
36+
@patch('jupyterlab_git.handlers.GitAllHistoryHandler.get_json_body', Mock(return_value={'current_path': 'test_path', 'history_count': 25}))
37+
@patch('jupyterlab_git.handlers.GitAllHistoryHandler.git')
38+
@patch('jupyterlab_git.handlers.GitAllHistoryHandler.finish')
39+
def test_all_history_handler_localbranch(mock_finish, mock_git):
40+
# Given
41+
show_top_level = {'code': 0, 'foo': 'top_level'}
42+
branch = 'branch_foo'
43+
log = 'log_foo'
44+
status = 'status_foo'
45+
46+
mock_git.show_top_level.return_value = show_top_level
47+
mock_git.branch.return_value = branch
48+
mock_git.log.return_value = log
49+
mock_git.status.return_value = status
50+
51+
# When
52+
GitAllHistoryHandler().post()
53+
54+
# Then
55+
mock_git.show_top_level.assert_called_with('test_path')
56+
mock_git.branch.assert_called_with('test_path')
57+
mock_git.log.assert_called_with('test_path', 25)
58+
mock_git.status.assert_called_with('test_path')
59+
60+
mock_finish.assert_called_with(json.dumps({
61+
'code': show_top_level['code'],
62+
'data': {
63+
'show_top_level': show_top_level,
64+
'branch': branch,
65+
'log': log,
66+
'status': status,
67+
}
68+
}))
69+
70+
3471
@patch('jupyterlab_git.handlers.GitPushHandler.__init__', Mock(return_value=None))
3572
@patch('jupyterlab_git.handlers.GitPushHandler.get_json_body', Mock(return_value={'current_path': 'test_path'}))
3673
@patch('jupyterlab_git.handlers.GitPushHandler.git')

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@jupyterlab/git",
3-
"version": "0.8.2",
3+
"version": "0.9.0",
44
"description": "A JupyterLab extension for version control using git",
55
"main": "lib/index.js",
66
"style": "style/index.css",
@@ -28,14 +28,13 @@
2828
},
2929
"files": [
3030
"lib/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf}",
31-
"style/*.css",
32-
"style/images/*.svg"
31+
"schema/**/*.{json,}",
32+
"style/**/*.{css,svg}"
3333
],
3434
"sideEffects": [
3535
"style/*.css"
3636
],
3737
"jupyterlab": {
38-
"extension": true,
3938
"discovery": {
4039
"server": {
4140
"managers": [
@@ -46,7 +45,9 @@
4645
"name": "jupyterlab-git"
4746
}
4847
}
49-
}
48+
},
49+
"extension": true,
50+
"schemaDir": "schema"
5051
},
5152
"dependencies": {
5253
"@jupyterlab/application": "^1.1.0",

schema/plugin.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"jupyter.lab.setting-icon-class": "jp-GitIcon",
3+
"jupyter.lab.setting-icon-label": "Git",
4+
"title": "Git",
5+
"description": "jupyterlab-git settings.",
6+
"type": "object",
7+
"properties": {
8+
"historyCount": {
9+
"type": "integer",
10+
"title": "History count",
11+
"description": "Number of (most recent) commits shown in the history log",
12+
"default": 25
13+
}
14+
}
15+
}

src/components/GitPanel.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
findRepoButtonStyle
2929
} from '../style/GitPanelStyle';
3030
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
31+
import { ISettingRegistry } from '@jupyterlab/coreutils';
3132

3233
/** Interface for GitPanel component state */
3334
export interface IGitSessionNodeState {
@@ -56,6 +57,7 @@ export interface IGitSessionNodeProps {
5657
app: JupyterFrontEnd;
5758
diff: IDiffCallback;
5859
renderMime: IRenderMimeRegistry;
60+
settings: ISettingRegistry.ISettings;
5961
}
6062

6163
/** A React component for the git extension's main display */
@@ -103,7 +105,8 @@ export class GitPanel extends React.Component<
103105
if (fileBrowser) {
104106
// Make API call to get all git info for repo
105107
let apiResult = await gitApi.allHistory(
106-
(fileBrowser as any).model.path
108+
(fileBrowser as any).model.path,
109+
this.props.settings.composite['historyCount'] as number
107110
);
108111

109112
if (apiResult.code === 0) {

src/components/GitWidget.tsx

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,16 @@ import { gitWidgetStyle } from '../style/GitWidgetStyle';
1919
import { IDiffCallback } from '../git';
2020

2121
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
22+
import { ISettingRegistry } from '@jupyterlab/coreutils';
2223
/**
2324
* An options object for creating a running sessions widget.
2425
*/
2526
export interface IOptions {
27+
/**
28+
* A settings key.
29+
*/
30+
key: string;
31+
2632
/**
2733
* A service manager instance.
2834
*/
@@ -33,6 +39,11 @@ export interface IOptions {
3339
* The default is a shared renderer instance.
3440
*/
3541
renderer?: IRenderer;
42+
43+
/**
44+
* The setings registry.
45+
*/
46+
settings: ISettingRegistry;
3647
}
3748

3849
/**
@@ -77,11 +88,26 @@ export class GitWidget extends Widget {
7788
node: (options.renderer || defaultRenderer).createNode()
7889
});
7990
this.addClass(gitWidgetStyle);
80-
const element = (
81-
<GitPanel app={app} diff={diffFunction} renderMime={renderMime} />
82-
);
83-
this.component = ReactDOM.render(element, this.node);
84-
this.component.refresh();
91+
92+
const { key } = options;
93+
const registry = options.settings;
94+
95+
void registry.load(key).then(settings => {
96+
this._settings = settings;
97+
98+
const element = (
99+
<GitPanel
100+
app={app}
101+
diff={diffFunction}
102+
renderMime={renderMime}
103+
settings={this._settings}
104+
/>
105+
);
106+
this.component = ReactDOM.render(element, this.node);
107+
108+
this._settings.changed.connect(this.component.refresh, this);
109+
this.component.refresh();
110+
});
85111
}
86112

87113
/**
@@ -190,4 +216,5 @@ export class GitWidget extends Widget {
190216
private _renderer: IRenderer = null;
191217
private _refreshId = -1;
192218
private _refreshed = new Signal<this, void>(this);
219+
private _settings: ISettingRegistry.ISettings;
193220
}

0 commit comments

Comments
 (0)