-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GitCommitterIdentityHandler and change identity check
User should be asked for name and email only when none of the following conditions are satisfied - * git config contains user.name and user.email * GIT_COMMITTER_NAME and GIT_COMMITTER_EMAIL are set * EMAIL is set If any of the above is true, git doesn't show warning to set the author info.
- Loading branch information
1 parent
99849b7
commit 5ce2624
Showing
5 changed files
with
149 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
GitLogHandler, | ||
GitPushHandler, | ||
GitUpstreamHandler, | ||
GitCommitterIdentityHandler, | ||
setup_handlers, | ||
) | ||
|
||
|
@@ -62,6 +63,71 @@ def test_all_history_handler_localbranch(self, mock_git): | |
} | ||
|
||
|
||
class TestCommitterIdentityHandler(ServerTest): | ||
@patch("jupyterlab_git.handlers.GitCommitterIdentityHandler.git", spec=Git) | ||
def test_name_and_email_from_config(self, mock_git): | ||
config_options = {"code": 0, "options": {"user.name": "foo", "user.email": "bar"}} | ||
mock_git.config.return_value = maybe_future(config_options) | ||
|
||
response = self.tester.get(["/committer_identity?path=/path/to/repo"]) | ||
payload = response.json() | ||
assert payload == {"identityEstablished": True} | ||
|
||
@patch("jupyterlab_git.handlers.GitCommitterIdentityHandler.git", spec=Git) | ||
def test_name_missing_from_config(self, mock_git): | ||
config_options = {"code": 0, "options": {"user.email": "bar"}} | ||
mock_git.config.return_value = maybe_future(config_options) | ||
|
||
response = self.tester.get(["/committer_identity?path=/path/to/repo"]) | ||
payload = response.json() | ||
assert payload == {"identityEstablished": False} | ||
|
||
@patch("jupyterlab_git.handlers.GitCommitterIdentityHandler.git", spec=Git) | ||
def test_email_missing_from_config(self, mock_git): | ||
config_options = {"code": 0, "options": {"user.name": "bar"}} | ||
mock_git.config.return_value = maybe_future(config_options) | ||
|
||
response = self.tester.get(["/committer_identity?path=/path/to/repo"]) | ||
payload = response.json() | ||
assert payload == {"identityEstablished": False} | ||
|
||
@patch("jupyterlab_git.handlers.GitCommitterIdentityHandler.git", spec=Git) | ||
@patch.dict(os.environ, {"GIT_COMMITTER_NAME": "foo", "GIT_COMMITTER_EMAIL": "[email protected]"}) | ||
def test_committer_name_email_var(self, mock_git): | ||
mock_git.config.return_value = maybe_future({"code": 0, "options": {}}) | ||
|
||
response = self.tester.get(["/committer_identity?path=/path/to/repo"]) | ||
payload = response.json() | ||
assert payload == {"identityEstablished": True} | ||
|
||
@patch("jupyterlab_git.handlers.GitCommitterIdentityHandler.git", spec=Git) | ||
@patch.dict(os.environ, {"GIT_COMMITTER_NAME": "foo"}) | ||
def test_missing_committer_email_var(self, mock_git): | ||
mock_git.config.return_value = maybe_future({"code": 0, "options": {}}) | ||
|
||
response = self.tester.get(["/committer_identity?path=/path/to/repo"]) | ||
payload = response.json() | ||
assert payload == {"identityEstablished": False} | ||
|
||
@patch("jupyterlab_git.handlers.GitCommitterIdentityHandler.git", spec=Git) | ||
@patch.dict(os.environ, {"GIT_COMMITTER_EMAIL": "[email protected]"}) | ||
def test_committer_name_var(self, mock_git): | ||
mock_git.config.return_value = maybe_future({"code": 0, "options": {}}) | ||
|
||
response = self.tester.get(["/committer_identity?path=/path/to/repo"]) | ||
payload = response.json() | ||
assert payload == {"identityEstablished": False} | ||
|
||
@patch("jupyterlab_git.handlers.GitCommitterIdentityHandler.git", spec=Git) | ||
@patch.dict(os.environ, {"EMAIL": "[email protected]"}) | ||
def test_committer_name_email_var(self, mock_git): | ||
mock_git.config.return_value = maybe_future({"code": 0, "options": {}}) | ||
|
||
response = self.tester.get(["/committer_identity?path=/path/to/repo"]) | ||
payload = response.json() | ||
assert payload == {"identityEstablished": True} | ||
|
||
|
||
class TestBranch(ServerTest): | ||
@patch("jupyterlab_git.handlers.GitBranchHandler.git", spec=Git) | ||
def test_branch_handler_localbranch(self, mock_git): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,14 +108,11 @@ describe('GitPanel', () => { | |
|
||
// Mock identity look up | ||
const identity = jest | ||
.spyOn(GitModel.prototype, 'config') | ||
.spyOn(GitModel.prototype, 'isCommitterIdentitySet') | ||
.mockResolvedValue( | ||
new Response( | ||
JSON.stringify({ | ||
options: { | ||
'user.name': 'John Snow', | ||
'user.email': '[email protected]' | ||
} | ||
identityEstablished: true | ||
}), | ||
{ status: 201 } | ||
) | ||
|
@@ -136,81 +133,29 @@ describe('GitPanel', () => { | |
spy.mockRestore(); | ||
}); | ||
|
||
it('should prompt for user identity if user.name is not set', async () => { | ||
it('should prompt for user identity if not set', async () => { | ||
const spy = jest.spyOn(GitModel.prototype, 'commit'); | ||
|
||
// Mock identity look up | ||
const identity = jest | ||
const config = jest | ||
.spyOn(GitModel.prototype, 'config') | ||
.mockImplementation(options => { | ||
let response: Response = null; | ||
if (options === undefined) { | ||
response = new Response( | ||
JSON.stringify({ | ||
options: { | ||
'user.email': '[email protected]' | ||
} | ||
}), | ||
{ status: 201 } | ||
); | ||
} else { | ||
response = new Response('', { status: 201 }); | ||
} | ||
response = new Response('', { status: 201 }); | ||
return Promise.resolve(response); | ||
}); | ||
const mock = apputils as jest.Mocked<typeof apputils>; | ||
mock.showDialog.mockResolvedValue({ | ||
button: { | ||
accept: true, | ||
caption: '', | ||
className: '', | ||
displayType: 'default', | ||
iconClass: '', | ||
iconLabel: '', | ||
label: '' | ||
}, | ||
value: { | ||
name: 'John Snow', | ||
email: '[email protected]' | ||
} | ||
}); | ||
|
||
const panel = new GitPanel(props); | ||
await panel.commitStagedFiles('Initial commit'); | ||
expect(identity).toHaveBeenCalledTimes(2); | ||
expect(identity.mock.calls[0]).toHaveLength(0); | ||
expect(identity.mock.calls[1]).toEqual([ | ||
{ | ||
'user.name': 'John Snow', | ||
'user.email': '[email protected]' | ||
} | ||
]); | ||
expect(spy).toHaveBeenCalledTimes(1); | ||
expect(spy).toHaveBeenCalledWith('Initial commit'); | ||
}); | ||
|
||
it('should prompt for user identity if user.email is not set', async () => { | ||
const spy = jest.spyOn(GitModel.prototype, 'commit'); | ||
|
||
// Mock identity look up | ||
const identity = jest | ||
.spyOn(GitModel.prototype, 'config') | ||
.mockImplementation(options => { | ||
let response: Response = null; | ||
if (options === undefined) { | ||
response = new Response( | ||
JSON.stringify({ | ||
options: { | ||
'user.name': 'John Snow' | ||
} | ||
}), | ||
{ status: 201 } | ||
); | ||
} else { | ||
response = new Response('', { status: 201 }); | ||
} | ||
return Promise.resolve(response); | ||
}); | ||
.spyOn(GitModel.prototype, 'isCommitterIdentitySet') | ||
.mockResolvedValue( | ||
new Response( | ||
JSON.stringify({ | ||
identityEstablished: false | ||
}), | ||
{ status: 201 } | ||
) | ||
); | ||
|
||
const mock = apputils as jest.Mocked<typeof apputils>; | ||
mock.showDialog.mockResolvedValue({ | ||
button: { | ||
|
@@ -230,9 +175,9 @@ describe('GitPanel', () => { | |
|
||
const panel = new GitPanel(props); | ||
await panel.commitStagedFiles('Initial commit'); | ||
expect(identity).toHaveBeenCalledTimes(2); | ||
expect(identity.mock.calls[0]).toHaveLength(0); | ||
expect(identity.mock.calls[1]).toEqual([ | ||
expect(identity).toHaveBeenCalledTimes(1); | ||
expect(config).toHaveBeenCalledTimes(1); | ||
expect(config.mock.calls[0]).toEqual([ | ||
{ | ||
'user.name': 'John Snow', | ||
'user.email': '[email protected]' | ||
|
@@ -247,21 +192,16 @@ describe('GitPanel', () => { | |
|
||
// Mock identity look up | ||
const identity = jest | ||
.spyOn(GitModel.prototype, 'config') | ||
.mockImplementation(options => { | ||
let response: Response = null; | ||
if (options === undefined) { | ||
response = new Response( | ||
JSON.stringify({ | ||
options: {} | ||
}), | ||
{ status: 201 } | ||
); | ||
} else { | ||
response = new Response('', { status: 201 }); | ||
} | ||
return Promise.resolve(response); | ||
}); | ||
.spyOn(GitModel.prototype, 'isCommitterIdentitySet') | ||
.mockResolvedValue( | ||
new Response( | ||
JSON.stringify({ | ||
identityEstablished: false | ||
}), | ||
{ status: 201 } | ||
) | ||
); | ||
|
||
const mock = apputils as jest.Mocked<typeof apputils>; | ||
mock.showDialog.mockResolvedValue({ | ||
button: { | ||
|
@@ -279,7 +219,6 @@ describe('GitPanel', () => { | |
const panel = new GitPanel(props); | ||
await panel.commitStagedFiles('Initial commit'); | ||
expect(identity).toHaveBeenCalledTimes(1); | ||
expect(identity).toHaveBeenCalledWith(); | ||
expect(spy).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
|