Skip to content

Commit 8094e4d

Browse files
Merge pull request jupyterlab#21 from jupyterlab/test
29th June, more than 5 buttons added, still building it up.
2 parents 41e53b3 + f11a1ec commit 8094e4d

File tree

2 files changed

+164
-28
lines changed

2 files changed

+164
-28
lines changed

git_handler/hi/hi/handlers.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,20 @@ def post_metrics():
3131

3232
class hi(IPythonHandler):
3333
def get(self):
34-
my_output = subprocess.check_output(["git", "log"])
35-
print(my_output)
36-
#self.finish(my_output)
37-
self.finish(json.dumps(get_metrics(my_output.decode("utf-8"))))
34+
self.finish(json.dumps(post_metrics()))
3835
print("Hi there! get extension!!")
3936

4037
def post(self):
4138
my_data = json.loads(self.request.body)
42-
print(my_data)
43-
my_output = subprocess.check_output(["git", "status"])
39+
temp = my_data["git_command"]
40+
<<<<<<< HEAD
41+
print(temp)
42+
my_output = subprocess.check_output(temp)
43+
#my_output = subprocess.check_output(["git", temp])
44+
=======
45+
print(temp+"hahahaha")
46+
my_output = subprocess.check_output(["git", temp])
47+
>>>>>>> 031de4ba54da64ac3661b65f1352829178560f03
4448
self.finish(my_output)
4549
#self.finish(json.dumps(post_metrics()))
4650
print("Hi there! post extensions!!")

src/index.ts

Lines changed: 154 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,21 @@ namespace CommandIDs {
5252
export
5353
const git_st = 'AVCbox:git status';
5454

55+
export
56+
const git_add = 'AVCbox:git add';
57+
5558
export
5659
const git_log = 'AVCbox:git log';
5760

61+
export
62+
const git_pull = 'AVCbox:git pull';
63+
64+
export
65+
const git_remote = 'AVCbox:git remote';
66+
67+
export
68+
const git_commit = 'AVCbox:git commit';
69+
5870
export
5971
const get_git_api = 'AVCbox:git api';
6072
};
@@ -76,10 +88,77 @@ const AVCboxPlugin: JupyterLabPlugin<void> = {
7688
*/
7789
export default AVCboxPlugin;
7890

91+
/**
92+
* Export interfaces for Git command use
93+
*/
94+
export interface IGit {
95+
path: string;
96+
version: string;
97+
}
98+
99+
export interface IFileStatus {
100+
x: string;
101+
y: string;
102+
path: string;
103+
rename?: string;
104+
}
105+
106+
export interface Remote {
107+
name: string;
108+
url: string;
109+
}
110+
111+
export enum RefType {
112+
Head,
113+
RemoteHead,
114+
Tag
115+
}
116+
117+
export interface Ref {
118+
type: RefType;
119+
name?: string;
120+
commit?: string;
121+
remote?: string;
122+
}
123+
124+
export interface Branch extends Ref {
125+
upstream?: string;
126+
ahead?: number;
127+
behind?: number;
128+
}
129+
130+
export interface IExecutionResult {
131+
exitCode: number;
132+
stdout: string;
133+
stderr: string;
134+
}
135+
136+
export interface IGitErrorData {
137+
error?: Error;
138+
message?: string;
139+
stdout?: string;
140+
stderr?: string;
141+
exitCode?: number;
142+
gitErrorCode?: string;
143+
gitCommand?: string;
144+
}
145+
146+
export interface IGitOptions {
147+
gitPath: string;
148+
version: string;
149+
env?: any;
150+
}
151+
152+
export interface Commit {
153+
hash: string;
154+
message: string;
155+
}
156+
79157
/**
80158
* a test link function for buttons
81159
*/
82160

161+
83162
let serverSettings = ServerConnection.makeSettings();
84163
let gapiLoaded = new PromiseDelegate<void>();
85164
export
@@ -98,6 +177,29 @@ function loadGapi(): Promise<void> {
98177
});
99178
}
100179

