Feedback Workflows
Feedback Workflows
Section titled “Feedback Workflows”Feedback workflows react to events in a repository (like PRs being merged or issues being created) and perform actions in response.
Overview
Section titled “Overview”Unlike core.workflow which synchronizes code, core.feedback triggers actions based on repository events.
core.feedback( name = "notify-on-merge", origin = git.github_trigger(...), destination = git.github_api(...), actions = [...],)Use Cases
Section titled “Use Cases”- Notify internal systems when external PRs are merged
- Create tracking issues when code is synced
- Update labels or milestones automatically
- Post comments on related PRs/issues
- Trigger downstream workflows
GitHub Trigger Origin
Section titled “GitHub Trigger Origin”Listen to GitHub events:
origin = git.github_trigger( url = "https://github.com/org/repo", events = ["pull_request", "push"],)Supported Events
Section titled “Supported Events”| Event | Trigger |
|---|---|
pull_request | PR opened, closed, merged, etc. |
push | Commits pushed to a branch |
issue | Issue opened, closed, etc. |
issue_comment | Comment on issue or PR |
GitHub API Destination
Section titled “GitHub API Destination”Perform actions via the GitHub API:
destination = git.github_api( url = "https://github.com/org/internal-repo",)Custom Actions
Section titled “Custom Actions”Define actions using Starlark functions:
def _notify_internal(ctx): """Notify internal team when external PR is merged.""" for change in ctx.origin.get_changes(): if change.labels.get("merged"): ctx.destination.create_issue( title = "External contribution merged: " + change.ref, body = "PR " + change.ref + " was merged. Please sync.", ) return ctx.success()
core.action( impl = _notify_internal, params = {},)Complete Example
Section titled “Complete Example”# Workflow to notify when external PRs are mergedcore.feedback( name = "notify-on-external-merge",
origin = git.github_trigger( url = "https://github.com/myorg/public-repo", events = ["pull_request"], ),
destination = git.github_api( url = "https://github.com/myorg/internal-repo", ),
actions = [ core.action( impl = _handle_pr_event, params = {}, ), ],)
def _handle_pr_event(ctx): for pr in ctx.origin.get_pull_requests(): if pr.merged: # Create an issue in the internal repo ctx.destination.create_issue( title = "[External] PR merged: " + pr.title, body = """\An external contribution was merged.
**PR**: """ + pr.url + """**Author**: """ + pr.author + """**Description**: """ + pr.body + """
Please run Copybara to import these changes.""", labels = ["external-contribution", "needs-import"], )
ctx.console.info("Created issue for PR: " + pr.number)
return ctx.success()Action Context
Section titled “Action Context”The ctx object provides:
| Property | Description |
|---|---|
ctx.origin | Access to origin events/data |
ctx.destination | API to perform actions |
ctx.console | Logging methods (info, warn, error) |
ctx.success() | Return successful result |
ctx.noop(msg) | Return no-op result |
ctx.error(msg) | Return error result |
Origin Methods
Section titled “Origin Methods”# Get all changes/eventschanges = ctx.origin.get_changes()
# Get pull requestsprs = ctx.origin.get_pull_requests()
# Access event datafor change in changes: ref = change.ref labels = change.labels author = change.authorDestination Methods
Section titled “Destination Methods”# Create an issuectx.destination.create_issue( title = "Issue title", body = "Issue body", labels = ["label1", "label2"], assignees = ["user1"],)
# Add a commentctx.destination.add_comment( number = 123, # Issue or PR number body = "Comment text",)
# Update labelsctx.destination.add_labels( number = 123, labels = ["reviewed"],)Running Feedback Workflows
Section titled “Running Feedback Workflows”# Validatejava -jar copybara.jar validate copy.bara.sky notify-on-external-merge
# Run (typically triggered by webhooks in CI)java -jar copybara.jar feedback copy.bara.sky notify-on-external-mergeWebhook Integration
Section titled “Webhook Integration”Set up a GitHub webhook to trigger the feedback workflow:
- Go to repo Settings → Webhooks
- Add webhook URL pointing to your CI
- Select events (e.g., “Pull requests”)
- CI runs Copybara feedback workflow on webhook
Combining with Sync Workflows
Section titled “Combining with Sync Workflows”A common pattern:
- External contributor opens PR on public repo
- PR gets merged
- Feedback workflow creates internal issue
- Team reviews and approves import
- Sync workflow (
import) runs to bring changes internal
# Feedback: notify on mergecore.feedback( name = "notify-on-merge", origin = git.github_trigger(url = public_url, events = ["pull_request"]), ...)
# Sync: import external contributionscore.workflow( name = "import", origin = git.github_pr_origin(url = public_url, branch = "main"), destination = git.gerrit_destination(url = internal_url, ...), mode = "CHANGE_REQUEST_FROM_SOT", ...)