1 | #include "StageFetcher.h" |
---|---|
2 | |
3 | #include <QJsonDocument> |
4 | #include <QJsonObject> |
5 | #include <QJsonArray> |
6 | |
7 | namespace Jenkins |
8 | { |
9 | StageFetcher::StageFetcher(const Config &config, const JenkinsJobBuildInfo &build, QObject *parent) |
10 | : IFetcher(config, parent) |
11 | , mBuild(build) |
12 | { |
13 | } |
14 | |
15 | void StageFetcher::triggerFetch() |
16 | { |
17 | get(mBuild.url.append("wfapi/describe"), true); |
18 | } |
19 | |
20 | void StageFetcher::processData(const QJsonDocument &json) |
21 | { |
22 | QVector<JenkinsStageInfo> stagesVector; |
23 | auto jsonObject = json.object(); |
24 | |
25 | if (jsonObject.contains(QStringLiteral("stages"))) |
26 | { |
27 | const auto stages = jsonObject[QStringLiteral("stages")].toArray(); |
28 | |
29 | for (const auto &stageInfo : stages) |
30 | { |
31 | JenkinsStageInfo stage; |
32 | const auto obj = stageInfo.toObject(); |
33 | |
34 | if (obj.contains(QStringLiteral("name")) && !obj[QStringLiteral( "name")].toString().contains( "Build")) |
35 | { |
36 | stage.name = obj[QStringLiteral("name")].toString(); |
37 | |
38 | if (obj.contains(QStringLiteral("id"))) |
39 | stage.id = obj[QStringLiteral("id")].toInt(); |
40 | if (obj.contains(QStringLiteral("links"))) |
41 | stage.url = obj[QStringLiteral("links")].toObject()[ "self"].toObject()[ "href"].toString(); |
42 | if (obj.contains(QStringLiteral("status"))) |
43 | stage.result = obj[QStringLiteral("status")].toString(); |
44 | if (obj.contains(QStringLiteral("durationMillis"))) |
45 | stage.duration = obj[QStringLiteral("durationMillis")].toInt(); |
46 | |
47 | stagesVector.append(stage); |
48 | } |
49 | } |
50 | } |
51 | |
52 | emit signalStagesReceived(stagesVector); |
53 | } |
54 | } |
55 |