git log, paste the output into a prompt, and publish whatever comes back.
That design works until the model writes “Closes #214” for a pull request nobody opened, or credits a fix to a commit hash that does not exist. A release note is a public statement about a repository, and the model cannot see the repository. It sees text.
This post builds the other design. JGit reads the real repository. Plain Java groups the commits by Conventional Commit type, works out the next version number and writes every line that names a commit or a pull request. A Spring AI ChatModel is asked for exactly one thing, a short opening paragraph, and its answer is checked against the list of commits it was given before it is used. Then a small Gitea client publishes the result, and publishes it in a way that survives being run twice.
If you read the earlier post on an AI code-review bot for Gitea and GitHub, this is its sibling, and the two differ in a way worth stating up front. The review bot reads a diff and writes inline comments on lines; its characteristic failure is a comment on a line number the model made up. This one reads history and writes documents; its characteristic failure is a commit hash or PR number the model made up. The guard is the same idea pointed at different facts, and nothing in this post needs the webhook machinery from that one.
Read this before the output blocks. The sandbox this was built in has no LLM API key, so no real language model was called. Every piece of “model output” below comes fromStubChatModel, a deterministic class that countsfeatandfixlines in the prompt and can be told to misbehave on purpose. It is labelled as a stub wherever it appears, and nothing here claims anything about how a real model words its answer. What is real: the JGit repository the tests build on disk, every commit hash, the parser, the grouping, the version bump, the diff budget, the guard, and the HTTP requests the Gitea client sends (to a small local fake server, not to a real Gitea).
Versions tested. JDK Temurin 25.0.5.1 (LTS), JGit 7.8.1.202611041320-r (latest GA on Maven Central, published 4 November 2026), Spring AI 2.1.0 (GA; its BOM pom was published to Maven Central on 19 November 2026), Spring Boot 4.2.0 BOM, JUnit 6.1.3. Gitea endpoints and field names were read from the swagger document of the Gitea 1.27.3 server behind ankurm.com. Every number in this post comes from a file in release-notes-ai/output.
Only one stage of the pipeline needs a model
Before any code, it helps to see the whole job as six stages and ask which of them a language model is actually good for.release-notes-ai in the java-ai-agents repository. The pieces map one to one onto the stages: GitHistory.java, ConventionalCommit.java, ReleaseModel.java, ReleaseNotes.java, Highlights.java, GiteaClient.java.
Going deeper
- Conventional Commits 1.0.0 specification — the commit format stage 2 parses
- Semantic Versioning — the rule stage 3 uses to pick the next version
- git-cliff — an existing tool that does stages 1 to 4 without a model; see the closing section
Read the commits with JGit, and expect three surprises
JGit is a pure-Java implementation of Git, so there is nogit binary to shell out to and no output to parse. The one call you need for a release is a range: the commits reachable from the new tag but not from the previous one, which is what git log v1.0.0..v1.1.0 prints.
/** Commits reachable from {@code to} but not from {@code from} (git's from..to), oldest first, merges skipped. */
public List<CommitInfo> commitsBetween(String from, String to) {
try (RevWalk rw = new RevWalk(repo)) {
List<CommitInfo> out = new ArrayList<>();
var log = git.log().addRange(commitOf(from), commitOf(to)).call();
for (RevCommit c : log) {
if (c.getParentCount() > 1) {
continue;
}
out.add(describe(c));
}
Collections.reverse(out);
return out;
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
That method lives in GitHistory.java. Two details are deliberate. log() walks newest first and release notes read oldest first, so the list is reversed. And merge commits are dropped, because a merge commit’s own subject (“Merge branch ‘feature/search'”) says nothing a reader wants; the commits it brought in are already in the range.
To test this against something real, the test suite builds a repository on disk with JGit itself: fourteen commits of assorted kinds, a feature branch merged with --no-ff, an annotated tag v1.0.0 and a lightweight tag v1.1.0. Author and committer dates are fixed, so the hashes are identical on every run (two consecutive runs produced byte-identical transcripts). Here is the range between the two tags, from output/02-history-range.txt:
$ git log --oneline v1.0.0..v1.1.0 (oldest first, merge commits skipped)
6e9776a feat(cli): add --json output flag (#3) files=1 +1 -0
6ba3519 fix: stop retrying on 4xx files=1 +1 -0
4ab0a75 docs: explain retry policy files=1 +1 -0
0082b4d Fixed stuff files=1 +1 -0
a061359 refactor(core)!: rename Order.id to Order.orderId files=1 +1 -1
2ff8458 perf(db): batch inserts in OrderRepository (#5) files=1 +1 -0
633f424 wip: half done files=1 +1 -0
92049cc feat(search): add fuzzy search (#6) files=1 +1 -0
08cccc3 docs: document back-off files=1 +1 -1
dedef67 Revert "feat(cli): add --json output flag" files=1 +1 -1
commits git log walks: 11, commits kept after skipping merges: 10
Ten commits are kept out of the eleven that git log walks; the missing one is the merge. Three smaller things in the same transcript each cost a surprise while writing this.
The root commit has no parent. To count lines added and deleted per commit, the code diffs each commit against its first parent. The very first commit of a repository has none, so there is nothing to diff against. The fix is to diff against an empty tree, which JGit exposes as EmptyTreeIterator (see parentTree in GitHistory.java). The transcript shows the root commit coming out as three files, +3 -0, instead of an exception.
root commit 84be7a6: files=3 +3 -0 (diffed against an empty tree, it has no parent)
An annotated tag is not the commit it points at. Reading the tag ref gives you the tag object for an annotated tag and the commit for a lightweight one, so the same call returns different kinds of thing depending on how the tag was made. The transcript shows it directly: the annotated v1.0.0 ref points at 03c7aed but peels to commit 17deac5; the lightweight v1.1.0 ref and its commit are the same dedef67. Asking JGit to resolve name^{commit}, as commitOf does, gives the commit for both. Use that anywhere you need a commit hash, for instance as the target of a Gitea release.
annotated tag v1.0.0: ref points at 03c7aed, peels to commit 17deac5, commitOf says 17deac5
lightweight tag v1.1.0: ref points at dedef67, commitOf says dedef67
previousTag(v1.1.0) = v1.0.0
previousTag(v1.0.0) = none
JGit ignores your intentions but obeys your~/.gitconfig. The first run of the test suite failed on every test that builds a repository, withUnsupportedSigningFormatException: No signer for ssh signatures. The sandbox user hascommit.gpgsign=trueandgpg.format=sshin the global Git config, and JGit reads it. CallingsetSign(false)on the commit and tag commands was not enough, becauseMergeCommandhas no such method (a compile error confirmed that), so the fixture now pinscommit.gpgsignandtag.gpgsignto false in the new repository’s own config. If your tests create commits with JGit and pass on your laptop but fail in CI, or the other way round, check the global config first. A second trap in the same area:MergeCommandstamps the merge commit with the wall clock, which changes every later hash on every run. The fixture prepares the merge withsetCommit(false)and commits it with a fixed date; see Fixture.java.
Intermediate: finding the previous tag instead of passing it in
A release job should not need to be told “the previous version was v1.0.0”. previousTag in GitHistory.java lists every tag that parses as MAJOR.MINOR.PATCH, keeps those whose commit is an ancestor of the one being released (JGit’s isMergedInto), excludes a tag that points at the release commit itself, and takes the highest. The two assertions in the transcript above show both ends: the previous tag of v1.1.0 is v1.0.0, and the previous tag of v1.0.0 is none, which is the signal to use commitsUpTo and write notes for the whole history.
It deliberately ignores tags that are not plain versions (v2.0.0-rc1, nightly). If you release release candidates and want notes relative to them, that is a one-line change to the SemVer pattern and a decision about what “previous” means for your project.
Going deeper
- Eclipse JGit project page
- GitHistory.java —
commitsBetween,commitsUpTo,previousTag,mergeBase,branchDiff - Fixture.java — the on-disk repository the tests are built on
Read each commit as a Conventional Commit, and decide what the rest are
A Conventional Commit subject looks likefeat(api): add order listing endpoint: a type, an optional scope in parentheses, an optional ! meaning “breaking”, a colon, a space and a description. A BREAKING CHANGE: footer in the body also marks a breaking change. Squash-merged pull requests often end in the pull request number as (#12), which is worth keeping.
private static final Pattern HEADER =
Pattern.compile("^(?<type>[A-Za-z]+)(\\((?<scope>[^)]+)\\))?(?<bang>!)?: (?<desc>.+)$");
private static final Pattern PR_SUFFIX = Pattern.compile("\\s\\(#(\\d+)\\)$");
private static final Pattern BREAKING_FOOTER =
Pattern.compile("(?m)^BREAKING[ -]CHANGE: (.+(?:\\n(?!\\n|[A-Za-z-]+: ).+)*)");
private static final Pattern REVERT = Pattern.compile("^Revert \"(.+)\"$");
The patterns are in ConventionalCommit.java. The interesting design question is not the regular expression but what to do with commits that do not match, because in a real repository many will not. The rule here is that nothing is ever dropped: a commit that is not conventional gets type other and appears in the notes under “Other changes”. Here is what the parser does with eleven messages, good and bad, from output/01-commit-parsing.txt:
subject type scope breaking PR conventional
feat(api): add order listing endpoint (#1) feat api false 1 true
fix: stop retrying on 4xx fix null false null true
Feat(UI): Capital letters are tolerated feat UI false null true
refactor(core)!: rename Order.id to Order.orderId refactor core true null true
chore: bump deps chore null true null true
feat!: drop the v1 API feat null true null true
Revert "feat(cli): add --json output flag" revert null false null true
Fixed stuff other null false null false
wip: half done other null false null false
feat add a thing without a colon other null false null false
feat(api):no space after the colon other null false null false
Four results are worth reading twice. Feat(UI) with capital letters is accepted, because people type it. wip: half done looks conventional but wip is not a type this generator knows, so it falls into other rather than inventing a “Wip” section. A missing space after the colon (feat(api):no space) is rejected, as the specification requires. And a breaking change declared in the footer of a chore commit still counts as breaking; the footer text itself becomes the note shown to readers.
breaking note from footer: the minimum JDK is now 21, update your CI.
“We do not use Conventional Commits” is the common case, not an edge case. In the fixture history, 2 of 10 commits land in other, and that is a tidy repository. If most of yours do, this pipeline still runs and still lists every commit, but the grouping and the version bump stop meaning much, and the honest options are to enforce the format with a commit-msg hook or a PR-title check, or to accept a flat list. Do not ask the model to guess the type of each commit: it turns a deterministic stage into a probabilistic one for the sake of a prettier heading.
Intermediate: reverts, footers and the PR suffix
A Git-generated revert has the subject Revert "feat(cli): add --json output flag", which is not a Conventional Commit header at all. The parser recognises it separately, gives it type revert and keeps the original subject as the description; the notes print it as “Revert: feat(cli): add –json output flag”. It does not cancel the original feature in the list. Working out that a revert and the commit it reverts annul each other needs the reverted hash from the body (This reverts commit ...) and a decision about commits that were reverted in an earlier release, so this module lists both and leaves that to a human.
The footer pattern accepts both BREAKING CHANGE: and BREAKING-CHANGE: and continues over wrapped lines until a blank line or the next footer, which is why the transcript shows “the minimum JDK is now 21, update your CI.” joined into one sentence and not cut after the comma.
Going deeper
- The specification, section by section
- ReleaseNotesTest.java —
parsesConventionalCommitswrites the table above and asserts its key rows
Group the commits, order them, and let the commits decide the version
Grouping is a map from type to commits in a fixed order, with breaking changes also collected into their own list so they can be printed first. The version bump falls out of the same data, using the Semantic Versioning rule: any breaking change means a major bump, otherwise anyfeat means minor, otherwise any fix or perf means patch, otherwise nothing worth releasing.
private static SemVer.Bump bumpFor(Map<String, List<CommitInfo>> byType, List<CommitInfo> breaking) {
if (!breaking.isEmpty()) return SemVer.Bump.MAJOR;
if (byType.containsKey("feat")) return SemVer.Bump.MINOR;
if (byType.containsKey("fix") || byType.containsKey("perf")) return SemVer.Bump.PATCH;
return SemVer.Bump.NONE;
}
From ReleaseModel.java. Running it on the ten commits between the two tags gives this grouped output, with the date taken from the last commit and every commit and PR link built from a base URL you pass in (output/03-grouped-release-notes.txt):
group sizes: feat=2, fix=1, perf=1, revert=1, docs=2, refactor=1, other=2
not in conventional form (type other): 2 of 10
bump implied by the commits: MAJOR, current 1.0.0 -> next 2.0.0
## v1.1.0 (2026-01-20)
This release contains 10 commits: 2 features and 1 bug fix. 1 breaking change is listed first.
### Breaking changes
- Order.getId() is now Order.getOrderId(), update every caller. ([a061359](https://git.example/acme/shop/commit/a061359aeddbe07c20c074b3fa1f909575076a49))
### Features
- **cli:** add --json output flag ([#3](https://git.example/acme/shop/pulls/3), [6e9776a](https://git.example/acme/shop/commit/6e9776a52f5a1cff3f185922acc3b5b311a2e24c))
- **search:** add fuzzy search ([#6](https://git.example/acme/shop/pulls/6), [92049cc](https://git.example/acme/shop/commit/92049cc1cace8c099d1e230ac7345e515060c3e0))
Note the first line of the transcript: the implied bump is MAJOR and the next version after 1.0.0 would be 2.0.0, because one refactor commit carries ! and a BREAKING CHANGE: footer. A refactor would normally not touch the version at all, which is a good reason for computing the bump from the breaking flag, not from the type alone. The release was tagged v1.1.0 in the fixture; the tool would have told you that was wrong.
A condition on that advice. This is the plain Semantic Versioning rule. Many projects treat a 0.x version differently (breaking changes bump the minor number), and some teams cap what a commit message is allowed to decide. If you adopt the bump, compare it against the tag a human intended for a few releases before letting a job tag automatically.
Intermediate: what the rendered Markdown leaves out on purpose
refactor, test, build, ci, chore and style commits are counted in the final line (“1 internal change … not listed”) instead of being listed. That is a reading-experience choice, not a rule: the types are in the INTERNAL list in ReleaseNotes.java. The same file builds the fallback sentence (“This release contains 10 commits: 2 features and 1 bug fix.”) used when the model is skipped or rejected, which is the next section’s subject.
Going deeper
- ReleaseModel.java and SemVer.java
- output/03-grouped-release-notes.txt — the complete notes, including the sections cut from the block above
Ask the model for one paragraph, then check it against the commit list
Now the one model call. With Spring AI,ChatClient.create(model) wraps any ChatModel, and the whole call is a system message, a user message and .call().content(). The user message is built by code as a closed list: one line per commit with its short hash, type, description and PR number. The system message says to use only that list, to write at most three sentences and to use no headings.
Instructions to a model are a request, not a guarantee, so the answer is checked before it is used. The guard in Highlights.java rejects an answer that is empty, longer than 600 characters, contains a markdown heading, or mentions a #NNN number or a seven-character hex hash that is not in the list it was given:
public static Optional<String> check(String answer, List<CommitInfo> commits) {
if (answer == null || answer.isBlank()) return Optional.of("empty answer");
if (answer.length() > MAX_CHARS) return Optional.of("longer than " + MAX_CHARS + " characters");
if (answer.lines().anyMatch(l -> l.startsWith("#") && l.length() > 1 && l.charAt(1) == ' ' || l.startsWith("##"))) {
return Optional.of("contains a markdown heading");
}
Set<String> prs = new HashSet<>();
Set<String> shas = new HashSet<>();
for (CommitInfo c : commits) {
shas.add(c.shortSha());
if (c.parsed().prNumber() != null) prs.add(String.valueOf(c.parsed().prNumber()));
}
Matcher m = PR.matcher(answer);
while (m.find()) {
if (!prs.contains(m.group(1))) return Optional.of("cites #" + m.group(1) + ", which is not in the commit list");
}
m = HASH.matcher(answer);
while (m.find()) {
if (!shas.contains(m.group())) return Optional.of("cites " + m.group() + ", which is not in the commit list");
}
return Optional.empty();
}
When the check fails, the caller does not retry and does not repair the text. It substitutes a sentence built from counts (see fallbackHighlights). Here is the exact text the stub receives, then the stub’s honest answer, then three bad answers the stub was told to produce, each rejected for a different reason. The file is output/04-model-guard.txt:
--- what the model receives ---
[SYSTEM]
You write the opening paragraph of release notes for developers.
Use only the commits in the list. Do not invent pull request numbers or commit hashes.
Write at most three sentences of plain prose: no headings, no bullet lists.
[USER]
Release v1.1.0. Commits:
- 6e9776a feat(cli): add --json output flag (#3)
- 6ba3519 fix: stop retrying on 4xx
- 4ab0a75 docs: explain retry policy
- 0082b4d other: Fixed stuff
- a061359 refactor(core): rename Order.id to Order.orderId [BREAKING]
- 2ff8458 perf(db): batch inserts in OrderRepository (#5)
- 633f424 other: wip: half done
- 92049cc feat(search): add fuzzy search (#6)
- 08cccc3 docs: document back-off
- dedef67 revert: feat(cli): add --json output flag
The same transcript continues with the stub’s answers, one per mode:
HONEST -> from model: true text: This stub counts 2 features and 1 fix; the first feature is "add --json output flag (#3)" (6e9776a).
INVENT_REFERENCES -> from model: false rejected because: cites #999, which is not in the commit list
shipped text: This release contains 10 commits: 2 features and 1 bug fix. 1 breaking change is listed first.
WRITE_HEADING -> from model: false rejected because: contains a markdown heading
shipped text: This release contains 10 commits: 2 features and 1 bug fix. 1 breaking change is listed first.
RAMBLE -> from model: false rejected because: longer than 600 characters
shipped text: This release contains 10 commits: 2 features and 1 bug fix. 1 breaking change is listed first.
The three rejection reasons come from the stub’s three misbehaving modes: it appends a claim that it closes #999 and fixes a regression from deadbee, neither of which is in the commit list, or it starts with a ## Highlights heading, or it repeats itself twelve times. In each case the shipped text is the code-built sentence, and the notes below it are unchanged, since the model never touched them. That separation is the whole point: the worst a bad model answer can do is cost you one nice paragraph.
What this guard does not prove. It checks references, length and shape. It cannot tell whether “the first feature is X” is a fair summary, and a model that quotes real hashes and real PR numbers can still say something misleading about them. Treat the paragraph as a draft a person reads before publishing, or have the job create the release as a draft (the Gitea client below takes a draft flag). And since no real model was called, nobody has measured how often a real one trips the guard; that is the first thing to measure when you swap one in.
Intermediate: why the model is not asked for the whole document
A design that asks the model for the whole document needs far more of the commit data in the prompt, it has to be allowed to write the lines that carry hashes and links, and its output can no longer be compared with anything: you cannot assert that the model’s list contains each commit exactly once without parsing Markdown the model chose the shape of. Asking for a paragraph keeps the prompt to one line per commit, and the guard is a handful of lines. The cost of the change is that the notes read as a generated list plus a human-sounding opening, not as flowing prose, which for release notes is usually what readers want anyway.
The same Highlights.java is reused for the pull request summary below, with the diff appended to the user message.
Going deeper
- Spring AI ChatClient reference
- Structured Output in Spring AI 2.0 — the other way to constrain a model answer, with schema validation and retries
- Prompt Caching in Spring AI — relevant once the system message is long and repeated on every call
- StubChatModel.java — the stand-in, with its four modes
A pull request description needs a diff, and a diff needs a budget
For a release, the commit subjects are enough. For a pull request description the reviewer also wants to know which files changed and how much, and the model benefits from seeing the change. That is where cost appears: a lock file or a generated file can be larger than everything else in the branch put together. Two decisions in PrDescription.java and DiffBudget.java deal with it. First, which diff: a pull request shows the changes on the branch since it left the base, not the difference between the two branch tips.main gained a commit after the feature branch was cut. The merge base is the last commit both branches share, and a pull request’s diff starts there. Compare the two tips directly and the later README change on main shows up as if the branch had made it. The test builds exactly this situation and records both answers (output/05-pull-request-description.txt):
files in the PR by merge-base diff (what Gitea shows): [package-lock.json, src/Export.java]
files by comparing the two branch tips (merge base forgotten): [README.md, package-lock.json, src/Export.java]
Second, how much of it the model sees. DiffBudget cuts each file’s patch at 1,500 characters, stops adding patches after 6,000 characters in total, and lists lock files, minified assets and images by name only. In the fixture the branch adds a 152-line Export.java and a lock file of roughly 5,000 characters:
prompt size with the default budget: 1739 characters; with no budget: 11076
budget: included=1 truncated=1 names-only=[package-lock.json]
title: Add CSV export (+2 more)
The default budget sends 1,739 characters to the model against 11,076 with no budget. The lock file is named but not shown, and the one large source file is cut. The characters are a proxy: they are not tokens, and tokens depend on the tokenizer of whichever model you use, so I am deliberately not converting them into a price.
The rest of the description is assembled by code: a breaking-changes section when there are any, a list of commits with their type, a table of files with lines added and deleted, and a checklist. The title is the description of the most significant commit (breaking, then feat, then fix), with a count of the others. The summary, the only model-written part, goes through the same guard as the release paragraph. Here is the body the pipeline built, the summary line coming from the stub:
## Summary
This stub counts 1 feature and 1 fix; the first feature is "add CSV export (#7)" (1cbba95).
## Changes
- `feat` add CSV export (1cbba95)
- `fix` escape quotes in CSV (0b05321)
- `chore` update package-lock.json (6454b34)
## Files
| File | Change | + | - |
|---|---|---|---|
| `package-lock.json` | modify | 1 | 1 |
| `src/Export.java` | add | 152 | 0 |
## Checklist
- [ ] Tests pass
- [ ] Docs updated if behaviour changed
Intermediate: the budget code
The whole policy is one short method, which is the reason to write it yourself instead of trusting a model with a large context window to cope:
public Budgeted apply(List<FileDiff> files) {
StringBuilder sb = new StringBuilder();
List<String> namesOnly = new ArrayList<>();
int included = 0, truncated = 0;
for (FileDiff f : files) {
boolean skip = skipSuffixes.stream().anyMatch(f.path()::endsWith);
if (skip || sb.length() >= totalChars) {
namesOnly.add(f.path());
continue;
}
String patch = f.patch();
if (patch.length() > perFileChars) {
patch = patch.substring(0, perFileChars) + "\n[... " + (f.patch().length() - perFileChars) + " more characters cut ...]\n";
truncated++;
}
sb.append(patch).append('\n');
included++;
}
return new Budgeted(sb.toString(), included, truncated, namesOnly);
}From DiffBudget.java. A truncated patch ends with a line saying how many characters were cut, so the model is told the diff is incomplete instead of silently receiving half a file. What this does not do is pick the important part of a long file; it takes the beginning. If your reviewers care about a particular directory, sorting the files before the budget is applied is the place to say so.
Going deeper
- PrDescription.java and DiffBudget.java
- output/05-pull-request-description.txt — the full body
- The code-review bot post — chunks a diff by size for the same cost reason, and applies a different guard (line numbers) to inline comments
Publish to Gitea so a second run edits instead of failing
A job that creates a release will be run twice: a retry after a timeout, a re-tag, a developer running it locally. Creating a release for a tag that already has one, or a pull request for a branch that already has one, fails with a conflict. So the client looks first and chooses between create and update. public Outcome upsertRelease(String tag, String name, String body, boolean draft, boolean prerelease, String targetCommitish) {
Response existing = send("GET", "/repos/" + repo + "/releases/tags/" + enc(tag), null);
Map<String, Object> payload = new LinkedHashMap<>();
payload.put("tag_name", tag);
payload.put("name", name);
payload.put("body", body);
payload.put("draft", draft);
payload.put("prerelease", prerelease);
payload.put("target_commitish", targetCommitish);
if (existing.status == 404) {
Response r = expect(send("POST", "/repos/" + repo + "/releases", payload), 201);
return new Outcome("created", r.json.path("id").asLong(), r.json.path("html_url").asString());
}
expect(existing, 200);
long id = existing.json.path("id").asLong();
payload.remove("tag_name"); // an edit that names the tag again is a rename, not what we want
Response r = expect(send("PATCH", "/repos/" + repo + "/releases/" + id, payload), 200);
return new Outcome("updated", id, r.json.path("html_url").asString());
}
From GiteaClient.java. The release is looked up by tag with GET /repos/{owner}/{repo}/releases/tags/{tag}, created with POST /repos/{owner}/{repo}/releases if that is a 404, otherwise edited with PATCH /repos/{owner}/{repo}/releases/{id}. The edit leaves tag_name out as a precaution: the code comment says naming it again would be a rename, and although the swagger edit option does accept tag_name, I did not test what a real server does with it. All three endpoints and their field names are in the swagger document at /git.app/api/swagger of the server this blog’s repositories live on (Gitea 1.27.3). A pull request is handled the same way, finding an existing one among the open pull requests by base and head branch. I used the list endpoint instead of GET /pulls/{base}/{head} because a branch such as feature/csv-export has a slash in it, and the swagger document does not say how that path segment is routed.
To run this for real without writing to a real repository, the tests start FakeGitea, a small server from FakeGitea.java that answers these endpoints with the status codes from the swagger document and records every request. It is not Gitea; it proves that the client sends the sequence of calls it should and handles 404, 200, 201 and 401, not that a real server agrees. The run, from output/06-gitea-publish.txt:
release run 1: created id=100
release run 2: updated id=100 body now: notes, take two
pull request run 1: created #11
pull request run 2: updated #11 title now: Add CSV export (+2 more)
wrong token: Gitea answered 401: {"message":"token is required"}
requests the server saw:
GET /repos/acme/shop/releases/tags/v1.1.0 -> 404
POST /repos/acme/shop/releases -> 201 fields=[tag_name, name, body, draft, prerelease, target_commitish]
GET /repos/acme/shop/releases/tags/v1.1.0 -> 200
PATCH /repos/acme/shop/releases/100 -> 200 fields=[name, body, draft, prerelease, target_commitish]
GET /repos/acme/shop/pulls?state=open&limit=50&page=1 -> 200
POST /repos/acme/shop/pulls -> 201 fields=[base, head, title, body]
GET /repos/acme/shop/pulls?state=open&limit=50&page=1 -> 200
PATCH /repos/acme/shop/pulls/11 -> 201 fields=[body, title]
GET /repos/acme/shop/releases/tags/v9.9.9 -> 401
Run 2 of the release is a GET that now finds it, followed by a PATCH to the same id, and the pull request run also ends in an update of #11 with the new title. The PATCH of a pull request answers 201, not 200, which looks like a typo but is what the swagger document lists for that operation, so the client accepts both. The wrong-token call surfaces Gitea’s 401 body as an exception message; the token itself never appears in it.
Check the repository settings before you debug your code. An unauthenticated read-only request to the repository API on ankurm.com for the repository this module lives in returns"has_pull_requests": falseand"has_releases": false, and the/pullsand/releasesendpoints answer 404 and 403. Pull requests and releases are per-repository features in Gitea, so on a repository where they are switched off, this client would fail with a plain “Gitea answered 404”, which reads like a bug in the code. Turn the features on under the repository settings before pointing the job at it. I did not verify what a real Gitea does with the release and pull request calls on a repository where they are enabled, because that would write to a real repository; that part rests on the swagger document and the fake.
Intermediate: the request fields and status codes the client relies on
| Call | Fields sent | Success status |
|---|---|---|
GET /repos/{o}/{r}/releases/tags/{tag} | none | 200, or 404 when there is no release |
POST /repos/{o}/{r}/releases | tag_name, name, body, draft, prerelease, target_commitish | 201 |
PATCH /repos/{o}/{r}/releases/{id} | the same, without tag_name | 200 |
GET /repos/{o}/{r}/pulls?state=open&limit=50&page=N | none | 200, repeated until an empty page |
POST /repos/{o}/{r}/pulls | base, head, title, body | 201 |
PATCH /repos/{o}/{r}/pulls/{index} | title, body | 201 per swagger, 200 also accepted |
Authentication is the header Authorization: token <your token> on every call. The fake server enforces it, which is how the 401 line in the transcript is produced. The client stops looking for an existing pull request after 20 pages of 50, a limit you would raise for a very busy repository.
Going deeper
- GiteaClient.java and FakeGitea.java
- The Gitea swagger document on this server — the source for every endpoint and field above
Swapping the stub for a real model
Everything model-specific sits behind one constructor argument.Highlights and PrDescription take a Spring AI ChatModel; the tests pass StubChatModel, and your application would pass the Anthropic, OpenAI or Ollama model that Spring AI auto-configures from your properties. The command-line entry point, ReleaseNotesApp.java, shows the wiring on a real repository, and output/07-command-line.txt is its output on the fixture:
$ java -cp ... com.ankurm.releasenotes.ReleaseNotesApp <repo> v1.1.0 https://git.example/acme/shop
## v1.1.0 (2026-01-20)
This stub counts 2 features and 1 fix; the first feature is "add --json output flag (#3)" (6e9776a).
When you do swap it in, three things are open questions that this post cannot answer for you, because no real model ran: how often the guard rejects a genuine answer, whether 600 characters is the right cap for your model’s style, and what the calls cost. Log the rejection reason in production. A guard that silently falls back is a guard you will never tune.
Should you build this at all? Parts of it already exist. Tools such as git-cliff and release-please group Conventional Commits into a changelog without any model, and if the model-written paragraph is the only thing you wanted, the honest answer may be that a person writing two sentences is cheaper and better. Building it in Java makes sense when the rest of your tooling is JVM, when you want the PR description and the release notes from the same parsed history, or when you want the checks (budget, guard, idempotent publishing) to be code you can test. If your commit messages are mostly free text, fix that first: no amount of prompting makes a flat history into a structured one.
Going deeper
- Build an AI Code-Review Bot in Java — the webhook-driven sibling, reading diffs and posting inline comments
- ReleaseNotesApp.java
No Comments yet!