4b6817381b
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
CI / coverage-report (push) Has been cancelled
CI / test-kubernetes (push) Has been cancelled
CI / should-run-thorough (push) Has been cancelled
CI / test-thorough (cloudwatch-demo) (push) Has been cancelled
CI / test-thorough (flink-ecs) (push) Has been cancelled
CI / test-thorough (upstream-lambda) (push) Has been cancelled
CI / test-thorough (prefect-ecs-fargate) (push) Has been cancelled
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Has been cancelled
Benchmark image — build + push to ECR (any adapter) / build + push (push) Has been cancelled
CI / quality (ubuntu-latest) (push) Has been cancelled
CI / test (tools-runtime) (push) Has been cancelled
CI / test (e2e-general) (push) Has been cancelled
CI / test (cli-runtime) (push) Has been cancelled
CI / test (e2e-provider-and-openclaw) (push) Has been cancelled
CI / test (integrations-and-misc) (push) Has been cancelled
Release / verify (push) Has been cancelled
Release / build-python-dist (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Has been cancelled
Release / publish-release (push) Has been cancelled
Release / publish-main-release (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Has been cancelled
Release / prepare (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Has been cancelled
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Has been cancelled
55 lines
1.7 KiB
Python
55 lines
1.7 KiB
Python
"""GitLab MR write-back helper for the publish_findings node."""
|
|
|
|
import logging
|
|
import os
|
|
|
|
from core.state import InvestigationState
|
|
from integrations.gitlab import build_gitlab_config, post_gitlab_mr_note
|
|
from platform.common.truncation import truncate
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
_GITLAB_MR_NOTE_LIMIT = 4000
|
|
|
|
|
|
def _build_mr_note(report: str) -> str:
|
|
body = truncate(report.strip(), _GITLAB_MR_NOTE_LIMIT)
|
|
return f"### RCA Finding\n\n<details>\n<summary>Investigation summary</summary>\n\n{body}\n\n</details>"
|
|
|
|
|
|
def post_gitlab_mr_writeback(state: InvestigationState, report: str) -> None:
|
|
"""Post an RCA summary as a GitLab MR note if write-back is enabled.
|
|
|
|
No-ops when:
|
|
- GITLAB_MR_WRITEBACK env var is not set to a truthy value
|
|
- merge_request_iid or project_id are absent from state
|
|
Failures are logged as warnings and never propagate to the caller.
|
|
"""
|
|
if os.getenv("GITLAB_MR_WRITEBACK", "").lower() not in ("true", "1", "yes"):
|
|
return
|
|
|
|
gl = (state.get("available_sources") or {}).get("gitlab", {})
|
|
mr_iid = gl.get("merge_request_iid", "")
|
|
project_id = gl.get("project_id", "")
|
|
|
|
if not mr_iid or not project_id:
|
|
return
|
|
|
|
try:
|
|
gl_config = build_gitlab_config(
|
|
{
|
|
"base_url": gl.get("gitlab_url", ""),
|
|
"auth_token": gl.get("gitlab_token", ""),
|
|
}
|
|
)
|
|
post_gitlab_mr_note(
|
|
config=gl_config,
|
|
project_id=project_id,
|
|
mr_iid=mr_iid,
|
|
body=_build_mr_note(report),
|
|
)
|
|
logger.info("[publish] GitLab MR note posted: project=%s mr_iid=%s", project_id, mr_iid)
|
|
except Exception as exc:
|
|
logger.warning("[publish] GitLab MR write-back failed: %s", exc)
|