Skip to content

Commit 1cbb55c

Browse files
authored
Add GitHub Destination as place to report (#2)
Allow users to specify GitHub Issue as a place to upload reports.
1 parent b377158 commit 1cbb55c

File tree

10 files changed

+297
-95
lines changed

10 files changed

+297
-95
lines changed

Cargo.lock

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.adoc

+42-5
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,15 @@ Used to diagnose errors with an engineers environment. Used when running `pity d
9191

9292
[source,yaml]
9393
....
94-
include::{exampleDir}/doctor-check.yaml[]
94+
apiVersion: pity.github.com/v1alpha
95+
kind: PityDoctorCheck
96+
metadata:
97+
name: path-exists
98+
spec:
99+
exec:
100+
target: scripts/does-path-env-exist.sh
101+
description: Check your shell for basic functionality
102+
help: You're shell does not have a path env. Reload your shell.
95103
....
96104

97105
From the example, when the check runs it will execute `scripts/does-path-env-exist.sh` which is defined relative to the file containing the check.
@@ -108,7 +116,14 @@ A common example is a dependency is missing, the node modules might need to be c
108116

109117
[source,yaml]
110118
....
111-
include::{exampleDir}/known-error.yaml[]
119+
apiVersion: pity.github.com/v1alpha
120+
kind: PityKnownError
121+
metadata:
122+
name: error-exists
123+
spec:
124+
description: Check if the word error is in the logs
125+
pattern: error
126+
help: The command had an error, try reading the logs around there to find out what happened.
112127
....
113128

114129
[cols="1,2"]
@@ -135,7 +150,20 @@ When using `pity-intercept` or `pity report`, a user is able to upload the error
135150

136151
[source,yaml]
137152
....
138-
include::{exampleDir}/report.yaml[]
153+
apiVersion: pity.github.com/v1alpha
154+
kind: PityReport
155+
metadata:
156+
name: report
157+
spec:
158+
additionalData:
159+
username: id -u
160+
ruby: which ruby
161+
node: which node
162+
nodeVersion: node -v
163+
destination:
164+
githubIssue:
165+
owner: ethankhall
166+
repo: dummy-repo
139167
....
140168

141169
[cols="1,2"]
@@ -147,9 +175,18 @@ a| `.spec.additionalData`
147175
| A map of `name` to `command`. Pity will run the command and capture the output as part of the report.
148176

149177
a| `.spec.destination`
150-
a| Currently, supports https://github.com/orhun/rustypaste[`rustyPaste`] as a source.
178+
a| Currently, supports GitHubIssues and https://github.com/orhun/rustypaste[`rustyPaste`] as a source.
151179
Additional options will be added in the future.
152180

181+
a| `.spec.destination.githubIssue.owner`
182+
a| (required) GitHub owner part of the slug. (ie. `ethankhall`)
183+
184+
a| `.spec.destination.githubIssue.owner`
185+
a| (required) GitHub repo name (ie. `pity`)
186+
187+
a| `.spec.destination.githubIssue.tags`
188+
a| List of tags to add to the issue.
189+
153190
a| `.spec.destination.rustyPaste.url`
154-
| URL to upload the report to.
191+
a| URL to upload the report to.
155192
|===

examples/report.yaml

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---
12
apiVersion: pity.github.com/v1alpha
23
kind: PityReport
34
metadata:
@@ -11,4 +12,14 @@ spec:
1112
nodeVersion: node -v
1213
destination:
1314
rustyPaste:
14-
url: http://localhost:8000
15+
url: http://localhost:8000
16+
---
17+
apiVersion: pity.github.com/v1alpha
18+
kind: PityReport
19+
metadata:
20+
name: github
21+
spec:
22+
destination:
23+
githubIssue:
24+
owner: ethankhall
25+
repo: dummy-repo

examples/scripts/does-path-env-exist.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
#!/usr/bin/env sh
1+
#!/usr/bin/env bash
22

3+
# This script will always fail.
34
if [[ "z$PATH" == "z" ]]; then
45
exit 1
56
fi

examples/test.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env -S cargo run --bin pity-intercept -- --extra-config examples bash
22

3+
>&2 echo "error 1!"
4+
sleep 1
35
echo "hello world"
4-
echo "error 1!"
56
exit 1

pity-intercept/src/main.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,13 @@ async fn run_command(opts: Cli) -> anyhow::Result<i32> {
9494
)
9595
.prompt();
9696

97+
let report_builder = ReportBuilder::new(capture, &found_config.report_upload);
9798
if let Ok(true) = ans {
98-
let report_builder = ReportBuilder::new(capture, &found_config.report_upload);
99-
10099
if let Err(e) = report_builder.distribute_report().await {
101100
warn!(target: "user", "Unable to upload report: {}", e);
102101
}
102+
} else {
103+
report_builder.write_local_report().ok();
103104
}
104105
Ok(exit_code)
105106
}

pity-lib/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ log = "0.4.16"
2323
regex = "1"
2424
derivative = "2"
2525
reqwest = { version = "0.11.23", features = ["multipart"] }
26-
time = { version = "0.3.31", features = ["macros", "formatting", "local-offset"] }
26+
time = { version = "0.3.31", features = ["macros", "formatting", "local-offset"] }
27+
json = "0.12"

pity-lib/src/capture.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ impl OutputCapture {
135135

136136
pub fn create_report_text(&self, title: Option<&str>) -> anyhow::Result<String> {
137137
let mut f = String::new();
138-
let title = title.unwrap_or("== Command Results");
138+
let title = title.unwrap_or("## Command Results");
139139
writeln!(&mut f, "{}\n", title)?;
140140
writeln!(&mut f, "Ran command `/usr/bin/env -S {}`", self.command)?;
141141
writeln!(
@@ -148,11 +148,12 @@ impl OutputCapture {
148148
"Result of command: {}",
149149
self.exit_code.unwrap_or(-1)
150150
)?;
151-
write!(&mut f, "\n=== Output\n")?;
152-
write!(&mut f, "\n[source,text]\n")?;
153-
writeln!(&mut f, "....")?;
154-
writeln!(&mut f, "{}", self.generate_output())?;
155-
writeln!(&mut f, "....")?;
151+
writeln!(&mut f)?;
152+
writeln!(&mut f, "### Output")?;
153+
writeln!(&mut f)?;
154+
writeln!(&mut f, "```text")?;
155+
writeln!(&mut f, "{}", self.generate_output().trim())?;
156+
writeln!(&mut f, "```")?;
156157
writeln!(&mut f)?;
157158
Ok(f)
158159
}

0 commit comments

Comments
 (0)