doczkal / rpms / abrt

Forked from rpms/abrt 4 years ago
Clone

Blame SOURCES/0026-cli-list-show-a-hint-about-creating-a-case-in-RHTS.patch

8f9a28
From 16b6963ef5e37805d2587684f90d2c6d5dd4ffdc Mon Sep 17 00:00:00 2001
8f9a28
From: Jakub Filak <jfilak@redhat.com>
8f9a28
Date: Thu, 6 Dec 2018 17:57:59 +0100
8f9a28
Subject: [PATCH] cli list: show a hint about creating a case in RHTS
8f9a28
8f9a28
Adds "Run 'abrt-cli report ...' for creating a case in Red Hat Customer Portal" to
8f9a28
abrt-cli list output.
8f9a28
8f9a28
Resolves: #1649753
8f9a28
8f9a28
(cherry-picked from 7966e5737e8d3af43b1ecdd6a823234b8d25931d)
8f9a28
8f9a28
Signed-off-by: Jakub Filak <jfilak@redhat.com>
8f9a28
---
8f9a28
 configure.ac        |  2 ++
8f9a28
 src/cli/Makefile.am |  3 ++-
8f9a28
 src/cli/list.c      | 49 +++++++++++++++++++++++++++++++++++++++++++++
8f9a28
 3 files changed, 53 insertions(+), 1 deletion(-)
8f9a28
8f9a28
diff --git a/configure.ac b/configure.ac
8f9a28
index 76e0f274b..5d70bb9a8 100644
8f9a28
--- a/configure.ac
8f9a28
+++ b/configure.ac
8f9a28
@@ -246,6 +246,7 @@ DEFAULT_PLUGINS_CONF_DIR='${datadir}/${PACKAGE_NAME}/conf.d/plugins'
8f9a28
 EVENTS_DIR='${datadir}/libreport/events'
8f9a28
 EVENTS_CONF_DIR='${sysconfdir}/libreport/events.d'
8f9a28
 JOURNAL_CATALOG_DIR='$(prefix)/lib/systemd/catalog'
8f9a28
+WORKFLOWS_DIR='${datadir}/libreport/workflows'
8f9a28
 ENABLE_SOCKET_OR_DBUS='-DENABLE_DBUS=1'
8f9a28
 DEFAULT_DUMP_LOCATION_MODE=0751
8f9a28
 DEFAULT_DUMP_DIR_MODE=$($PKG_CONFIG --variable=dd_mode libreport)
8f9a28
@@ -389,6 +390,7 @@ AC_SUBST(PLUGINS_CONF_DIR)
8f9a28
 AC_SUBST(DEFAULT_PLUGINS_CONF_DIR)
8f9a28
 AC_SUBST(EVENTS_CONF_DIR)
8f9a28
 AC_SUBST(JOURNAL_CATALOG_DIR)
8f9a28
+AC_SUBST(WORKFLOWS_DIR)
8f9a28
 AC_SUBST(EVENTS_DIR)
8f9a28
 AC_SUBST(DEFAULT_DUMP_LOCATION)
8f9a28
 AC_SUBST(DEFAULT_DUMP_LOCATION_MODE)
8f9a28
diff --git a/src/cli/Makefile.am b/src/cli/Makefile.am
8f9a28
index 92dc20ab4..a7c76efa3 100644
8f9a28
--- a/src/cli/Makefile.am
8f9a28
+++ b/src/cli/Makefile.am
8f9a28
@@ -17,7 +17,8 @@ abrt_cli_CFLAGS = \
8f9a28
 	-I$(srcdir)/../include \
8f9a28
 	-I$(srcdir)/../lib \
8f9a28
 	$(LIBREPORT_CFLAGS) \
8f9a28
-	$(POLKIT_AGENT_CFLAGS)
8f9a28
+	$(POLKIT_AGENT_CFLAGS) \
8f9a28
+	-DWORKFLOWS_DIR=\"${WORKFLOWS_DIR}\"
8f9a28
 
