id: github-pr-size-label-guard
namespace: company.team
description: |
Scan open GitHub pull requests, label them by diff size, warn on oversized PRs,
and gate merges with a review checklist posted to Slack.
triggers:
- id: every_morning
type: io.kestra.plugin.core.trigger.Schedule
description: Triage open PRs every weekday morning
cron: "0 8 * * MON-FRI"
- id: on_demand_webhook
type: io.kestra.plugin.core.trigger.Webhook
description: On-demand triage after a big merge or release cut
key: "{{ secret('WEBHOOK_KEY') }}"
inputs:
- id: repositories
type: ARRAY
itemType: STRING
displayName: Repositories to scan
description: Repo slugs in owner/name format
defaults:
- "kestra-io/blueprints"
- id: warn_additions
type: INT
displayName: Oversize threshold
description: Flag PRs with more changed lines than this
defaults: 800
- id: slack_channel
type: STRING
displayName: Slack channel
description: Channel receiving the oversize-PR digest
defaults: "#code-review"
tasks:
- id: scan_repos
type: io.kestra.plugin.core.flow.Loop
description: Fan out PR scans across repositories with bounded concurrency
values: "{{ inputs.repositories }}"
concurrencyLimit: 4
tasks:
- id: fetch_open_prs
type: io.kestra.plugin.core.http.Request
description: List open pull requests via the GitHub REST API
uri: "https://api.github.com/repos/{{ parents[0].value
}}/pulls?state=open&per_page=50"
method: GET
headers:
Authorization: "Bearer {{ secret('GITHUB_TOKEN') }}"
Accept: "application/vnd.github+json"
- id: classify_prs
type: io.kestra.plugin.scripts.python.Script
description: Classify PRs into XS/S/M/L/XL buckets and flag oversized ones
containerImage: python:3.11
dependencies:
- kestra
script: |
from kestra import Kestra
import json
warn_at = {{ inputs.warn_additions }}
# fetch_open_prs returns parsed JSON body; fall back to an empty
# list so the blueprint stays runnable in the catalog preview.
try:
prs = {{ outputs.fetch_open_prs.body | json }}
except Exception:
prs = []
if not isinstance(prs, list):
prs = []
def bucket(additions, deletions):
total = (additions or 0) + (deletions or 0)
if total < 50:
return "XS"
if total < 200:
return "S"
if total < 500:
return "M"
if total < warn_at:
return "L"
return "XL"
classified, offenders = [], []
for pr in prs:
additions = pr.get("additions", 0)
deletions = pr.get("deletions", 0)
size = bucket(additions, deletions)
entry = {
"number": pr.get("number"),
"title": pr.get("title", ""),
"url": pr.get("html_url", ""),
"author": (pr.get("user") or {}).get("login", "unknown"),
"additions": additions,
"deletions": deletions,
"size": size,
}
classified.append(entry)
if size == "XL":
offenders.append(entry)
Kestra.logger().info(f"Classified {len(classified)} PRs, {len(offenders)} oversized")
Kestra.outputs({"prs": classified, "offenders": offenders, "repo": """{{ parents[0].value }}"""})
- id: alert_on_oversized
type: io.kestra.plugin.core.flow.If
description: Post a Slack digest only when oversized PRs exist
condition: "{{ outputs.classify_prs.vars.offenders | length > 0 }}"
then:
- id: notify_slack
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Post oversized-PR digest with links and review checklist
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
messageText: |
:rotating_light: *Oversized PRs in `{{ outputs.classify_prs.vars.repo }}`*
{{ outputs.classify_prs.vars.offenders | length }} PR(s) over {{ inputs.warn_additions }} changed lines.
{% for p in outputs.classify_prs.vars.offenders %}<{{ p.url }}|#{{ p.number }} {{ p.title }}> by @{{ p.author }} (+{{ p.additions }}/-{{ p.deletions }}) [{{ p.size }}]
{% endfor %}
Checklist: split stacked changes, add tests, request 2 reviewers.
- id: emit_review_metrics
type: io.kestra.plugin.core.output.OutputValues
description: Export triage coverage for dashboards and audit history
values:
repos_scanned: "{{ inputs.repositories | length }}"
warn_threshold: "{{ inputs.warn_additions }}"
scanned_at: "{{ now() }}"
errors:
- id: alert_on_failure
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Alert on-call if the triage itself fails
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
messageText: |
:warning: *PR Size Guard FAILED*
Flow: `{{ flow.id }}` execution `{{ execution.id }}`
Check GITHUB_TOKEN scope and worker logs.