File indexing completed on 2024-04-14 15:32:41

0001 /*******************************************************************
0002  * duplicatefinderjob.h
0003  * SPDX-FileCopyrightText: 2011 Matthias Fuchs <mat69@gmx.net>
0004  * SPDX-FileCopyrightText: 2019 Harald Sitter <sitter@kde.org>
0005  *
0006  * SPDX-License-Identifier: GPL-2.0-or-later
0007  *
0008  ******************************************************************/
0009 
0010 #ifndef DUPLICATE_FINDER_H
0011 #define DUPLICATE_FINDER_H
0012 
0013 #include <QList>
0014 
0015 #include <KJob>
0016 
0017 #include "bugzillalib.h"
0018 #include "parsebugbacktraces.h"
0019 
0020 /**
0021  * Looks if of the current backtrace is a
0022  * duplicate of any of the specified bug ids.
0023  * If a duplicate is found result is emitted instantly
0024  */
0025 class DuplicateFinderJob : public KJob
0026 {
0027     Q_OBJECT
0028 public:
0029     struct Result {
0030         /**
0031          * First duplicate that was found, it might be that
0032          * this one is a duplicate itself, though this is still
0033          * useful for example to inform the user that their
0034          * backtrace is a duplicate of this bug, which is
0035          * tracked at another number though.
0036          *
0037          * @note 0 means that there is no duplicate
0038          * @see parrentDuplicate
0039          */
0040         int duplicate = 0;
0041 
0042         /**
0043          * This always points to the parent bug, i.e.
0044          * the bug that has no duplicates itself.
0045          * If this is 0 it means that there are no duplicates
0046          */
0047         int parentDuplicate = 0;
0048 
0049         Bugzilla::Bug::Status status = Bugzilla::Bug::Status::Unknown;
0050         Bugzilla::Bug::Resolution resolution = Bugzilla::Bug::Resolution::Unknown;
0051     };
0052 
0053     DuplicateFinderJob(const QList<Bugzilla::Bug::Ptr> &bugs, BugzillaManager *manager, QObject *parent = nullptr);
0054     ~DuplicateFinderJob() override;
0055 
0056     void start() override;
0057 
0058     /**
0059      * Call this after result has been emitted to
0060      * get the result
0061      */
0062     Result result() const;
0063 
0064 private Q_SLOTS:
0065     void slotBugReportFetched(const Bugzilla::Bug::Ptr &bug, QObject *owner);
0066     void slotCommentsFetched(const QList<Bugzilla::Comment::Ptr> &comments, QObject *owner);
0067 
0068     void slotError(const QString &message, QObject *owner);
0069 
0070 private:
0071     void analyzeNextBug();
0072     void fetchBug(int bugId);
0073     void commentsParsed(ParseBugBacktraces::DuplicateRating rating);
0074 
0075 private:
0076     BugzillaManager *m_manager = nullptr;
0077     Result m_result;
0078 
0079     Bugzilla::Bug::Ptr m_bug = nullptr;
0080 
0081     QList<Bugzilla::Bug::Ptr> m_bugs;
0082 };
0083 #endif