Skip to content

Commit 1cfe86b

Browse files
committed
added schema/user settings. historyCount controls number of logs shown
1 parent 5b3f9d3 commit 1cfe86b

File tree

8 files changed

+86
-22
lines changed

8 files changed

+86
-22
lines changed

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 = {

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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": 100
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: 31 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,25 @@ 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+
// this._settings.changed.connect(this._loadSettings, this);
98+
99+
const element = (
100+
<GitPanel
101+
app={app}
102+
diff={diffFunction}
103+
renderMime={renderMime}
104+
settings={this._settings}
105+
/>
106+
);
107+
this.component = ReactDOM.render(element, this.node);
108+
this.component.refresh();
109+
});
85110
}
86111

87112
/**
@@ -190,4 +215,5 @@ export class GitWidget extends Widget {
190215
private _renderer: IRenderer = null;
191216
private _refreshId = -1;
192217
private _refreshed = new Signal<this, void>(this);
218+
private _settings: ISettingRegistry.ISettings;
193219
}

src/git.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,14 @@ export class Git {
270270
/** Make request for all git info of repository 'path'
271271
* (This API is also implicitly used to check if the current repo is a Git repo)
272272
*/
273-
async allHistory(path: string): Promise<IGitAllHistory> {
273+
async allHistory(
274+
path: string,
275+
historyCount: number
276+
): Promise<IGitAllHistory> {
274277
try {
275278
let response = await httpGitRequest('/git/all_history', 'POST', {
276-
current_path: path
279+
current_path: path,
280+
history_count: historyCount
277281
});
278282
if (response.status !== 200) {
279283
const data = await response.text();

src/index.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
JupyterFrontEnd,
44
JupyterFrontEndPlugin
55
} from '@jupyterlab/application';
6-
import { PathExt } from '@jupyterlab/coreutils';
6+
import { ISettingRegistry, PathExt } from '@jupyterlab/coreutils';
77
import { IFileBrowserFactory } from '@jupyterlab/filebrowser';
88
import { IMainMenu } from '@jupyterlab/mainmenu';
99
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
@@ -32,12 +32,13 @@ export interface IGitExtension {
3232
* The default running sessions extension.
3333
*/
3434
const plugin: JupyterFrontEndPlugin<IGitExtension> = {
35-
id: 'jupyter.extensions.running-sessions-git',
35+
id: '@jupyterlab/git:plugin',
3636
requires: [
3737
IMainMenu,
3838
ILayoutRestorer,
3939
IFileBrowserFactory,
40-
IRenderMimeRegistry
40+
IRenderMimeRegistry,
41+
ISettingRegistry
4142
],
4243
provides: IGitExtension,
4344
activate,
@@ -55,14 +56,16 @@ export class GitExtension implements IGitExtension {
5556
gitCloneWidget: GitClone;
5657
constructor(
5758
app: JupyterFrontEnd,
59+
key: string,
60+
settings: ISettingRegistry,
5861
restorer: ILayoutRestorer,
5962
factory: IFileBrowserFactory,
6063
renderMime: IRenderMimeRegistry
6164
) {
6265
this.app = app;
6366
this.gitPlugin = new GitWidget(
6467
app,
65-
{ manager: app.serviceManager },
68+
{ key, manager: app.serviceManager, settings },
6669
this.performDiff.bind(this),
6770
renderMime
6871
);
@@ -109,13 +112,22 @@ function activate(
109112
mainMenu: IMainMenu,
110113
restorer: ILayoutRestorer,
111114
factory: IFileBrowserFactory,
112-
renderMime: IRenderMimeRegistry
115+
renderMime: IRenderMimeRegistry,
116+
settings: ISettingRegistry
113117
): IGitExtension {
114118
const { commands } = app;
119+
const key = plugin.id;
115120

116121
registerGitIcons(defaultIconRegistry);
117122

118-
let gitExtension = new GitExtension(app, restorer, factory, renderMime);
123+
let gitExtension = new GitExtension(
124+
app,
125+
key,
126+
settings,
127+
restorer,
128+
factory,
129+
renderMime
130+
);
119131

120132
const category = 'Git';
121133
// Rank has been chosen somewhat arbitrarily to give priority to the running

0 commit comments

Comments
 (0)