-
Notifications
You must be signed in to change notification settings - Fork 7
/
bug-agent.cpp
205 lines (178 loc) · 5.11 KB
/
bug-agent.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#include "bug-agent.h"
#include "branchitem.h"
#include "mainwindow.h"
#include "vymmodel.h"
#include <QHash>
extern Main *mainWindow;
extern QDir vymBaseDir;
extern bool debug;
BugAgent::BugAgent (BranchItem *bi,const QString &u)
{
if (!bi)
{
qWarning ("Const BugAgent: bi==NULL");
delete (this);
return;
}
branchID=bi->getID();
VymModel *model = bi->getModel();
modelID = model->getModelID();
//qDebug()<<"Constr. BugAgent for "<<branchID;
url = u;
QStringList args;
if (url.contains("show_bug"))
{
missionType = SingleBug;
QRegExp rx("(\\d+)");
if (rx.indexIn(url) != -1)
{
bugID = rx.cap(1);
args << bugID;
} else
{
qDebug() << "BugAgent: No bugID found in: " << url;
delete (this);
return;
}
} else if (u.contains("buglist.cgi"))
{
missionType = Query; //FIXME-3 query not supported yet by new bugger
args << "--query";
args << url;
} else
{
qDebug() << "Unknown Bugzilla command:\n"<<url;
delete (this);
return;
}
bugScript = vymBaseDir.path() + "/scripts/bugger";
p = new VymProcess;
connect (p, SIGNAL (finished(int, QProcess::ExitStatus) ),
this, SLOT (processFinished(int, QProcess::ExitStatus) ));
p->start (bugScript, args);
if (!p->waitForStarted())
{
qWarning() << "BugAgent::getBugzillaData couldn't start " << bugScript;
return;
}
// Visual hint that we are doing something // FIXME-4 show spinner instead?
if (missionType == SingleBug)
model->setHeading ("Updating: " + bi->getHeadingPlain(), bi ); //FIXME-4 translation needed?
}
BugAgent::~BugAgent ()
{
//qDebug()<<"Destr. BugAgent for "<<branchID;
delete p;
}
void BugAgent::processFinished(int exitCode, QProcess::ExitStatus exitStatus)
{
if (exitStatus == QProcess::NormalExit)
{
result=p->getStdout().split("\n");
QString err = p->getErrout();
if (!err.isEmpty())
qWarning() << "BugAgent Error: " << err;
else
processBugzillaData ();
} else
qWarning() << "BugAgent: Process finished with exitCode=" << exitCode;
deleteLater();
}
void BugAgent::processBugzillaData()
{
// Find model from which we had been started
VymModel *model = mainWindow->getModel (modelID);
if (model)
{
// and find branch which triggered this mission
BranchItem *missionBI = (BranchItem*)(model->findID (branchID));
if (missionBI)
{
// Here we go...
QRegExp re("(\\d*):(\\S*):\"(.*)\"");
re.setMinimal(false);
bug_desc.clear();
bug_prio.clear();
bug_sev.clear();
bug_deltats.clear();
bug_status.clear();
bug_whiteboard.clear();
QStringList bugs;
foreach (QString line,result)
{
if (debug) qDebug() << "BugAgent::procBugData line="<<line;
if (re.indexIn(line) != -1)
{
if (re.cap(2) == "short_desc")
{
bugs.append(re.cap(1));
bug_desc[re.cap(1)] = re.cap(3).replace("\\\"","\"");
}
else if (re.cap(2) == "priority")
bug_prio[re.cap(1)] = re.cap(3).left(2);
else if (re.cap(2) == "bug_severity")
{
if (re.cap(3) == "Critical")
bug_sev[re.cap(1)] = "S1";
else if (re.cap(3) == "Major")
bug_sev[re.cap(1)] = "S2";
else if (re.cap(3) == "Normal")
bug_sev[re.cap(1)] = "S3";
else if (re.cap(3) == "Minor")
bug_sev[re.cap(1)] = "S4";
else if (re.cap(3) == "Enhancement")
bug_sev[re.cap(1)] = "S5";
else
{
qWarning() << "BugAgent: Bugzilla returned severity " << re.cap(3);
bug_sev[re.cap(1)] = re.cap(3);
}
}
else if (re.cap(2) == "delta_ts")
bug_deltats[re.cap(1)] = re.cap(3);
else if (re.cap(2) == "bug_status")
bug_status[re.cap(1)] = re.cap(3);
else if (re.cap(2) == "status_whiteboard")
bug_whiteboard[re.cap(1)] = re.cap(3);
}
}
if (bug_desc.count() <= 0 )
qWarning() << "BugAgent: Couldn't find data";
else if (missionType == SingleBug)
{
// Only single bug changed
QString b = bugs.first();
setModelBugzillaData (model, missionBI, b);
} else
{
// Process results of query
BranchItem *newbi;
foreach (QString b,bugs)
{
//qDebug ()<<" -> "<<b<<" "<<bug_desc[b];
newbi = model->addNewBranch(missionBI);
newbi->setURL ("https://bugzilla.novell.com/show_bug.cgi?id="+b);
if (!newbi)
qWarning() << "BugAgent: Couldn't create new branch?!";
else
setModelBugzillaData (model, newbi,b);
}
}
} else
qWarning () << "BugAgent: Found model, but not branch #" << branchID;
} else
qWarning () << "BugAgent: Couldn't find model #" << modelID;
}
void BugAgent::setModelBugzillaData (VymModel *model, BranchItem *bi, const QString &bugID)
{
QString ps = bug_prio[bugID];
if (bug_whiteboard[bugID].contains ("PNEW")) ps = ps + "/" + bug_sev[bugID];
if (bug_status[bugID] == "CLOSED"
|| bug_status[bugID] == "VERIFIED"
|| bug_status[bugID] == "RESOLVED")
{
model->setHeadingPlainText ("(" + ps + ") - " + bugID + " - " + bug_desc[bugID], bi);
model->colorSubtree (Qt::blue, bi);
} else
model->setHeadingPlainText (ps + " - " + bugID + " - " + bug_desc[bugID], bi);
}