Эх сурвалжийг харах

Add stacktrace directly to github issue

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
tobiasKaminsky 3 жил өмнө
parent
commit
53a04af735

+ 20 - 3
src/main/java/com/nextcloud/client/errorhandling/ShowErrorActivity.kt

@@ -31,6 +31,7 @@ import com.owncloud.android.R
 import com.owncloud.android.databinding.ActivityShowErrorBinding
 import com.owncloud.android.utils.ClipboardUtil
 import com.owncloud.android.utils.DisplayUtils
+import com.owncloud.android.utils.StringUtils
 
 class ShowErrorActivity : AppCompatActivity() {
     private lateinit var binding: ActivityShowErrorBinding
@@ -65,8 +66,22 @@ class ShowErrorActivity : AppCompatActivity() {
     private fun reportIssue() {
         ClipboardUtil.copyToClipboard(this, binding.textViewError.text.toString(), false)
         val issueLink = getString(R.string.report_issue_link)
-        if (issueLink.isNotEmpty()) {
-            val uriUrl = Uri.parse(issueLink)
+        val template = getString(R.string.report_issue_template)
+        if (issueLink.isNotEmpty() && template.isNotEmpty()) {
+            // val uriUrl = Uri.parse(
+            //     String.format(
+            //         issueLink,
+            //         StringUtils.escapeStacktrace(
+            //             String.format(template, binding.textViewError.text.toString())
+            //         )
+            //     )
+            // )
+            val uriUrl = Uri.parse(
+                String.format(
+                    issueLink,
+                    StringUtils.escapeStacktrace(binding.textViewError.text.toString())
+                )
+            )
             val intent = Intent(Intent.ACTION_VIEW, uriUrl)
             DisplayUtils.startIntentIfAppAvailable(intent, this, R.string.no_browser_available)
         }
@@ -80,7 +95,9 @@ class ShowErrorActivity : AppCompatActivity() {
 
     override fun onOptionsItemSelected(item: MenuItem): Boolean {
         return when (item.itemId) {
-            R.id.error_share -> { onClickedShare(); true }
+            R.id.error_share -> {
+                onClickedShare(); true
+            }
             else -> super.onOptionsItemSelected(item)
         }
     }

+ 1 - 1
src/main/java/com/owncloud/android/MainApp.java

@@ -233,7 +233,7 @@ public class MainApp extends MultiDexApplication implements HasAndroidInjector {
         final boolean isCrashReportingProcess = getAppProcessName().endsWith(":crash");
         final boolean useExceptionHandler = !appInfo.isDebugBuild();
 
-        if (!isCrashReportingProcess && useExceptionHandler) {
+        if (!isCrashReportingProcess) {
             Thread.UncaughtExceptionHandler defaultPlatformHandler = Thread.getDefaultUncaughtExceptionHandler();
             final ExceptionHandler crashReporter = new ExceptionHandler(this,
                                                                         defaultPlatformHandler);

+ 15 - 14
src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java

@@ -102,7 +102,6 @@ import com.owncloud.android.ui.events.SearchEvent;
 import com.owncloud.android.ui.fragment.FileDetailsSharingProcessFragment;
 import com.owncloud.android.ui.fragment.GalleryFragment;
 import com.owncloud.android.ui.fragment.OCFileListFragment;
-import com.owncloud.android.ui.preview.PreviewTextStringFragment;
 import com.owncloud.android.ui.trashbin.TrashbinActivity;
 import com.owncloud.android.utils.BitmapUtils;
 import com.owncloud.android.utils.DisplayUtils;
@@ -431,19 +430,21 @@ public abstract class DrawerActivity extends ToolbarActivity
         int itemId = menuItem.getItemId();
 
         if (itemId == R.id.nav_all_files) {
-            if (this instanceof FileDisplayActivity &&
-                !(((FileDisplayActivity) this).getLeftFragment() instanceof GalleryFragment) &&
-                !(((FileDisplayActivity) this).getLeftFragment() instanceof PreviewTextStringFragment)) {
-                showFiles(false);
-                ((FileDisplayActivity) this).browseToRoot();
-                EventBus.getDefault().post(new ChangeMenuEvent());
-            } else {
-                Intent intent = new Intent(getApplicationContext(), FileDisplayActivity.class);
-                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
-                intent.setAction(FileDisplayActivity.ALL_FILES);
-                intent.putExtra(FileDisplayActivity.DRAWER_MENU_ID, menuItem.getItemId());
-                startActivity(intent);
-            }
+            throw new RuntimeException();
+
+//            if (this instanceof FileDisplayActivity &&
+//                !(((FileDisplayActivity) this).getLeftFragment() instanceof GalleryFragment) &&
+//                !(((FileDisplayActivity) this).getLeftFragment() instanceof PreviewTextStringFragment)) {
+//                showFiles(false);
+//                ((FileDisplayActivity) this).browseToRoot();
+//                EventBus.getDefault().post(new ChangeMenuEvent());
+//            } else {
+//                Intent intent = new Intent(getApplicationContext(), FileDisplayActivity.class);
+//                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+//                intent.setAction(FileDisplayActivity.ALL_FILES);
+//                intent.putExtra(FileDisplayActivity.DRAWER_MENU_ID, menuItem.getItemId());
+//                startActivity(intent);
+//            }
         } else if (itemId == R.id.nav_favorites) {
             handleSearchEvents(new SearchEvent("", SearchRemoteOperation.SearchType.FAVORITE_SEARCH),
                                menuItem.getItemId());

+ 12 - 4
src/main/java/com/owncloud/android/utils/StringUtils.java

@@ -58,7 +58,7 @@ public final class StringUtils {
                     matcher.group(),
                     String.format(Locale.getDefault(), "<font color='%d'><b>%s</b></font>", color,
                                   matcher.group())
-                );
+                                                            );
                 matcher.appendReplacement(stringBuffer, Matcher.quoteReplacement(replacement));
             }
             matcher.appendTail(stringBuffer);
@@ -70,11 +70,19 @@ public final class StringUtils {
     }
 
     public static
-    @NonNull String removePrefix(@NonNull String s, @NonNull String prefix)
-    {
-        if (s.startsWith(prefix)){
+    @NonNull
+    String removePrefix(@NonNull String s, @NonNull String prefix) {
+        if (s.startsWith(prefix)) {
             return s.substring(prefix.length());
         }
         return s;
     }
+
+    public static String escapeStacktrace(String string) {
+        return string
+            .replaceAll("\n", "%0A")
+            .replaceAll(" ", "\\+")
+            .replaceAll("`", "%A")
+            .replaceAll("#", "%23");
+    }
 }

+ 44 - 1
src/main/res/values/setup.xml

@@ -97,7 +97,50 @@
     <string name="help_link" translatable="false">https://help.nextcloud.com/c/clients/android</string>
     <string name="translation_link" translatable="false">https://www.transifex.com/nextcloud/nextcloud/android/</string>
     <string name="contributing_link" translatable="false">https://github.com/nextcloud/android/blob/master/CONTRIBUTING.md</string>
-    <string name="report_issue_link" translatable="false">https://github.com/nextcloud/android/issues/new/choose</string>
+    <string name="report_issue_link" translatable="false">https://github.com/nextcloud/android/issues/new?labels=bug&amp;body=%1$s</string>
+    <string name="report_issue_template" translatable="false">"### Stacktrace\n"
+            "\n" +
+            "### Steps to reproduce\n" +
+            "1. \n" +
+            "2. \n" +
+            "3. \n" +
+            "\n" +
+            "### Expected behaviour\n" +
+            "- Tell us what should happen\n" +
+            "\n" +
+            "### Actual behaviour\n" +
+            "- Tell us what happens\n" +
+            "\n" +
+            "### Can you reproduce this problem on https://try.nextcloud.com?\n" +
+            "- Please create a test demo account and see if this still happens there.\n" +
+            "- If yes, please open up a bug report\n" +
+            "- If not, please verify server setup and ask for help on forum\n" +
+            "\n" +
+            "### Environment data\n" +
+            "Android version:\n" +
+            "\n" +
+            "Device model: \n" +
+            "\n" +
+            "Stock or customized system:\n" +
+            "\n" +
+            "Nextcloud app version:\n" +
+            "\n" +
+            "Nextcloud server version:\n" +
+            "\n" +
+            "Reverse proxy:\n" +
+            "\n" +
+            "### Logs\n" +
+            "#### Web server error log\n" +
+            "```\n" +
+            "Insert your webserver log here\n" +
+            "```\n" +
+            "\n" +
+            "#### Nextcloud log (data/nextcloud.log)\n" +
+            "```\n" +
+            "Insert your Nextcloud log here\n" +
+            "```\n" +
+            "**NOTE:** Be super sure to remove sensitive data like passwords, note that everybody can look here! You " +
+            "can use the Issue Template application to prefill some of the required information: https://apps.nextcloud.com/apps/issuetemplate\n"</string>
 
     <!-- login data links -->
     <string name="login_data_own_scheme" translatable="false">nc</string>

+ 117 - 0
src/test/java/com/owncloud/android/utils/StringUtilsTest.java

@@ -131,4 +131,121 @@ public class StringUtilsTest {
         assertEquals("returned text without prefix was incorrect",
                      expectedReturn, StringUtils.removePrefix(text, prefix));
     }
+
+    @Test
+    public void escapeString() {
+        // we cannot use R.string.report_issue_template
+        // filled with a random stacktrace
+        String raw = "### Stacktrace\n" +
+            "java.lang.RuntimeException\n" +
+            "at com.owncloud.android.ui.activity.DrawerActivity.onNavigationItemClicked(DrawerActivity.java:423)\n" +
+            "at com.owncloud.android.ui.activity.DrawerActivity.lambda$null$0$DrawerActivity(DrawerActivity.java:383)\n" +
+            "at com.owncloud.android.ui.activity.-$$Lambda$DrawerActivity$WuFXuKRKoNjsgnTzctIqSi-LJ_I.run(Unknown Source:4)\n" +
+            "at android.os.Handler.handleCallback(Handler.java:883)\n" +
+            "at android.os.Handler.dispatchMessage(Handler.java:100)\n" +
+            "at android.os.Looper.loop(Looper.java:214)\n" +
+            "at android.app.ActivityThread.main(ActivityThread.java:7356)\n" +
+            "at java.lang.reflect.Method.invoke(Native Method)\n" +
+            "at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)\n" +
+            "at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)\n" +
+            "\n" +
+            "### Steps to reproduce\n" +
+            "1. \n" +
+            "2. \n" +
+            "3. \n" +
+            "\n" +
+            "### Expected behaviour\n" +
+            "- Tell us what should happen\n" +
+            "\n" +
+            "### Actual behaviour\n" +
+            "- Tell us what happens\n" +
+            "\n" +
+            "### Can you reproduce this problem on https://try.nextcloud.com?\n" +
+            "- Please create a test demo account and see if this still happens there.\n" +
+            "- If yes, please open up a bug report\n" +
+            "- If not, please verify server setup and ask for help on forum\n" +
+            "\n" +
+            "### Environment data\n" +
+            "Android version:\n" +
+            "\n" +
+            "Device model: \n" +
+            "\n" +
+            "Stock or customized system:\n" +
+            "\n" +
+            "Nextcloud app version:\n" +
+            "\n" +
+            "Nextcloud server version:\n" +
+            "\n" +
+            "Reverse proxy:\n" +
+            "\n" +
+            "### Logs\n" +
+            "#### Web server error log\n" +
+            "```\n" +
+            "Insert your webserver log here\n" +
+            "```\n" +
+            "\n" +
+            "#### Nextcloud log (data/nextcloud.log)\n" +
+            "```\n" +
+            "Insert your Nextcloud log here\n" +
+            "```\n" +
+            "**NOTE:** Be super sure to remove sensitive data like passwords, note that everybody can look here! You " +
+            "can use the Issue Template application to prefill some of the required information: https://apps.nextcloud.com/apps/issuetemplate\n";
+
+        String escaped = "###+Stacktrace%0A" +
+            "java.lang.RuntimeException%0A" +
+            "at+com.owncloud.android.ui.activity.DrawerActivity.onNavigationItemClicked(DrawerActivity.java:423)%0A" +
+            "at+com.owncloud.android.ui.activity.DrawerActivity.lambda$null$0$DrawerActivity(DrawerActivity.java:383)%0A" +
+            "at+com.owncloud.android.ui.activity.-$$Lambda$DrawerActivity$WuFXuKRKoNjsgnTzctIqSi-LJ_I.run(Unknown+Source:4)%0A" +
+            "at+android.os.Handler.handleCallback(Handler.java:883)%0A" +
+            "at+android.os.Handler.dispatchMessage(Handler.java:100)%0A" +
+            "at+android.os.Looper.loop(Looper.java:214)%0A" +
+            "at+android.app.ActivityThread.main(ActivityThread.java:7356)%0A" +
+            "at+java.lang.reflect.Method.invoke(Native+Method)%0A" +
+            "at+com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)%0A" +
+            "at+com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)%0A" +
+            "%0A" +
+            "###+Steps+to+reproduce%0A" +
+            "1.+%0A" +
+            "2.+%0A" +
+            "3.+%0A" +
+            "%0A" +
+            "###+Expected+behaviour%0A" +
+            "-+Tell+us+what+should+happen%0A" +
+            "%0A" +
+            "###+Actual+behaviour%0A" +
+            "-+Tell+us+what+happens%0A" +
+            "%0A" +
+            "###+Can+you+reproduce+this+problem+on+https://try.nextcloud.com?%0A" +
+            "-+Please+create+a+test+demo+account+and+see+if+this+still+happens+there.%0A" +
+            "-+If+yes,+please+open+up+a+bug+report%0A" +
+            "-+If+not,+please+verify+server+setup+and+ask+for+help+on+forum%0A" +
+            "%0A" +
+            "###+Environment+data%0A" +
+            "Android+version:%0A" +
+            "%0A" +
+            "Device+model:+%0A" +
+            "%0A" +
+            "Stock+or+customized+system:%0A" +
+            "%0A" +
+            "Nextcloud+app+version:%0A" +
+            "%0A" +
+            "Nextcloud+server+version:%0A" +
+            "%0A" +
+            "Reverse+proxy:%0A" +
+            "%0A" +
+            "###+Logs%0A" +
+            "####+Web+server+error+log%0A" +
+            "```%0A" +
+            "Insert+your+webserver+log+here%0A" +
+            "```%0A" +
+            "%0A" +
+            "####+Nextcloud+log+(data/nextcloud.log)%0A" +
+            "```%0A" +
+            "Insert+your+Nextcloud+log+here%0A" +
+            "```%0A" +
+            "**NOTE:**+Be+super+sure+to+remove+sensitive+data+like+passwords,+note+that+everybody+can+look+here!+You+" +
+            "can+use+the+Issue+Template+application+to+prefill+some+of+the+required+information:+https://apps.nextcloud.com/apps/issuetemplate%0A";
+
+        assertEquals(escaped, StringUtils.escapeStacktrace(raw));
+    }
 }