Skip to content

GitHub Repos: new commits on a branch, a fourth type of the repository watch - #742

Merged
pufit merged 3 commits into
mainfrom
pufit/repo-watch-commits
Nov 23, 2026
Merged

pufit merged 3 commits into
mainfrom
pufit/repo-watch-commits

Conversation

@pufit

@pufit pufit commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

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:

sync:
  github_repos:
    enabled: true
    repos: [acme/widgets]
    types: [commit]            # pull_request | issue | release | commit
    branches:                  # optional; no entry: the repository's default branch
      acme/widgets: [main, release/1.2]

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 commit type a cron job needs only the existing messages gate:

run_if:
  - type: messages
    sources: [github_repos]
    consumer: on-new-commits

It stays idle while the branch does not move, and one push starts one run. docs/cron.md has 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.

Member Value
id <owner>/<repo>@<branch>:pushed:<before>..<head>, with the first 12 characters of the head at the last run and of the head
summary [acme/widgets] 3 new commits on main, or [acme/widgets] main moved to 5c4d3e2f1a0b when the watch cannot count them
content Repository:, Type: Commit, Event: pushed, Branch:, Commits:, Head:, Before:, URL:, then one line per listed commit
timestamp the time of the run that found the head moved

The 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.

Metadata key Value
repo_name, repo_url as for the other types
event pushed
subject_type Commit
branch the branch
head_sha the branch's head
before_sha its head at the last run
commit_count the number of commits that the branch's listing shows above before_sha; empty when the listing does not show before_sha
commits a list of the newest of them, up to 50, in the listing's order, each <sha> <first line of the message, cut to 120 characters>
truncated true when before_sha is 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_url the comparison of the two heads on GitHub

GitHub lists by commit date, not by ancestry. Across a merge the listing interleaves the commits of the merged branches, so commits and commit_count are 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_bots nor deny_authors judges 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

  • Settings (nerve/config.py). sync.github_repos.types takes commit. sync.github_repos.branches maps a repository of repos to 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, not refs/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 that repos does not list, a branch that is not a string, a branch name that the watch cannot follow or that starts with refs/, a branch named twice, and more than 8. A branch that is not a string is one that YAML read as something else (an unquoted 1.10 is the number 1.1; no, off and 0 are no names), and the message says to quote it. While the watch is off, a warning names them. The setting is read only with the commit type: without it, a value that is left there is ignored with one warning.
  • Poll mode (nerve/sources/github_repos.py). One gh api repos/{repo}/commits?sha=refs/heads/{branch}&per_page=100 per 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.
  • Hosted mode (nerve/channels/hosted/, nerve/sources/github_hosted.py). The subscription that Nerve sends to the channel gateway carries the commit type and, for a repository with an entry, its branches. The gateway then follows the branches and delivers the same record, which the hosted source reads with commits as a list and truncated as a flag.
  • Web UI. The Sources page shows the branch of a commit record next to its repository and each commit on its own line. In the metadata header, 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, of any source, are shown in full, as before.
  • Docs. 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) and config.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:

  • An agent that does not name commit sends the very same subscription as before, byte for byte, whatever its branches setting 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.
  • An agent names commit in 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 or commit is taken out of types. docs/sources.md and config.example.yaml say 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

Command Result
pytest tests/test_github_repos_source.py tests/test_hosted_sources.py tests/test_channel_contract.py tests/test_onboarding_environment.py 480 passed
pytest tests/, in four shards, after the merge of main 10912 passed, 38 skipped
npx vitest run src/utils/sourceMetadata.test.ts src/components/Sources/renderers/GitHubRenderer.test.tsx (in web/) 7 passed
npx tsc -b (in web/) clean

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 commit type. 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 the commit type 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: the commits rule, and the lists of other keys in full.

Not covered

  • No test talks to GitHub: poll mode runs against a fake 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.
  • The same move again, between the same two commits, has the ID of the earlier record, so it is not stored a second time and a job that is gated on the watch does not run for it. Only a branch that flips between the same two heads meets this.
  • The first commits of an empty repository are not reported: the first listing with a commit is the branch's baseline.
  • In poll mode a branch that does not exist fails its listing at every run, with a warning, and fails the run when it is the only listing; the hosted gateway rests such a branch for an hour instead.
  • The other web tests and the browser tests were not run; only the tests of the touched files.

🤖 Generated with Claude Code

pufit and others added 2 commits November 21, 2026 12:27
…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 alex-clickhouse left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approved automatically on a review request from pufit. No manual code review was done.

@nerveai

nerveai commented Nov 21, 2026 •

Copy link
Copy Markdown

Nerve PR review · ✅ Ready to merge

Updated for 5c92227: a merge of main (#736). The one conflict, in nerve/sources/github_hosted.py, keeps both sides' list and flag keys. The commit sample moved to inbox 1022, and two new tests pin the frame with and without the thread-items entry. Verdict unchanged.

Adds a commit type to the repository watch: one record per branch and run when the head moves. A cron job can then start on new commits through the existing messages gate instead of polling on a timer. It reuses the existing source, record type, cursor and failure rule, and the hosted record matches the poll one through the contract fixture. Agents that don't name commit send a byte-identical frame, pinned by a test.

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:

  • Release order: repo_watch_types (nerve/channels/hosted/sources.py:228) sends commit as soon as it is named, and an older gateway then closes the whole stream, Slack included, on every reconnect. Ship the gateway first.
  • commit_count comes from a date-ordered listing (nerve/sources/github_repos.py:682), so a merged branch with older commits is undercounted. compare/{before}...{head} would be exact. Decide before the gateway contract settles.

Checked: full suite in an offline sandbox at 5c92227 (3 chunks): 10897 passed, 39 skipped; test_slack_integration.py excluded (hangs offline on main too); web unchanged since e052ed1 (build + 2811 vitest passed offline then); CI green; read the merge resolution in hosted sources, contract and reader · automated review by nerveai — mention @nerveai to ask a follow-up.

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 alex-clickhouse left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approved automatically on a review request from pufit. No manual code review was done.

@pufit
pufit merged commit c185208 into main Nov 23, 2026
6 checks passed
@pufit
pufit deleted the pufit/repo-watch-commits branch November 23, 2026 03:26
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.

3 participants