Skip to content

Commit 44f52ce

Browse files
authored
Merge pull request #10 from iaoiui/master
Add a feature to commit only source code(.py)
2 parents 789e267 + 15e03e8 commit 44f52ce

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

env.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
####################### SSH KEY FOR GIT ###################################
2-
ssh-keygen -t rsa && ssh-keygen -y -f ~/.ssh/id_rsa > ~/.ssh/id_rsa.pub && eval `ssh-agent -s` && ssh-add -k
2+
eval `ssh-agent -s` && ssh-add -k
33
####################### To be added to git account settings ################
44

55

githubcommit/handlers.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os, json, git, urllib, requests
44
from git import Repo, GitCommandError
55
from subprocess import check_output
6+
import subprocess
67

78
class GitCommitHandler(IPythonHandler):
89

@@ -32,6 +33,8 @@ def put(self):
3233
data = json.loads(self.request.body.decode('utf-8'))
3334
filename = urllib.parse.unquote(data['filename'])
3435
msg = data['msg']
36+
commit_only_source = data['commit_only_source']
37+
3538

3639
# get current directory (to return later)
3740
cwd = os.getcwd()
@@ -54,8 +57,13 @@ def put(self):
5457
# commit current notebook
5558
# client will sent pathname containing git directory; append to git directory's parent
5659
try:
60+
if commit_only_source :
61+
subprocess.run(['jupyter', 'nbconvert', '--to', 'script', str(os.environ.get('GIT_PARENT_DIR') + "/" + os.environ.get('GIT_REPO_NAME') + filename)])
62+
filename = str(os.environ.get('GIT_PARENT_DIR') + "/" + os.environ.get('GIT_REPO_NAME') + filename.replace('ipynb', 'py'))
63+
5764
print(repo.git.add(str(os.environ.get('GIT_PARENT_DIR') + "/" + os.environ.get('GIT_REPO_NAME') + filename)))
58-
print(repo.git.commit( a=True, m="{}\n\nUpdated {}".format(msg, filename) ))
65+
print(repo.git.commit( a=False, m="{}\n\nUpdated {}".format(msg, filename) ))
66+
5967
except GitCommandError as e:
6068
print(e)
6169
self.error_and_return(cwd, "Could not commit changes to notebook: {}".format(git_dir_parent + filename))

githubcommit/static/main.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ define(['base/js/namespace','base/js/dialog','jquery'],function(IPython, dialog,
1313
var input = $('<textarea rows="4" cols="72"></textarea>')
1414
var div = $('<div/>')
1515

16+
var checkbox = '<input type="checkbox" id="commit_only_source" name="feature" value="scales" checked /><label>commit only source code</label>'
17+
18+
div.append(checkbox)
1619
div.append(p)
1720
.append(input)
1821

@@ -24,7 +27,8 @@ define(['base/js/namespace','base/js/dialog','jquery'],function(IPython, dialog,
2427
var filepath = window.location.pathname.match(re)[1];
2528
var payload = {
2629
'filename': filepath,
27-
'msg': input.val()
30+
'msg': input.val(),
31+
'commit_only_source': $("#commit_only_source").prop('checked')
2832
};
2933
var settings = {
3034
url : '/git/commit',
@@ -83,6 +87,7 @@ define(['base/js/namespace','base/js/dialog','jquery'],function(IPython, dialog,
8387
notebook:env.notebook,
8488
keyboard_manager: env.notebook.keyboard_manager,
8589
})
90+
8691
}
8792
}
8893

0 commit comments

Comments
 (0)