Build a GitHub issue URL with title / body / labels prefilled.
(
message: str,
feedback_type: str,
diagnostics: dict[str, str],
)
| 2173 | |
| 2174 | |
| 2175 | def _build_feedback_url( |
| 2176 | message: str, |
| 2177 | feedback_type: str, |
| 2178 | diagnostics: dict[str, str], |
| 2179 | ) -> str: |
| 2180 | """Build a GitHub issue URL with title / body / labels prefilled.""" |
| 2181 | from urllib.parse import urlencode |
| 2182 | |
| 2183 | first_line = message.splitlines()[0] if message else "" |
| 2184 | truncated = first_line[:60] + ("…" if len(first_line) > 60 else "") |
| 2185 | title_prefix = f"[{feedback_type}] " if feedback_type != "other" else "" |
| 2186 | title = f"{title_prefix}{truncated}" if truncated else f"{title_prefix}Feedback from CLI" |
| 2187 | |
| 2188 | if diagnostics: |
| 2189 | diag_block = "\n".join(f"- **{k}**: {v}" for k, v in diagnostics.items()) |
| 2190 | body = ( |
| 2191 | f"{message}\n\n" |
| 2192 | "---\n\n" |
| 2193 | "<details>\n" |
| 2194 | "<summary>Diagnostics (auto-collected by <code>openkb feedback</code>)</summary>\n\n" |
| 2195 | f"{diag_block}\n" |
| 2196 | "</details>\n" |
| 2197 | ) |
| 2198 | else: |
| 2199 | body = message |
| 2200 | |
| 2201 | params = {"title": title, "body": body} |
| 2202 | label = _FEEDBACK_LABEL_MAP.get(feedback_type, "") |
| 2203 | if label: |
| 2204 | params["labels"] = label |
| 2205 | |
| 2206 | return f"https://github.com/{_FEEDBACK_REPO}/issues/new?{urlencode(params)}" |
| 2207 | |
| 2208 | |
| 2209 | @cli.command() |