Add GitHub PR to Launchpad MP comment mirroring tool #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Implements a Temporal workflow that mirrors GitHub PR comments (issue + review comments) to Launchpad Merge Proposals with fingerprint-based deduplication for idempotency.
Architecture
Database Layer
MirroredCommentmodel with SHA256 fingerprint for deduplicationd4f9a1b2c3e5addsmirrored_commenttable with unique constraint on fingerprintMirroredCommentsRepositoryfor persistence and duplicate detectionWorkflow
MirrorPullRequestCommentsWorkfloworchestrates 5 activities:parse_input- validates URLs, extracts identifiersfetch_github_comments- retrieves issue/review comments via GitHub APIfilter_deduplicate- queries DB for existing fingerprintspost_launchpad_comments- posts to MP via launchpadlibrecord_sync- persists metadata and statusAPI
POST /v1/tools/mirror-pr-commentsendpoint (authenticated)include_outdated(review comments),include_review_states(approval summaries)GitHub Integration
UnifiedCommentdataclassLaunchpad Integration
[File: path/to/file.py | Line: 123]Usage
Fingerprinting ensures re-running the workflow skips already-mirrored comments. Requires
GITHUB_TOKENenvironment variable.Original prompt
Overview
Add a new productivity tool that mirrors all open comments from a GitHub Pull Request (issue comments + review comments) onto a specified Launchpad Merge Proposal (MP). This should follow the existing architectural patterns used for the current Temporal-based tool that converts a Launchpad Merge Proposal into a GitHub Pull Request.
Objectives
github_pr_urllaunchpad_mp_urlinclude_outdated(bool),include_review_states(bool)MirrorPullRequestCommentsWorkflow) that:launchpadlib.Technical Requirements
Workflow & Activities
Create
MirrorPullRequestCommentsWorkflowwith activities:parse_input– validate and extract owner, repo, PR number, and MP identifier.fetch_github_comments– uses GitHub REST API to collect issue and review comments.filter_deduplicate– checks stored fingerprints in DB and returns only new comments.post_launchpad_comments– posts comments to Launchpad MP usinglaunchpadlib.record_sync– stores summary and mirrored comment records (status posted/skipped/error).Retry policies: Use Temporal default with exponential backoff for network-bound activities. Ensure activities have reasonable
start_to_close_timeoutvalues.Data Model
Add SQLAlchemy model
MirroredCommentwith columns:id(PK)fingerprint(unique; sha256 of"{source}:{comment_id}:{body}")github_comment_idgithub_source(issue|review)mp_identifier(string, e.g.,project:merge_number)created_atposted_atstatus(pending|posted|skipped|error)error_message(nullable)Create Alembic migration to add the
mirrored_commentstable and index/unique constraint onfingerprint.GitHub Integration
Use environment variable
GITHUB_TOKEN. Endpoints:GET /repos/{owner}/{repo}/issues/{number}/commentsGET /repos/{owner}/{repo}/pulls/{number}/commentsNormalize into unified dataclass
UnifiedComment(fields: source, id, author_login, body, created_at, path, line, fingerprint).Optionally (if
include_review_states), also capture review events (GET /repos/{owner}/{repo}/pulls/{number}/reviews) and post a summary comment (e.g., "Review by X: APPROVED" or "CHANGES_REQUESTED") to Launchpad. This can be done by treating review state summaries as pseudo-comments with distinct fingerprint formatreview_state:{review_id}:{state}.Launchpad Integration
Reuse existing Launchpad authentication pattern from the current tool. Implement a helper service (e.g.,
services/launchpad_comments.py) with function to post a textual comment to the Merge Proposal. Prefix review comments with file/line context if available, e.g.:[File: path/to/file.py | Line: 123]\nOriginal review comment body...API Endpoint
Add FastAPI route:
POST /tools/mirror-pr-commentsBody JSON schema:
{ "github_pr_url": "https://github.com/owner/repo/pull/123", "launchpad_mp_url": "https://code.launchpad.net/~owner/project/+merge/456", "include_outdated": false, "include_review_states": false }Response:
{ "workflow_id": "mirror-pr-comments-<hash>", "status": "started" }Idempotency & Deduplication
Fingerprints ensure no duplicate posting. Before posting, query DB for existing fingerprints for the same
mp_identifier. Skip those already present. Record skipped counts.Observability
Log structured entries per activity including
workflow_id, counts, and partial (truncated) comment bodies (first 80 chars). Provide final summary metrics via logs. (Optional future enhancement: integrate with metrics system if one exists.)Error Handling
error; continue with others.Configuration
Add any new env vars to documentation (
DEVELOPMENT.md):GITHUB_TOKEN. Confirm Launchpad credentials already documented; extend if needed.Testing
Add unit tests:
This pull request was created as a result of the following prompt from Copilot chat.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.