repomatic.github.unsubscribe moduleΒΆ

Unsubscribe from closed, inactive GitHub notification threads.

Processes notification threads in two phases:

  1. REST notification threads: fetches the Issue/PullRequest notification threads last moved before the cutoff via /notifications, resolves each subject in batched GraphQL lookups, and unsubscribes the closed, stale ones via DELETE + PATCH.

  2. GraphQL threadless subscriptions: searches for closed issues/PRs the user is involved in but that lack notification threads, and unsubscribes via the updateSubscription mutation.

Requires the gh CLI to be installed and authenticated with a token that has the notifications scope (classic PAT) or equivalent fine-grained permissions.

repomatic.github.unsubscribe.GRAPHQL_PAGE_SIZE = 25ΒΆ

Per-page count for GraphQL search results.

repomatic.github.unsubscribe.NOTIFICATION_PAGE_SIZE = 50ΒΆ

Per-page count for REST /notifications results.

repomatic.github.unsubscribe.NOTIFICATION_SUBJECT_TYPES = frozenset({'Issue', 'PullRequest'})ΒΆ

Notification subject types to process.

repomatic.github.unsubscribe.SUBJECT_BATCH_SIZE = 50ΒΆ

Subjects looked up per GraphQL round trip.

Looked up one at a time, each thread costs a REST detail call. A batched lookup answers 50 in one request for a single rate-limit point, so a 113-thread pool costs three requests instead of 113.

repomatic.github.unsubscribe.SUBJECT_STATES = {'CLOSED': 'closed', 'MERGED': 'closed', 'OPEN': 'open'}ΒΆ

GraphQL subject states, mapped onto the REST spelling the phase compares.

REST reports a merged pull request as closed, where GraphQL distinguishes MERGED. Collapsing the two here keeps one vocabulary in the caller, and keeps the batched lookup a drop-in for the one-subject REST lookup, _get_thread_details.

repomatic.github.unsubscribe.REPORT_TEMPLATE = 'unsubscribe-report'ΒΆ

The template the report of both phases renders through.

repomatic.github.unsubscribe.SUBJECT_URL_PATTERN = re.compile('/repos/(?P<owner>[^/]+)/(?P<repo>[^/]+)/(?:issues|pulls)/(?P<number>\\d+)$')ΒΆ

Owner, repository and number, read off a notification’s subject URL.

A subject URL is the only handle the notification list gives out. GraphQL addresses the same object by coordinates, and issueOrPullRequest covers both shapes, so the issues/pulls half of the path is read and discarded.

repomatic.github.unsubscribe.UNSUBSCRIBE_WORKFLOW = 'unsubscribe.yaml'ΒΆ

Workflow file the backlog warning links to for a manual run with a higher cap.

The report renders inside that workflow’s own run, so the reader is one click from the Run workflow form the warning tells them to use. Kept equal to the filename repomatic.components.COMPONENTS ships, since a link to a workflow a repository does not have is worse than no link.

class repomatic.github.unsubscribe.DetailRow(action, html_url, number, repo, title, updated_at)[source]ΒΆ

Bases: object

Per-item detail for the markdown report table.

action: ReportActionΒΆ

What the run did to the item.

html_url: strΒΆ

Browser URL of the issue or pull request.

number: int | NoneΒΆ

Issue or pull request number, None when unknown.

repo: strΒΆ

Repository the item belongs to, in owner/name form.

title: strΒΆ

Title of the issue or pull request.

updated_at: datetime | NoneΒΆ

When the item last moved, None when unknown.

class repomatic.github.unsubscribe.PhaseResult(cutoff=None, max_unsubscribes=0, total=0, unsubscribed=0, failed=0, deferred=0, skipped_recent=0, rows=list(), skipped=False, skip_reason='')[source]ΒΆ

Bases: object

Counts and rows one phase accumulates.

cutoff: datetime | None = NoneΒΆ

Inactivity boundary the phase compared against.

max_unsubscribes: int = 0ΒΆ

Most unsubscribes the phase may make.

total: int = 0ΒΆ

Candidates the phase inspected.

unsubscribed: int = 0ΒΆ

Items unsubscribed from, or that a dry run would unsubscribe from.

failed: int = 0ΒΆ

Eligible items whose unsubscribe failed.

deferred: int = 0ΒΆ

