Skip to content

Commit

Permalink
Ran nbdev_prepare to generate kyma_poc/scm.py
Browse files Browse the repository at this point in the history
  • Loading branch information
jwmatthews committed Oct 30, 2023
1 parent 140ef49 commit cbe5c9c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 17 deletions.
7 changes: 6 additions & 1 deletion kyma_poc/_modidx.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@
'doc_host': 'https://jwmatthews.github.io',
'git_url': 'https://github.com/jwmatthews/kyma_poc',
'lib_path': 'kyma_poc'},
'syms': {'kyma_poc.core': {'kyma_poc.core._sanitize_output': ('core.html#_sanitize_output', 'kyma_poc/core.py')}}}
'syms': { 'kyma_poc.core': {'kyma_poc.core._sanitize_output': ('core.html#_sanitize_output', 'kyma_poc/core.py')},
'kyma_poc.scm': { 'kyma_poc.scm.GitDiff': ('scm_git_diff.html#gitdiff', 'kyma_poc/scm.py'),
'kyma_poc.scm.GitDiff.__init__': ('scm_git_diff.html#gitdiff.__init__', 'kyma_poc/scm.py'),
'kyma_poc.scm.GitDiff.get_patch': ('scm_git_diff.html#gitdiff.get_patch', 'kyma_poc/scm.py'),
'kyma_poc.scm.GitDiff.get_patch_for_file': ( 'scm_git_diff.html#gitdiff.get_patch_for_file',
'kyma_poc/scm.py')}}}
31 changes: 31 additions & 0 deletions kyma_poc/scm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/02_scm_git_diff.ipynb.

# %% auto 0
__all__ = ['GitDiff']

# %% ../nbs/02_scm_git_diff.ipynb 12
from git import BadName, Repo

class GitDiff:
def __init__(self, repo_path):
self.repo_path = repo_path
self.repo = Repo(self.repo_path)

def get_patch(self, start_commit_id, end_commit_id="HEAD"):
# If either commit_id is not valid, this will raise a BadName exception
start_commit = self.repo.commit(start_commit_id)
end_commit = self.repo.commit(end_commit_id)
return start_commit.diff(end_commit_id, create_patch=True)

def get_patch_for_file(self, start_commit_id, end_commit_id, file_path):
diff_indexes = self.get_patch(start_commit_id, end_commit_id)
# We need to search through the indexes to find the diff for our file_path
patch = None
for diff in diff_indexes:
print(f"'{file_path}' '{diff.a_path}' '{diff.b_path}' ")
if diff.a_path == file_path or diff.b_path == file_path:
print("Found match")
patch = diff.diff
break
return patch

20 changes: 4 additions & 16 deletions nbs/02_scm_git_diff.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -149,7 +149,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -184,7 +184,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -322,21 +322,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "env",
"display_name": "python3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
}
},
"nbformat": 4,
Expand Down

0 comments on commit cbe5c9c

Please sign in to comment.