Page MenuHomeGitPull.it

Simplify extraction of JSON debug data received via mail
Closed, ResolvedPublic1 Points

Description

Simplify extraction of JSON debug data received via mail.

Event Timeline

valerio.bozzolan triaged this task as Normal priority.

Done!

https://lab.reyboz.it/libre-busto/crash-report/

1<?php
2# Android Crash Dump exporter for Phabricator
3# Copyright (C) 2021 Valerio Bozzolan
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU Affero General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU Affero General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program. If not, see <http://www.gnu.org/licenses/>
17
18/**
19 * Quick and dirty Android Crash Dump analyzer
20 *
21 * https://gitpull.it/P15
22 */
23
24// base of your Phabricator
25define( 'BASE_URI', 'https://gitpull.it/maniphest/task/edit/form/3/?' );
26
27// received data
28$data_raw = $_POST['data'] ?? null;
29
30$data_clean_text = null;
31$task_args = null;
32if( $data_raw ) {
33
34 $data = @json_decode( $data_raw );
35
36 if( $data ) {
37
38 $data_raw = json_encode( $data, JSON_PRETTY_PRINT );
39
40 // some useful informations
41 $data_clean = [
42 'version code' => $data->APP_VERSION_CODE ?? null,
43 'version name' => $data->APP_VERSION_NAME ?? null,
44 'android version' => $data->ANDROID_VERSION ?? null,
45 'phone' => $data->PHONE_MODEL ?? null,
46 'brand' => $data->BRAND ?? null,
47 'stack' => $data->STACK_TRACE ?? null,
48 ];
49
50 // build an human phrase
51 $data_clean_parts = [];
52 foreach( $data_clean as $k => $v ) {
53 $data_clean_parts[] = "$k:\n$v";
54 }
55 $data_clean_text = implode( "\n\n", $data_clean_parts );
56
57 // build query string
58 $task_args = [
59 'title' => "Fix crash when...",
60 'description' => implode( "\n", [
61 "Dear Developers,",
62 "Please triage this crash:",
63 '',
64 '```',
65 '',
66 $data_clean_text,
67 "\n",
68 '```',
69 '',
70 '',
71 "Thank you! :)",
72 '',
73 '',
74 "> Generated with https://lab.reyboz.it/libre-busto/crash-report/ (P15)",
75 ] ),
76 ];
77
78 } else {
79 $data_raw = 'invalid';
80 }
81
82}
83
84?>
85<html>
86<head>
87 <title>Libre BusTO - crash report dump</title>
88</head>
89<body>
90
91 <h1>Libre BusTO - crash report dump</h1>
92
93 <form method="post">
94 <?php if( $data_clean_text ): ?>
95
96 <p>Info:</p>
97 <textarea readonly><?= htmlentities( $data_clean_text ) ?></textarea>
98 <?php if( $task_args ): ?>
99 <br />
100 <a href="<?= htmlspecialchars( BASE_URI . http_build_query( $task_args ) )?>" target="_blank">Create Task</a>
101 <?php endif ?>
102 </p>
103
104 <?php endif ?>
105
106 <p>Paste here your JSON crash report:</p>
107
108 <p><textarea name="data"><?= htmlentities( $data_raw ) ?></textarea></p>
109
110 <p><button type="submit">OK</button></p>
111 </form>
112
113 <hr />
114
115 <p><a href="https://gitpull.it/tag/libre_busto/">Workboard</a></p>
116
117 <hr />
118
119 <p><a href="https://gitpull.it/P15" target="_blank">Source code and license</a></p>
120
121</body>
122</html>