1#pragma once
2
3/****************************************************************************************
4 ** GitQlient is an application to manage and operate one or several Git repositories. With
5 ** GitQlient you will be able to add commits, branches and manage all the options Git provides.
6 ** Copyright (C) 2021 Francesc Martinez
7 **
8 ** LinkedIn: www.linkedin.com/in/cescmm/
9 ** Web: www.francescmm.com
10 **
11 ** This program is free software; you can redistribute it and/or
12 ** modify it under the terms of the GNU Lesser General Public
13 ** License as published by the Free Software Foundation; either
14 ** version 2 of the License, or (at your option) any later version.
15 **
16 ** This program is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ** Lesser General Public License for more details.
20 **
21 ** You should have received a copy of the GNU Lesser General Public
22 ** License along with this library; if not, write to the Free Software
23 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 ***************************************************************************************/
25
26#include <QObject>
27#include <QMap>
28#include <QVector>
29
30#include <PullRequest.h>
31#include <Issue.h>
32#include <Platform.h>
33
34namespace GitServer
35{
36class IRestApi;
37struct PullRequest;
38struct Issue;
39struct Label;
40struct Milestone;
41}
42
43class GitServerCache : public QObject
44{
45 Q_OBJECT
46
47signals:
48 void connectionTested();
49 void issueUpdated(const GitServer::Issue &issue);
50 void issuesReceived();
51 void prUpdated(GitServer::PullRequest pr);
52 void prReceived();
53 void prReviewsReceived();
54 void errorOccurred(const QString &error);
55
56public:
57 explicit GitServerCache(QObject *parent = nullptr);
58 ~GitServerCache();
59
60 bool init(const QString &serverUrl, const QPair<QString, QString> &repoInfo);
61
62 QString getUserName() const;
63
64 QVector<GitServer::PullRequest> getPullRequests() const;
65 GitServer::PullRequest getPullRequest(int number) const { return mPullRequests.value(number); }
66 GitServer::PullRequest getPullRequest(const QString &sha) const;
67 QVector<GitServer::Issue> getIssues() const;
68 GitServer::Issue getIssue(int number) const { return mIssues.value(number); }
69 QVector<GitServer::Label> getLabels() const { return mLabels; }
70 QVector<GitServer::Milestone> getMilestones() const { return mMilestones; }
71
72 GitServer::Platform getPlatform() const;
73 GitServer::IRestApi *getApi() const;
74
75private:
76 bool mInit = false;
77 int mPreSteps = -1;
78 bool mWaitingConfirmation = false;
79 QScopedPointer<GitServer::IRestApi> mApi;
80 QMap<int, GitServer::PullRequest> mPullRequests;
81 QMap<int, GitServer::Issue> mIssues;
82 QVector<GitServer::Label> mLabels;
83 QVector<GitServer::Milestone> mMilestones;
84
85 void triggerSignalConditionally();
86
87 void onConnectionTested();
88 void onIssueUpdated(const GitServer::Issue &issue);
89 void onPRUpdated(const GitServer::PullRequest &pr);
90 void onCommentsReceived(int number, const QVector<GitServer::Comment> &comments);
91 void onCodeReviewsReceived(int number, const QVector<GitServer::CodeReview> &codeReviews);
92 void onCommentReviewsReceived(int number, const QMap<int, GitServer::Review> &commentReviews);
93 void onCommitsReceived(int number, const QVector<GitServer::Commit> &commits, int currentPage, int lastPage);
94
95 void initLabels(const QVector<GitServer::Label> &labels);
96 void initMilestones(const QVector<GitServer::Milestone> &milestones);
97 void initIssues(const QVector<GitServer::Issue> &issues);
98 void initPullRequests(const QVector<GitServer::PullRequest> &prs);
99};
100