Repository navigation
GitHub Repos: new commits on a branch, a fourth type of the repository watch - #742
Conversation
…y watch The repository watch reported new pull requests, issues and releases. A job that should start when a branch moves, such as a build or a test run, had to run on a timer and look for itself. sync.github_repos.types now takes commit. The watch then follows the branches that sync.github_repos.branches names for a repository, or the repository's default branch. It stores the head of a branch at its first run. From then on a run that finds another head reports one record for the branch, with the commits that the branch's listing shows before the earlier head, however many they are: one record per branch and run, never one per commit. A cron job gated on the source's unread records with the existing messages gate so runs when there are new commits and stays idle otherwise; docs/cron.md has the example. The record keeps the type github_repo_activity, with the event pushed and the subject type Commit. Its metadata names the branch, its head, the head before, the number of new commits, up to 50 of them as a list, and truncated, which is true when the list does not hold exactly the new commits: more than 50, more than the 100 that the listing shows, or a push that rewrote the branch. It has no author, so include_bots and deny_authors do not judge it. In poll mode the source lists the commits of each branch with gh api and keeps the heads in its cursor. In hosted mode the subscription carries the commit type and the branches, and the channel gateway delivers the same record; the contract's sample of it is pinned, and the source in poll mode builds that very record from the same listing. The gateway announces nothing about the types it knows, and one that does not know commit refuses the subscription and closes the stream. So an agent that does not name commit sends the very bytes it sent before, whatever its branches setting says, and the docs say that a hosted agent names commit only once its gateway knows the type. The types that are sent are chosen in one function. The Sources page shows the branch of a commit record, each commit on its own line, and a long metadata list as its length. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… record's ID names both heads
Changes to the commit type of the repository watch.
The listing of a branch is asked for refs/heads/<branch>. For a bare name
GitHub also lists a tag or a commit of that name, so a setting such as
branches: {acme/widgets: [v1.2.0]} could follow a tag. Now it follows the
branch of that name alone. A name that starts with refs/ refuses to load,
so main and refs/heads/main cannot both be followed, and the contract
model refuses the same.
The ID of a commit record names both ends of the move,
<repo>@<branch>:pushed:<before>..<head> with the first 12 characters of
each commit. With the head alone, a branch that returned to an earlier
head had the ID of the earlier record of that head, so it gave no record
of its own.
A commit's line has a space in the place of the line and the paragraph
separator and of each bidirectional control, as for control characters.
sync.github_repos.branches refuses an entry that is not a string, and the
message says to quote it: YAML reads an unquoted 1.10 as the number 1.1,
and the setting dropped no, off and 0 without a word. The setting is
checked only with the commit type, as the docs said: without it, a value
that is left there is ignored with one warning.
The docs say what the list of a commit record is: the commits of GitHub's
listing above the earlier head, in the listing's order, which is by
commit date and not by ancestry. Across a merge the list and the count
are not always the exact set of the new commits, and subject_url, the
comparison, is. truncated is true when the earlier head is not among the
listed commits, after 100 or more new commits or a rewritten branch, or
when the record lists fewer commits than it counts. The docs also list
everything in branches that refuses to load.
On the Sources page, only the commits of a commit record are shown as
their number when they are too long for a chip. The lists of every other
key are shown in full, as before the commit type.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
alex-clickhouse
left a comment
There was a problem hiding this comment.
Approved automatically on a review request from pufit. No manual code review was done.
|
Nerve PR review · ✅ Ready to merge Updated for 5c92227: a merge of main (#736). The one conflict, in Adds a Completeness: tests cover baseline, move, truncation, merge, default-branch change, a same-named tag, failures, config refusals and the hosted frame. Docs, example and web renderer are updated. No migration. Textual overlap with #679 in the hosted contract and sources: whichever lands second rebases. Worth considering:
Checked: full suite in an offline sandbox at |
Main gained the records of thread items in hosted mode (#736): one record for each comment, review and description of a thread, a subscription entry that says that Nerve accepts them, and sync.github.thread_items. This branch adds the commit type of the repository watch. Both change the hosted GitHub source. One file conflicted, nerve/sources/github_hosted.py: each side added to the keys whose values are lists and to those that are flags. Both additions stay: commits is a list, and truncated and mentions_agent are flags. The copy of the contract's sample of the new commits of a branch has another inbox identity, 1022, since the sample of a thread item that main brought has 1021, which the commit sample had. Its pinned digest follows. Tests for the two additions together. One frame holds the thread item entry and a watch that asks for commits, each as it is alone, and the watch of an agent that does not ask for commits is the same bytes with and without the entry. Both samples go through the hosted reader, and each source's guardrail judges its own record whatever the other's settings say. The stream test of the commit record finds the watch after the thread item entry. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
alex-clickhouse
left a comment
There was a problem hiding this comment.
Approved automatically on a review request from pufit. No manual code review was done.
What
The repository watch (
sync.github_repos) reports new pull requests, issues and releases of the repositories it names. It can now also report the new commits on a branch:The watch stores the head of each branch at its first run. From then on, a run that finds another head reports one record for the branch, with the commits that arrived, however many they are and however long after the last run. It is one record per branch and run, never one per commit.
Why
Some work should start when a branch moves: a build, a test run, anything that follows the code. Until now such a job had to run on a timer and look for itself. With the
committype a cron job needs only the existingmessagesgate:It stays idle while the branch does not move, and one push starts one run.
docs/cron.mdhas the full example.The record
The record type stays
github_repo_activity, and the record is the same in poll mode and in hosted mode.id<owner>/<repo>@<branch>:pushed:<before>..<head>, with the first 12 characters of the head at the last run and of the headsummary[acme/widgets] 3 new commits on main, or[acme/widgets] main moved to 5c4d3e2f1a0bwhen the watch cannot count themcontentRepository:,Type: Commit,Event: pushed,Branch:,Commits:,Head:,Before:,URL:, then one line per listed committimestampThe ID names both heads, so a branch that returns to an earlier head, as after a push that was taken back, gives a record of its own.
repo_name,repo_urleventpushedsubject_typeCommitbranchhead_shabefore_shacommit_countbefore_sha; empty when the listing does not showbefore_shacommits<sha> <first line of the message, cut to 120 characters>truncatedtruewhenbefore_shais not among the listed commits (100 or more new commits, or a push that rewrote the branch), or when the record lists fewer commits than it counts (more than 50)subject_urlGitHub lists by commit date, not by ancestry. Across a merge the listing interleaves the commits of the merged branches, so
commitsandcommit_countare not always the exact set of the new commits;subject_url, the comparison, is. The docs say so.A commit record has no author: one push can hold commits of many authors, so neither
include_botsnordeny_authorsjudges it. The first line of a message has a space in the place of each control character, of the line and paragraph separators, and of each bidirectional embedding, override and isolate control (U+202A to U+202E, U+2066 to U+2069).What changes
nerve/config.py).sync.github_repos.typestakescommit.sync.github_repos.branchesmaps a repository ofreposto its branches, at most 8 each; a repository without an entry follows its default branch. An entry is a branch's name, not a ref:main, notrefs/heads/main. While the watch is on, these refuse to load, as the other settings of the watch do: a value that is no such map (branches: [main],branches: []), a repository thatreposdoes not list, a branch that is not a string, a branch name that the watch cannot follow or that starts withrefs/, a branch named twice, and more than 8. A branch that is not a string is one that YAML read as something else (an unquoted1.10is the number1.1;no,offand0are no names), and the message says to quote it. While the watch is off, a warning names them. The setting is read only with thecommittype: without it, a value that is left there is ignored with one warning.nerve/sources/github_repos.py). Onegh api repos/{repo}/commits?sha=refs/heads/{branch}&per_page=100per branch and run; for the default branch,gh api repos/{repo}names it first. The request names the branch's ref, so a tag or a commit that has the same name is never read in its place. The cursor keeps the head of each branch. A branch that cannot be listed fails its listing alone and keeps its head, like every listing of this source.nerve/channels/hosted/,nerve/sources/github_hosted.py). The subscription that Nerve sends to the channel gateway carries thecommittype and, for a repository with an entry, itsbranches. The gateway then follows the branches and delivers the same record, which the hosted source reads withcommitsas a list andtruncatedas a flag.commitsof a commit record are shown as their number when they are too long for a chip; the lists of every other key, of any source, are shown in full, as before.docs/sources.md("New commits on a branch", the settings, what refuses to load, the events and the hosted notes),docs/config.md,docs/cron.md(a job gated on new commits) andconfig.example.yaml.Hosted mode and gateways that do not know the type
Nerve cannot ask the channel gateway which types it knows: the gateway announces nothing about them, and it refuses a subscription that names a type or a member it does not know by closing the stream. This is the same rule that already holds for the repository watch itself (see "Hosted repository watch" in
docs/sources.md).So this change keeps two things:
commitsends the very same subscription as before, byte for byte, whatever itsbranchessetting says. A test pins the frame. This holds next to the entry for thread items that main gained (Hosted GitHub: accept one record for each comment, review and description of a thread #736): the entry and the commit type do not touch each other, and a second test pins the frame with and without each.commitin hosted mode only once its gateway knows the type. Against an older gateway the stream is refused each time the agent connects, hosted chat traffic included, until the gateway is updated orcommitis taken out oftypes.docs/sources.mdandconfig.example.yamlsay so.The types that are sent are chosen in one function,
repo_watch_types.The merge of main
Main gained the records of thread items in hosted mode (#736) while this branch was open, and the branch now holds a merge of it. One file conflicted,
nerve/sources/github_hosted.py, where each side added to the metadata keys that are lists and flags; both additions stay. The copy of the contract's sample of a commit record has another inbox identity (1022), since the sample of a thread item has the one it had, and its pinned digest follows. New tests cover the two additions together: the frame, and both samples through the hosted reader with each source's guardrail.Tests
pytest tests/test_github_repos_source.py tests/test_hosted_sources.py tests/test_channel_contract.py tests/test_onboarding_environment.pypytest tests/, in four shards, after the merge of mainnpx vitest run src/utils/sourceMetadata.test.ts src/components/Sources/renderers/GitHubRenderer.test.tsx(inweb/)npx tsc -b(inweb/)Cases. Poll mode: the first listing of a branch stores its head; a moved head gives one record with the exact fields above; the record equals the channel contract's sample for the same listing, which the hosted source reads into the same record; 50 and 51 commits, the listing but for the earlier head, as many as the listing and more, and a rewritten branch; a listing after a merge; two branches give two records; a branch added or removed; the default branch and its change; a branch that cannot be listed keeps its head and reports when it is back; a name that is also a tag or a commit is followed as a branch alone; a branch that returns to an earlier head has a record of its own; the rules of a commit's line, with the separators and each of those bidirectional controls; the inbox guardrail keeps commit records only with the
committype. Settings: the mapping, its refusals (a ref, an entry that YAML read as a number, a boolean, a date or nothing, a value that is no map) and its warning while the watch is off; without thecommittype the setting is not read. Hosted mode: the contract model's bounds and its refusal of a ref; the frame is unchanged unless the watch asks for commits; branches that the gateway would refuse are not published; the sample, delivered over a stream, reaches the inbox with its list and its flag. Web: thecommitsrule, and the lists of other keys in full.Not covered
gh api, hosted mode against a fake gateway. One thing was checked against GitHub by hand, with read-only requests:sha=refs/heads/<branch>lists the same commits as the branch's plain name, and the name of a tag or of a missing branch asked for that way is a 404.🤖 Generated with Claude Code