Skip to content

Decompose publish_draft_campaign into named steps - #27

Merged
th0rz05 merged 1 commit into
mainfrom
refactor/decompose-publish-flow
Jun 3, 2026
Merged

Decompose publish_draft_campaign into named steps#27
th0rz05 merged 1 commit into
mainfrom
refactor/decompose-publish-flow

Conversation

@th0rz05

@th0rz05 th0rz05 commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

Pure refactor of the LinkedIn publish flow. publish_draft_campaign was a single ~159-line function that nested six distinct concerns inside one try block. It's now a slim orchestrator delegating to focused helpers:

  • _group_budget — pick the campaign-group total budget (explicit lifetime vs. summed line items).
  • _resolve_org_urn — resolve the Company Page URN, only when an ad needs a freshly minted post.
  • _create_group — create + track the Campaign Group.
  • _create_line_items — one Campaign per LineItem, with B2B targeting resolution; returns URNs, unresolved facets, and result rows.
  • _create_ads — one Creative per Ad, minting a dark post where needed.
  • _rollback_and_raise — tear down partial work and re-raise with a summary.

The orchestrator body drops from ~140 lines to ~35 and reads as the sequence of steps it performs.

Behaviour

Unchanged. The _Created rollback tracker and its reverse-dependency-order teardown are preserved exactly — the publish tests pin both the rollback ordering and the dark-post/existing-post branching, and all pass untouched.

Also tidies a stale docstring line (B2B resolution is wired since #25, no longer "a follow-up").

Test plan

  • pytest -q green (43) — including the 5 publish/rollback tests, unchanged
  • ruff check clean on server.py

The publish flow was a single ~159-line function nesting budget selection,
group creation, org-URN resolution, per-line-item campaign creation, per-ad
post/creative creation, and rollback-on-failure. Extract each concern into a
focused helper (_group_budget, _resolve_org_urn, _create_group,
_create_line_items, _create_ads, _rollback_and_raise) so the orchestrator
reads as the sequence of steps it performs.

Behaviour is unchanged — the rollback tracker and reverse-order teardown are
preserved exactly (the publish tests pin both). Pure refactor.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 3, 2026 11:13

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@th0rz05
th0rz05 merged commit c1b9424 into main Jun 3, 2026
@th0rz05
th0rz05 deleted the refactor/decompose-publish-flow branch June 3, 2026 11:13
th0rz05 added a commit that referenced this pull request Jun 9, 2026
The publish flow was a single ~159-line function nesting budget selection,
group creation, org-URN resolution, per-line-item campaign creation, per-ad
post/creative creation, and rollback-on-failure. Extract each concern into a
focused helper (_group_budget, _resolve_org_urn, _create_group,
_create_line_items, _create_ads, _rollback_and_raise) so the orchestrator
reads as the sequence of steps it performs.

Behaviour is unchanged — the rollback tracker and reverse-order teardown are
preserved exactly (the publish tests pin both). Pure refactor.
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.

2 participants