subspace_client_github/
issue_report.rs1mod browser;
5mod diagnostics;
6mod draft;
7mod error;
8mod http;
9mod repository;
10mod submission;
11
12pub use browser::{BrowserFallback, BrowserMode, MAX_BROWSER_URL_BYTES};
13pub use diagnostics::Diagnostics;
14pub use draft::{Draft, IssueType};
15pub use error::{Error, ErrorKind};
16pub use repository::IssueRepository;
17pub use submission::{CreatedIssue, Outcome, ReportPlan, TransportKind};
18pub use subspace_core::diagnostics::IssuePaths;
19
20const MAX_BODY_CHARS: usize = 65_536;
21
22#[derive(Debug, Clone)]
24pub struct PreparedReport {
26 title: String,
27 body: String,
28 user_body: String,
29 diagnostic_lines: Vec<String>,
30 issue_type: IssueType,
31 product_id: String,
32 repository: IssueRepository,
33}
34
35impl PreparedReport {
36 pub fn title(&self) -> &str {
38 &self.title
39 }
40
41 pub fn body(&self) -> &str {
43 &self.body
44 }
45
46 pub fn issue_type(&self) -> IssueType {
48 self.issue_type
49 }
50
51 pub fn repository(&self) -> &IssueRepository {
54 &self.repository
55 }
56
57 pub fn requested_labels(&self) -> [String; 2] {
58 [
59 self.issue_type.label().into(),
60 format!("source:{}", self.product_id),
61 ]
62 }
63
64 pub fn browser_fallback(&self) -> BrowserFallback {
65 browser::prepare(self)
66 }
67}
68
69pub fn prepare(
72 draft: &Draft,
73 diagnostics: &Diagnostics,
74 repository: &IssueRepository,
75) -> Result<PreparedReport, Error> {
76 let title = draft::validated_title(draft)?;
77 let diagnostic_lines = diagnostics::lines(diagnostics)?;
78 let user_body = draft::body(draft);
79 let body = body_with_diagnostics(&user_body, &diagnostic_lines);
80 if body.chars().count() > MAX_BODY_CHARS {
81 return Err(ErrorKind::BodyTooLong.into());
82 }
83 Ok(PreparedReport {
84 title,
85 body,
86 user_body,
87 diagnostic_lines,
88 issue_type: draft.issue_type(),
89 product_id: diagnostics.product_id().into(),
90 repository: repository.clone(),
91 })
92}
93
94fn body_with_diagnostics(user_body: &str, lines: &[String]) -> String {
95 if lines.is_empty() {
96 return user_body.into();
97 }
98 format!("{user_body}\n\n## Diagnostics\n\n{}", lines.join("\n"))
99}
100
101#[cfg(test)]
102mod tests;