| 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 <Milestone.h> |
| 27 | #include <Label.h> |
| 28 | #include <User.h> |
| 29 | #include <Comment.h> |
| 30 | |
| 31 | #include <QVector> |
| 32 | #include <QJsonObject> |
| 33 | #include <QJsonArray> |
| 34 | #include <QStringList> |
| 35 | #include <QDateTime> |
| 36 | #include <QScopedPointer> |
| 37 | |
| 38 | namespace GitServer |
| 39 | { |
| 40 | |
| 41 | struct Issue |
| 42 | { |
| 43 | Issue() = default; |
| 44 | Issue(const QString &_title, const QByteArray &_body, const Milestone &goal, const QVector<Label> &_labels, |
| 45 | const QVector<GitServer::User> &_assignees) |
| 46 | : title(_title) |
| 47 | , body(_body) |
| 48 | , milestone(goal) |
| 49 | , labels(_labels) |
| 50 | , assignees(_assignees) |
| 51 | { |
| 52 | } |
| 53 | |
| 54 | int number {}; |
| 55 | QString title {}; |
| 56 | QByteArray body {}; |
| 57 | Milestone milestone {}; |
| 58 | QVector<Label> labels {}; |
| 59 | User creator {}; |
| 60 | QVector<User> assignees {}; |
| 61 | QString url {}; |
| 62 | QDateTime creation {}; |
| 63 | int = 0; |
| 64 | QVector<Comment> ; |
| 65 | bool isOpen = true; |
| 66 | |
| 67 | QJsonObject toJson() const |
| 68 | { |
| 69 | QJsonObject object; |
| 70 | |
| 71 | if (!title.isEmpty()) |
| 72 | object.insert("title" , title); |
| 73 | |
| 74 | if (!body.isEmpty()) |
| 75 | object.insert("body" , body.toStdString().c_str()); |
| 76 | |
| 77 | if (milestone.id != -1) |
| 78 | object.insert("milestone" , milestone.id); |
| 79 | |
| 80 | QJsonArray array; |
| 81 | auto count = 0; |
| 82 | |
| 83 | for (const auto &assignee : assignees) |
| 84 | array.insert(count++, assignee.name); |
| 85 | object.insert("assignees" , array); |
| 86 | |
| 87 | object.insert("state" , isOpen ? "open" : "closed" ); |
| 88 | |
| 89 | QJsonArray labelsArray; |
| 90 | count = 0; |
| 91 | |
| 92 | for (const auto &label : labels) |
| 93 | labelsArray.insert(count++, label.name); |
| 94 | object.insert("labels" , labelsArray); |
| 95 | |
| 96 | return object; |
| 97 | } |
| 98 | }; |
| 99 | |
| 100 | } |
| 101 | |