8f9a28
 if SUGGEST_AUTOREPORTING
8f9a28
 abrt_cli_CFLAGS += -DSUGGEST_AUTOREPORTING=1
8f9a28
diff --git a/src/cli/list.c b/src/cli/list.c
8f9a28
index d069695c6..2c140cb38 100644
8f9a28
--- a/src/cli/list.c
8f9a28
+++ b/src/cli/list.c
8f9a28
@@ -77,6 +77,55 @@ static void print_crash(problem_data_t *problem_data, int detailed, int text_siz
8f9a28
                             /*names_to_skip:*/ NULL,
8f9a28
                             /*max_text_size:*/ text_size,
8f9a28
                             MAKEDESC_SHOW_ONLY_LIST | MAKEDESC_SHOW_URLS);
8f9a28
+
8f9a28
+        /*
8f9a28
+         * If the problem is reportable and has not yet been reported into RHTS
8f9a28
+         * and there is at least one applicable Workflow which contains
8f9a28
+         * 'report_RHTSupport' event, then append a short message informing
8f9a28
+         * user that he can create a new case in Red Hat Customer Portal.
8f9a28
+         */
8f9a28
+        const char *const not_reportable =  problem_data_get_content_or_NULL(problem_data, FILENAME_NOT_REPORTABLE);
8f9a28
+        const char *const reported_to    =  not_reportable            ? NULL : problem_data_get_content_or_NULL(problem_data, FILENAME_REPORTED_TO);
8f9a28
+        report_result_t *const report    = !reported_to               ? NULL : find_in_reported_to_data(reported_to, "RHTSupport");
8f9a28
+
8f9a28
+        if (!not_reportable && !report)
8f9a28
+        {
8f9a28
+            /* The lines below should be replaced by something simpler, I'd
8f9a28
+             * like to see:
8f9a28
+             * GHashTable *possible_worfklows = load_applicable_workflows_for_dump();
8f9a28
+             *
8f9a28
+             * However, this feature (rhbz#1055565) is intended for RHEL only
8f9a28
+             * and I'm not sure whether it's worth to file another bug against
8f9a28
+             * libreport and try to improve libreport public API.
8f9a28
+             */
8f9a28
+            const char *const dump_dir_name = problem_data_get_content_or_NULL(problem_data, CD_DUMPDIR);
8f9a28
+            GList *const wf_names = list_possible_events_glist(dump_dir_name, "workflow");
8f9a28
+            GHashTable *const possible_workflows = load_workflow_config_data_from_list(wf_names, WORKFLOWS_DIR);
8f9a28
+            g_list_free_full(wf_names, free);
8f9a28
+
8f9a28
+            int event_found = 0;
8f9a28
+
8f9a28
+            GHashTableIter iter;
8f9a28
+            gpointer key = NULL;
8f9a28
+            gpointer value = NULL;
8f9a28
+
8f9a28
+            g_hash_table_iter_init(&iter, possible_workflows);
8f9a28
+            while (!event_found && g_hash_table_iter_next(&iter, &key, &value))
8f9a28
+            {
8f9a28
+                GList *const event_names = wf_get_event_names((workflow_t *)value);
8f9a28
+                event_found = !!g_list_find_custom(event_names, "report_RHTSupport", (GCompareFunc)g_strcmp0);
8f9a28
+                g_list_free_full(event_names, free);
8f9a28
+            }
8f9a28
+
8f9a28
+            g_hash_table_destroy(possible_workflows);
8f9a28
+
8f9a28
+            if (event_found)
8f9a28
+            {
8f9a28
+                char *tmp = xasprintf("%sRun 'abrt-cli report %s' for creating a case in Red Hat Customer Portal\n", desc, dump_dir_name);
8f9a28
+                free(desc);
8f9a28
+                desc = tmp;
8f9a28
+            }
8f9a28
+        }
8f9a28
     }
8f9a28
     fputs(desc, stdout);
8f9a28
     free(desc);
8f9a28
-- 
8f9a28
2.17.2
8f9a28