Skip to content

Added additional metadata to diff output#46

Open
banginji wants to merge 5 commits intomainfrom
additional-metadata-in-diff
Open

Added additional metadata to diff output#46
banginji wants to merge 5 commits intomainfrom
additional-metadata-in-diff

Conversation

@banginji
Copy link
Collaborator

Added in current and new commit hashes
Added the current version of the tool

This fixes #31

Added in current and new commit hashes
Added the current version of the tool

Signed-off-by: banginji <ban.ginji@gmail.com>
Signed-off-by: banginji <ban.ginji@gmail.com>
Signed-off-by: banginji <ban.ginji@gmail.com>
@banginji banginji requested a review from colindean February 26, 2026 05:31
Comment on lines 97 to 105
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: I think I'd prefer this ordering and format for the new stuff, plus some minor cleanup:

Suggested change
change_count = len(added + removed + updated)
comment = f"### Detected {change_count} changes to dependencies in Poetry lockfile\n\n"
if base_commit_hash and target_commit_hash:
# let GitHub auto-link the hashes
comment += f"From base {base_commit_hash} to target {target_commit_hash}:\n\n"
summary_lines = [p.summary_line() for p in added + removed + updated]
comment += "\n".join(summary_lines)
comment += (
f"\n\n*({len(added)} added, {len(removed)} removed, {len(updated)} updated, {len(not_changed)} not changed)*"
)
if diff_poetry_lock_version:
comment += f"<small>Generated by diff-poetry-lock {diff_poetry_lock_version}</small>\n\n"

That check and use of diff_poetry_lock_version is actually redundant: Just use __version__ directly since it's in scope. I don't really see a testing reason to override it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to follow suggested format for diff output and replaced version with __version__

Comment on lines +145 to +146
base_commit_hash = api.resolve_commit_hash(settings.ref)
target_commit_hash = api.resolve_commit_hash(settings.base_ref)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Hmm. This adds two HTTP requests to this process, right? Can we resolve the hashes without touching the API, or ensure that the result is served from some cached value since api.resolve_commit_hash() could hit a cache that may be populated in inside of load_lockfile()?

As in, when we load the lockfile given a ref, can we get the hash of the ref as a side benefit, then put that into a cache?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to make get_file to now return a json that has the sha# which is persisted in the github class and is looked up here so removed the 2 additional apis and the newly implemented api call

Comment on lines +148 to +151
packages,
base_commit_hash=base_commit_hash,
target_commit_hash=target_commit_hash,
diff_poetry_lock_version=__version__,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: This is about a parameter away from benefitting from some kind of a CommentData class. But, I think you can drop the diff_poetry_lock_version=__version__ since __version__ is in scope… or you can make it a default value for the parameter and avoid passing it here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the parameter; __version__ is inlined in the method now

Comment on lines +20 to +33
### Detected 6 changes to dependencies in Poetry lockfile

**Base commit hash (new poetry.lock):** `f4e6ca0f4d67d9bb3f8ab43a89ceca2d0d2be7a1`
**Target commit hash (old poetry.lock):** `a86b84f85d0bb2bf2fca6d6e8c58f2ce6f9e393c`
**diff-poetry-lock version:** `1.0.1`

Added **pydantic** (1.10.6)
Added **requests-mock** (1.10.0)
Added **six** (1.16.0)
Added **tomli** (2.0.1)
Added **typing-extensions** (4.5.0)
Updated **urllib3** (1.26.14 -> 1.26.15)

*(5 added, 0 removed, 1 updated, 4 not changed)*
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: If you take my above code suggestion:

Suggested change
### Detected 6 changes to dependencies in Poetry lockfile
**Base commit hash (new poetry.lock):** `f4e6ca0f4d67d9bb3f8ab43a89ceca2d0d2be7a1`
**Target commit hash (old poetry.lock):** `a86b84f85d0bb2bf2fca6d6e8c58f2ce6f9e393c`
**diff-poetry-lock version:** `1.0.1`
Added **pydantic** (1.10.6)
Added **requests-mock** (1.10.0)
Added **six** (1.16.0)
Added **tomli** (2.0.1)
Added **typing-extensions** (4.5.0)
Updated **urllib3** (1.26.14 -> 1.26.15)
*(5 added, 0 removed, 1 updated, 4 not changed)*
### Detected 6 changes to dependencies in Poetry lockfile
From base f4e6ca0f4d67d9bb3f8ab43a89ceca2d0d2be7a1 to target a86b84f85d0bb2bf2fca6d6e8c58f2ce6f9e393c:
Added **pydantic** (1.10.6)
Added **requests-mock** (1.10.0)
Added **six** (1.16.0)
Added **tomli** (2.0.1)
Added **typing-extensions** (4.5.0)
Updated **urllib3** (1.26.14 -> 1.26.15)
*(5 added, 0 removed, 1 updated, 4 not changed)*
<small>Generated by diff-poetry-lock 1.0.1</small>\n\n

Remember, GH will autolink the hashes and shorten to just 8 chars on display.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

try:
r = self.session.get(
f"{self.s.api_url}/repos/{self.s.repository}/commits/{ref}",
headers={"Authorization": f"token {self.s.token}", "Accept": "application/vnd.github+json"},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: We should extract this authorization header generation to a method. It's copypasted all over this class.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracted the headers to a function

Comment on lines 82 to 90
**Base commit hash (new poetry.lock):** `new-sha`
**Target commit hash (old poetry.lock):** `old-sha`
**diff-poetry-lock version:** `test-version`

Removed **pydantic** (1.10.6)
Removed **typing-extensions** (4.5.0)
Updated **urllib3** (1.26.15 -> 1.26.14)

*(0 added, 2 removed, 1 updated, 4 not changed)*"""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: This will have to change if you take my suggestion below.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Comment on lines 117 to 127
### Detected 3 changes to dependencies in Poetry lockfile

**Base commit hash (new poetry.lock):** `new-sha`
**Target commit hash (old poetry.lock):** `old-sha`
**diff-poetry-lock version:** `test-version`

Added **pydantic** (1.10.6)
Added **typing-extensions** (4.5.0)
Updated **urllib3** (1.26.14 -> 1.26.15)

*(2 added, 0 removed, 1 updated, 4 not changed)*"""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: This will have to change if you take my suggestion below.

Consider extracting this example to a variable since of duplicating it, especially if it's not different from above.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

banginji added 2 commits March 2, 2026 19:42
1- Modified commit hash lookup to be done in the get_file api call
2- Altered diff output format
3- Wrapped the api headers into a function to be reused instead of the headers dict

Signed-off-by: banginji <ban.ginji@users.noreply.github.com>
Signed-off-by: banginji <ban.ginji@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Change list should show more metadata

2 participants