Skip to content

Record each approved bill report in the CRM when its review PR merges - #247

Draft
DTrim99 wants to merge 2 commits into
mainfrom
crm-publication-record
Draft

DTrim99 wants to merge 2 commits into
mainfrom
crm-publication-record

Conversation

@DTrim99

@DTrim99 DTrim99 commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

When a bill-review PR merges, the bill's approved report is now recorded in the CRM (Teamverse p454). This PR is based on #241, which owns publish-bill.yml and the App v3 contract. The CRM side is PolicyEngine/CRM#458.

  • Workflow. publish-bill.yml has a new step after the bill is marked published and main is checked out: Record the report in the CRM, which runs scripts/record_publication.py.

  • Script. record_publication.py reads the research row (and processed_bills.bill_number through legiscan_bill_id) and builds one record:

    • research id, title, state, bill number, session;
    • the App v3 bill page (/us/report/bill/{id}) and the saved report;
    • the review PR;
    • the filed date, approved_at and published_at (the merge time).

    It posts the record to the CRM's POST /api/publications/record with a Bearer token. Fields with no value are left out, so a re-run never blanks what the CRM holds. --dry-run prints the record without sending it.

  • Safety.

    • The step never fails a publish:
      • with the secrets unset it prints a ::notice:: and stops;
      • any error (database, network, 4xx/5xx) is a ::warning::;
      • the script always exits 0, and the step has continue-on-error: true.
    • Inputs reach the script through env only, never through inline ${{ }} in the script.
    • The token is never printed; the tests check this.
  • Docs. docs/APP_V3_BILL_CONTRACT.md gains a "Recorded" lifecycle row and section 5, which maps each CRM field to its source and lists the secrets.

Secrets and variables (not set here)

  • CRM_PUBLICATIONS_URL: the CRM backend's base URL.
  • CRM_PUBLICATIONS_TOKEN: the same value as the CRM backend's PUBLICATIONS_SERVICE_TOKEN.
  • CRM_PUBLICATIONS_PROJECT_ID (optional repository variable): the Teamverse project. The default is p301.

Until the secrets are set, a merge publishes exactly as before, plus one notice line.

Tests

uv run --with pytest pytest scripts/test_record_publication.py scripts/test_publish_analysis.py: 25 passed (17 new). The new tests cover:

  • the record from a full row and from a 2026 row before migration 010;
  • bill numbers derived from research ids;
  • URL joining;
  • skipping when the secrets are unset;
  • the post with the token;
  • warnings on CRM 401 and 503, a network error, a missing row and a database error;
  • CRM warnings shown;
  • dry run.

None of these tests use the network or Supabase. The workflow YAML parses.

🤖 Generated with Claude Code

DTrim99 and others added 2 commits December 3, 2026 12:41
publish-bill.yml now runs scripts/record_publication.py once the bill is
marked published. The script reads the research row and posts one record
to the CRM's POST /api/publications/record (Teamverse p454). The record
holds the bill, session, App v3 bill page and saved report, the PR, and
the filed and approved dates. Fields with no value are left out, so they
never blank what the CRM already holds.

The step can't fail the publish:
- With CRM_PUBLICATIONS_URL or CRM_PUBLICATIONS_TOKEN unset, it prints a
  notice and records nothing.
- Any error is a warning, and the script always exits 0.
- continue-on-error backs that up.

Inputs reach the script through env only. The contract doc gains a CRM
section.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ublication-record

# Conflicts:
#	docs/APP_V3_BILL_CONTRACT.md
@DTrim99
DTrim99 changed the base branch from app-v3-bill-contract to main December 3, 2026 21:12
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.

1 participant