Eligible items left for a later run because the cap was reached.

skipped_recent: int = 0ΒΆ

Closed items that moved since the cutoff.

rows: list[DetailRow]ΒΆ

One row per item acted on.

skipped: bool = FalseΒΆ

Whether the phase could not run at all.

skip_reason: str = ''ΒΆ

Why the phase could not run, for the report.

skip(reason, error)[source]ΒΆ

Mark the phase as unable to run, for the reason the report gives.

Parameters:
  • reason (str) – What the report says, one sentence.

  • error (Exception) – The failure behind it, logged rather than reported.

Return type:

None

act(label, make_row, unsubscribe, *, dry_run)[source]ΒΆ

Unsubscribe from one eligible item, unless the cap is reached.

An item past the cap is counted as deferred rather than acted on, so the report can say how much a later run still owes.

Parameters:
  • label (str) – How the log line names the item.

  • make_row (Callable[..., DetailRow]) – Builds the item’s row from the action it records.

  • unsubscribe (Callable[[], bool]) – Performs the unsubscribe, returning its success.

  • dry_run (bool) – Record what would be done without acting.

Return type:

None

class repomatic.github.unsubscribe.Phase1Result(cutoff=None, max_unsubscribes=0, total=0, unsubscribed=0, failed=0, deferred=0, skipped_recent=0, rows=list(), skipped=False, skip_reason='', newest_updated=None, oldest_updated=None, skipped_open=0, skipped_unknown=0)[source]ΒΆ

Bases: PhaseResult

Accumulated counts and details from REST notification phase.

newest_updated: datetime | None = NoneΒΆ

Latest activity among the inspected subjects.

oldest_updated: datetime | None = NoneΒΆ

Earliest activity among the inspected subjects.

skipped_open: int = 0ΒΆ

Subjects still open.

skipped_unknown: int = 0ΒΆ

Subjects whose state or activity could not be read.

class repomatic.github.unsubscribe.Phase2Result(cutoff=None, max_unsubscribes=0, total=0, unsubscribed=0, failed=0, deferred=0, skipped_recent=0, rows=list(), skipped=False, skip_reason='', not_subscribed=0, search_query='')[source]ΒΆ

Bases: PhaseResult

Accumulated counts and details from GraphQL threadless phase.

not_subscribed: int = 0ΒΆ

Search results the user is not subscribed to.

search_query: str = ''ΒΆ

The search the phase ran.

class repomatic.github.unsubscribe.UnsubscribeResult(dry_run=False, months=3, phase1=Phase1Result(), phase2=Phase2Result())[source]ΒΆ

Bases: object

Accumulated results from both unsubscribe phases.

dry_run: bool = FalseΒΆ

Whether the run only reported.

months: int = 3ΒΆ

Inactivity threshold of the run, in months.

phase1: Phase1ResultΒΆ

Results of the REST notification phase.

phase2: Phase2ResultΒΆ

Results of the GraphQL threadless phase.

repomatic.github.unsubscribe.render_report(result, repo_url=None)[source]ΒΆ

Render a markdown report from unsubscribe results.

Pure function that produces the same markdown structure as the downstream unsubscribe.yaml workflow’s $GITHUB_STEP_SUMMARY. The repository is passed in rather than probed, so the renderer stays pure and the caller keeps the one environment lookup.

Parameters:
  • result (UnsubscribeResult) – Structured results from both phases.

  • repo_url (str | None) – Repository the run belongs to, linking the backlog warning to its workflow. Omitted, that warning renders as plain text.

Return type:

str

Returns:

Markdown report string.

repomatic.github.unsubscribe.unsubscribe_threads(months, max_unsubscribes, dry_run)[source]ΒΆ

Unsubscribe from closed, inactive notification threads.

Runs two phases, each behind its own runner:

  1. REST notification threads (_run_rest_phase): fetches notification threads, inspects each subject for closed + stale status, and unsubscribes.

  2. GraphQL threadless subscriptions (_run_graphql_phase): searches for closed issues/PRs the user is involved in and unsubscribes via mutation.

Parameters:
  • months (int) – Inactivity threshold in months.

  • max_unsubscribes (int) – Maximum unsubscribes per phase.

  • dry_run (bool) – If True, report what would be done without acting.

Return type:

UnsubscribeResult

Returns:

Structured results from both phases.