Skip to content

Commit 708d19f

Browse files
iflindafcollonval
andauthored
Feature 866 - Display Commit Description (jupyterlab#1134)
* test test * Removed unecessary commit history from testing * Changed single quote to double quote * Function detailed_log now returns commit message. Added additional check for pytest test_detailed_log. Updated .prej-commit-config.yaml to latest version of pre-commit from version 20.8b1 to 22.3.0 as commits were failing using the old version. * Changed variable name of commit message * Test Summary Test Description * Revert 'Test Summary' This reverts commit c7ac545 * Modified detailed_log function to also return commit message The detailed_log function now uses --pretty=%B format to return all the commit info. Also added test case in pytest test_detailed_log.py * Added additional function to run command(s) to request git log with specific formats. * Renamed function and added comments to execute_log_command function. Started modify py.test for test_detailed_log. * Added ability to see entire commit body when viewing history from SinglePastCommitInfo.tsx. Added minor padding to styling in SinglePastCommitInfo.ts padding. * Update jupyterlab_git/git.py Co-authored-by: Frédéric Collonval <[email protected]> * Fixed styling issue with \n by applying 'whiteSpace: pre-wrap' style to the commitBodyClass. * Fixed git log command to include --pretty=format:%b%x00 and added minor styling changes * Modified test_detailed_log.py to return commit_body expected response * Fixed issue with commit_body not removing white spaces correctly * Update jupyterlab_git/git.py to simplify commit_body output. Co-authored-by: Frédéric Collonval <[email protected]> * Fixed issue with commit_body not removing x00 and added additional strip for strip_and_split function to remove new lines. Co-authored-by: Frédéric Collonval <[email protected]>
1 parent 9b035bf commit 708d19f

File tree

6 files changed

+84
-51
lines changed

6 files changed

+84
-51
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/psf/black
3-
rev: 20.8b1 # Replace by any tag/version: https://github.com/psf/black/tags
3+
rev: 22.3.0 # Replace by any tag/version: https://github.com/psf/black/tags
44
hooks:
55
- id: black
66
language_version: python3 # Should be a command that runs python3.6+

jupyterlab_git/git.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def strip_and_split(s):
170170
"""strip trailing \x00 and split on \x00
171171
Useful for parsing output of git commands with -z flag.
172172
"""
173-
return s.strip("\x00").split("\x00")
173+
return s.strip("\x00").strip("\n").split("\x00")
174174

175175

176176
class Git:
@@ -555,19 +555,29 @@ async def detailed_log(self, selected_hash, path):
555555
Execute git log -1 --numstat --oneline -z command (used to get
556556
insertions & deletions per file) & return the result.
557557
"""
558-
cmd = ["git", "log", "-1", "--numstat", "--oneline", "-z", selected_hash]
558+
cmd = [
559+
"git",
560+
"log",
561+
"-1",
562+
"--numstat",
563+
"--pretty=format:%b%x00",
564+
"-z",
565+
selected_hash,
566+
]
567+
559568
code, my_output, my_error = await execute(
560569
cmd,
561570
cwd=path,
562571
)
563-
564572
if code != 0:
565573
return {"code": code, "command": " ".join(cmd), "message": my_error}
566574

567575
total_insertions = 0
568576
total_deletions = 0
569577
result = []
570-
line_iterable = iter(strip_and_split(my_output)[1:])
578+
first_split = my_output.split("\x00", 1)
579+
commit_body = first_split[0].strip()
580+
line_iterable = iter(strip_and_split(first_split[1].strip()))
571581
for line in line_iterable:
572582
is_binary = line.startswith("-\t-\t")
573583
previous_file_path = ""
@@ -609,6 +619,7 @@ async def detailed_log(self, selected_hash, path):
609619

610620
return {
611621
"code": code,
622+
"commit_body": commit_body,
612623
"modified_file_note": modified_file_note,
613624
"modified_files_count": str(len(result)),
614625
"number_of_insertions": str(total_insertions),

jupyterlab_git/tests/test_detailed_log.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ async def test_detailed_log():
1313
with patch("jupyterlab_git.git.execute") as mock_execute:
1414
# Given
1515
process_output = [
16-
"f29660a (HEAD, origin/feature) Commit message",
17-
"10\t3\tnotebook_without_spaces.ipynb",
16+
" Test Description with leading and trailing spaces ",
17+
"\n10\t3\tnotebook_without_spaces.ipynb",
1818
"11\t4\tNotebook with spaces.ipynb",
1919
"12\t5\tpath/notebook_without_spaces.ipynb",
2020
"13\t6\tpath/Notebook with spaces.ipynb",
@@ -31,6 +31,7 @@ async def test_detailed_log():
3131

3232
expected_response = {
3333
"code": 0,
34+
"commit_body": "Test Description with leading and trailing spaces",
3435
"modified_file_note": "7 files changed, 60 insertions(+), 19 deletions(-)",
3536
"modified_files_count": "7",
3637
"number_of_insertions": "60",
@@ -102,7 +103,7 @@ async def test_detailed_log():
102103
"log",
103104
"-1",
104105
"--numstat",
105-
"--oneline",
106+
"--pretty=format:%b%x00",
106107
"-z",
107108
"f29660a2472e24164906af8653babeb48e4bf2ab",
108109
],

src/components/SinglePastCommitInfo.tsx

+55-42
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import * as React from 'react';
44
import { LoggerContext } from '../logger';
55
import { GitExtension } from '../model';
66
import { discardIcon, rewindIcon } from '../style/icons';
7-
import { actionButtonClass } from '../style/SinglePastCommitInfo';
7+
import {
8+
actionButtonClass,
9+
commitBodyClass
10+
} from '../style/SinglePastCommitInfo';
811
import { Git } from '../tokens';
912
import { ActionButton } from './ActionButton';
1013
import { CommitDiff } from './CommitDiff';
@@ -58,6 +61,11 @@ export interface ISinglePastCommitInfoState {
5861
*/
5962
info: string;
6063

64+
/**
65+
* Commit information.
66+
*/
67+
commitBody: string;
68+
6169
/**
6270
* Number of modified files.
6371
*/
@@ -111,6 +119,7 @@ export class SinglePastCommitInfo extends React.Component<
111119
super(props);
112120
this.state = {
113121
info: '',
122+
commitBody: '',
114123
numFiles: '',
115124
insertions: '',
116125
deletions: '',
@@ -130,6 +139,7 @@ export class SinglePastCommitInfo extends React.Component<
130139

131140
this.setState({
132141
info: log.modified_file_note,
142+
commitBody: log.commit_body,
133143
numFiles: log.modified_files_count,
134144
insertions: log.number_of_insertions,
135145
deletions: log.number_of_deletions,
@@ -159,47 +169,50 @@ export class SinglePastCommitInfo extends React.Component<
159169
return <div>{this.props.trans.__('Error loading commit data')}</div>;
160170
}
161171
return (
162-
<CommitDiff
163-
actions={
164-
<>
165-
<ActionButton
166-
className={actionButtonClass}
167-
icon={discardIcon}
168-
title={this.props.trans.__(
169-
'Revert changes introduced by this commit'
170-
)}
171-
onClick={this._onRevertClick}
172-
/>
173-
<ActionButton
174-
className={actionButtonClass}
175-
icon={rewindIcon}
176-
title={this.props.trans.__(
177-
'Discard changes introduced *after* this commit (hard reset)'
178-
)}
179-
onClick={this._onResetClick}
180-
/>
181-
<LoggerContext.Consumer>
182-
{logger => (
183-
<ResetRevertDialog
184-
open={this.state.resetRevertDialog}
185-
action={this.state.resetRevertAction}
186-
model={this.props.model}
187-
logger={logger}
188-
commit={this.props.commit}
189-
onClose={this._onResetRevertDialogClose}
190-
trans={this.props.trans}
191-
/>
192-
)}
193-
</LoggerContext.Consumer>
194-
</>
195-
}
196-
numFiles={this.state.numFiles}
197-
insertions={this.state.insertions}
198-
deletions={this.state.deletions}
199-
files={this.state.modifiedFiles}
200-
onOpenDiff={this.props.onOpenDiff}
201-
trans={this.props.trans}
202-
></CommitDiff>
172+
<div>
173+
<p className={commitBodyClass}>{this.state.commitBody}</p>
174+
<CommitDiff
175+
actions={
176+
<>
177+
<ActionButton
178+
className={actionButtonClass}
179+
icon={discardIcon}
180+
title={this.props.trans.__(
181+
'Revert changes introduced by this commit'
182+
)}
183+
onClick={this._onRevertClick}
184+
/>
185+
<ActionButton
186+
className={actionButtonClass}
187+
icon={rewindIcon}
188+
title={this.props.trans.__(
189+
'Discard changes introduced *after* this commit (hard reset)'
190+
)}
191+
onClick={this._onResetClick}
192+
/>
193+
<LoggerContext.Consumer>
194+
{logger => (
195+
<ResetRevertDialog
196+
open={this.state.resetRevertDialog}
197+
action={this.state.resetRevertAction}
198+
model={this.props.model}
199+
logger={logger}
200+
commit={this.props.commit}
201+
onClose={this._onResetRevertDialogClose}
202+
trans={this.props.trans}
203+
/>
204+
)}
205+
</LoggerContext.Consumer>
206+
</>
207+
}
208+
numFiles={this.state.numFiles}
209+
insertions={this.state.insertions}
210+
deletions={this.state.deletions}
211+
files={this.state.modifiedFiles}
212+
onOpenDiff={this.props.onOpenDiff}
213+
trans={this.props.trans}
214+
></CommitDiff>
215+
</div>
203216
);
204217
}
205218

src/style/SinglePastCommitInfo.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ export const commitClass = style({
55
width: '100%',
66
fontSize: '12px',
77
marginBottom: '10px',
8-
marginTop: '5px'
8+
marginTop: '5px',
9+
paddingTop: '5px'
910
});
1011

1112
export const commitOverviewNumbersClass = style({
@@ -92,3 +93,9 @@ export const fileListClass = style({
9293
export const actionButtonClass = style({
9394
float: 'right'
9495
});
96+
97+
export const commitBodyClass = style({
98+
paddingTop: '5px',
99+
whiteSpace: 'pre-wrap',
100+
wordWrap: 'break-word'
101+
});

src/tokens.ts

+1
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,7 @@ export namespace Git {
957957
*/
958958
export interface ISingleCommitFilePathInfo {
959959
code: number;
960+
commit_body?: string;
960961
modified_file_note?: string;
961962
modified_files_count?: string;
962963
number_of_insertions?: string;

0 commit comments

Comments
 (0)