180+
function POST_Git_Request(git_command){
181+
let data0 = {"git_command":git_command , "parameters":{"id":"valore"}};
182+
let request = {
183+
url: URLExt.join(serverSettings.baseUrl, 'hi'),
184+
method: 'POST',
185+
cache: true,
186+
contentType: 'bar',
187+
headers: {
188+
foo: 'bar'
189+
},
190+
data: JSON.stringify(data0),
191+
//data: '{"git_command":["git", "status"], "parameters":{"id":"valore"}}'
192+
};
193+
194+
ServerConnection.makeRequest(request, serverSettings).then(response =>{
195+
if (response.xhr.status !== 200) {
196+
throw ServerConnection.makeError(response);
197+
}
198+
//console.log(JSON.stringify(response.data, null, 2));
199+
console.log(response.data);
200+
});
201+
202+
}
101203

102204
/**
103205
* Activate the AVCbox extension.
@@ -118,6 +220,7 @@ function activateAVCbox(app: JupyterLab, rendermime: IRenderMime, palette: IComm
118220
rendermime: rendermime.clone(),
119221
contentFactory
120222
});
223+
121224
//test msg
122225
console.log('JupyterLab extension JL_git (typescript extension) is activated!');
123226
// Add the AVCbox panel to the tracker.
@@ -132,24 +235,7 @@ function activateAVCbox(app: JupyterLab, rendermime: IRenderMime, palette: IComm
132235
label: 'git status command',
133236
execute: args => {
134237
console.log('Try to exec *git status* command');
135-
136-
let request = {
137-
url: URLExt.join(serverSettings.baseUrl, 'hi'),
138-
method: 'POST',
139-
cache: true,
140-
contentType: 'bar',
141-
headers: {
142-
foo: 'bar'
143-
},
144-
data: '["foo", {"bar":["baz", null, 1.0, 2]}]',
145-
};
146-
147-
ServerConnection.makeRequest(request, serverSettings).then(response =>{
148-
if (response.xhr.status !== 200) {
149-
throw ServerConnection.makeError(response);
150-
}
151-
console.log(JSON.stringify(response.data, null, 2));
152-
});
238+
POST_Git_Request( ["git","status"] )
153239
}
154240
});
155241
palette.addItem({ command, category });
@@ -161,17 +247,63 @@ function activateAVCbox(app: JupyterLab, rendermime: IRenderMime, palette: IComm
161247
label: 'git log command',
162248
execute: args => {
163249
console.log('Try to exec *git log* command');
250+
164251
$.getJSON(serverSettings.baseUrl + 'hi', function(data) {
165-
//console.log(data['rss']);
166-
//console.log(data['limits']['memory']);
167-
console.log(JSON.stringify(data, null, 2));
252+
console.log(data['rss']);
253+
console.log(data['limits']['memory']);
254+
//console.log(JSON.stringify(data, null, 2));
168255
});
256+
POST_Git_Request(["git","log"])
257+
}
258+
});
259+
palette.addItem({ command, category });
260+
261+
//git pull button
262+
command = CommandIDs.git_pull;
263+
commands.addCommand(command, {
264+
label: 'git pull command',
265+
execute: args => {
266+
console.log('Try to exec *git pull* command');
267+
POST_Git_Request(["git","pull"])
169268
}
170269
});
171270
palette.addItem({ command, category });
172271

272+
//git remote button
273+
command = CommandIDs.git_remote;
274+
commands.addCommand(command, {
275+
label: 'git remote command',
276+
execute: args => {
277+
console.log('Try to exec *git remote -v* command');
278+
POST_Git_Request(["git", "remote", "-v"])
279+
}
280+
});
281+
palette.addItem({ command, category });
282+
283+
//jvftcf
284+
//git commit button
285+
command = CommandIDs.git_commit;
286+
commands.addCommand(command, {
287+
label: 'git commit command',
288+
execute: args => {
289+
console.log('Try to exec *git commit* command');
290+
POST_Git_Request(["git", "commit", "-m", "'surprise!!!!'"])
291+
}
292+
});
293+
palette.addItem({ command, category });
294+
295+
//git add button
296+
command = CommandIDs.git_add;
297+
commands.addCommand(command, {
298+
label: 'git add command',
299+
execute: args => {
300+
console.log('Try to exec *git add* command');
301+
POST_Git_Request(["git", "add", "src/index.ts"])
302+
}
303+
});
304+
palette.addItem({ command, category });
173305

174-
//Third button
306+
//test button
175307
command = CommandIDs.get_git_api;
176308
commands.addCommand(command, {
177309
label: 'Access GitHub JSON',

0 commit comments

Comments
 (0)