Skip to content

#1145: persist commit fields in MkCommits.create#1850

Merged
yegor256 merged 2 commits intojcabi:masterfrom
bibonix:fix-1145-mkcommits-persistence
May 5, 2026
Merged

#1145: persist commit fields in MkCommits.create#1850
yegor256 merged 2 commits intojcabi:masterfrom
bibonix:fix-1145-mkcommits-persistence

Conversation

@bibonix
Copy link
Copy Markdown
Contributor

@bibonix bibonix commented May 5, 2026

Fixes #1145.

MkCommits.create(JsonObject) previously delegated straight to get(sha) without applying any Directives, so nothing was ever written to the mock storage XML. Any subsequent call that traverses the storage (MkCommit.json(), etc.) raised NodeNotFoundException because the XPath /github/repos/repo[@coords=...]/git/commits/commit[sha=...] selected zero nodes.

The fix walks the input JSON and writes each key as an element under a new <commit> node, mirroring how MkBranches.create and MkReferences.create persist their inputs. Arrays are stored with the @array attribute that JsonNode already understands, and nested objects (author, etc.) are stored as nested elements.

Reproduction

The first commit adds two failing tests to MkCommitsTest that call commits.create(...) and then read the commit back via commits.get(sha).json(). On master both fail with NodeNotFoundException. After the fix in the second commit, all three tests in MkCommitsTest pass and the full mvn test suite is green (715 tests, 6 skipped pre-existing).

Test plan

  • mvn -B -ntp test -Dtest=MkCommitsTest — 3 / 3 green
  • mvn -B -ntp test — 715 tests, no failures or errors
  • No new qulice violations introduced (verified via mvn -Pqulice; only the pre-existing PMD warnings on createsMkCommit remain)

bibonix added 2 commits May 5, 2026 04:35
Adds two tests that call MkCommits.create(JsonObject) and then assert
that input fields (sha, message) survive a round-trip through
MkCommits.get(sha).json(). Both tests fail on master because
MkCommits.create() does not apply any Directives to the storage XML
and the commit node is missing when MkCommit.json() runs its XPath.
MkCommits.create(JsonObject) used to delegate straight to get(sha) without
applying any Directives, so the commit node was never inserted into the
mock storage XML. Any subsequent call to MkCommit.json() (or any other
method that reads from the storage) raised NodeNotFoundException because
the XPath /github/repos/repo/git/commits/commit[sha=...] selected nothing.

The fix walks the input JsonObject and writes every key as an element
under the new <commit> node, mirroring how MkBranches.create and
MkReferences.create persist their inputs. Arrays are stored with the
@array attribute that JsonNode already understands, so MkCommit.json()
round-trips them as JsonArray. Nested objects (e.g. author) are stored
as nested elements.
@yegor256 yegor256 merged commit 0d57c51 into jcabi:master May 5, 2026
8 of 14 checks passed
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.

MkCommit does not persist in storage

2 participants