1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Integrations\Connectors\SenhorVerdugo; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
class Create extends SenhorVerdugo |
7
|
|
|
{ |
8
|
|
View Code Duplication |
public function issueWatcher() |
|
|
|
|
9
|
|
|
{ |
10
|
|
|
$issueKey = 'TEST-961'; |
11
|
|
|
|
12
|
|
|
try { |
13
|
|
|
$issueService = new IssueService(); |
14
|
|
|
|
15
|
|
|
// watcher's id |
16
|
|
|
$watcher = 'lesstif'; |
17
|
|
|
|
18
|
|
|
$issueService->addWatcher($issueKey, $watcher); |
19
|
|
|
|
20
|
|
|
} catch (SenhorVerdugoException $e) { |
|
|
|
|
21
|
|
|
$this->assertTrue(false, 'add watcher Failed : '.$e->getMessage()); |
22
|
|
|
} |
23
|
|
|
} |
24
|
|
|
|
25
|
|
View Code Duplication |
public function issueWorklog() |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
$issueKey = 'TEST-961'; |
28
|
|
|
|
29
|
|
|
try { |
30
|
|
|
$workLog = new Worklog(); |
31
|
|
|
|
32
|
|
|
$workLog->setComment('I did some work here.') |
33
|
|
|
->setStarted("2016-05-28 12:35:54") |
34
|
|
|
->setTimeSpent('1d 2h 3m'); |
35
|
|
|
|
36
|
|
|
$issueService = new IssueService(); |
37
|
|
|
|
38
|
|
|
$ret = $issueService->addWorklog($issueKey, $workLog); |
39
|
|
|
|
40
|
|
|
$workLogid = $ret->{'id'}; |
|
|
|
|
41
|
|
|
|
42
|
|
|
var_dump($ret); |
|
|
|
|
43
|
|
|
} catch (SenhorVerdugoException $e) { |
|
|
|
|
44
|
|
|
$this->assertTrue(false, 'Create Failed : '.$e->getMessage()); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
public function issueLink() |
51
|
|
|
{ |
52
|
|
|
try { |
53
|
|
|
$il = new IssueLink(); |
54
|
|
|
|
55
|
|
|
$il->setInwardIssue('TEST-258') |
56
|
|
|
->setOutwardIssue('TEST-249') |
57
|
|
|
->setLinkTypeName('Relates') |
58
|
|
|
->setComment('Linked related issue via REST API.'); |
59
|
|
|
|
60
|
|
|
$ils = new IssueLinkService(); |
61
|
|
|
|
62
|
|
|
$ret = $ils->addIssueLink($il); |
|
|
|
|
63
|
|
|
|
64
|
|
|
} catch (SenhorVerdugoException $e) { |
|
|
|
|
65
|
|
|
print("Error Occured! " . $e->getMessage()); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
|
70
|
|
View Code Duplication |
public function issueRemoteLink() |
|
|
|
|
71
|
|
|
{ |
72
|
|
|
$issueKey = 'TEST-316'; |
73
|
|
|
|
74
|
|
|
try { |
75
|
|
|
$issueService = new IssueService(); |
76
|
|
|
|
77
|
|
|
$ril = new RemoteIssueLink(); |
78
|
|
|
|
79
|
|
|
$ril->setUrl('http://www.mycompany.com/support?id=1') |
80
|
|
|
->setTitle('Remote Link Title') |
81
|
|
|
->setRelationship('causes') |
82
|
|
|
->setSummary('Crazy customer support issue'); |
83
|
|
|
|
84
|
|
|
$rils = $issueService->createOrUpdateRemoteIssueLink($issueKey, $ril); |
85
|
|
|
|
86
|
|
|
// rils is array of RemoteIssueLink classes |
87
|
|
|
var_dump($rils); |
|
|
|
|
88
|
|
|
} catch (SenhorVerdugoException $e) { |
|
|
|
|
89
|
|
|
$this->assertTrue(false, 'Create Failed : '.$e->getMessage()); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function comment() |
94
|
|
|
{ |
95
|
|
|
$issueKey = "TEST-879"; |
96
|
|
|
|
97
|
|
|
try { |
98
|
|
|
$comment = new Comment(); |
99
|
|
|
|
100
|
|
|
$body = "<<<COMMENT |
101
|
|
|
Adds a new comment to an issue. |
102
|
|
|
* Bullet 1 |
103
|
|
|
* Bullet 2 |
104
|
|
|
** sub Bullet 1 |
105
|
|
|
** sub Bullet 2 |
106
|
|
|
* Bullet 3 |
107
|
|
|
COMMENT;"; |
108
|
|
|
|
109
|
|
|
$comment->setBody($body) |
110
|
|
|
->setVisibility('role', 'Users'); |
111
|
|
|
; |
112
|
|
|
|
113
|
|
|
$issueService = new IssueService(); |
114
|
|
|
$ret = $issueService->addComment($issueKey, $comment); |
115
|
|
|
print_r($ret); |
116
|
|
|
} catch (SenhorVerdugoException $e) { |
|
|
|
|
117
|
|
|
$this->assertTrue(false, "add Comment Failed : " . $e->getMessage()); |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function addAttachment() |
122
|
|
|
{ |
123
|
|
|
$issueKey = "TEST-879"; |
124
|
|
|
|
125
|
|
|
try { |
126
|
|
|
$issueService = new IssueService(); |
127
|
|
|
|
128
|
|
|
// multiple file upload support. |
129
|
|
|
$ret = $issueService->addAttachments( |
130
|
|
|
$issueKey, |
131
|
|
|
['screen_capture.png', 'bug-description.pdf', 'README.md'] |
132
|
|
|
); |
133
|
|
|
|
134
|
|
|
print_r($ret); |
135
|
|
|
} catch (SenhorVerdugoException $e) { |
|
|
|
|
136
|
|
|
$this->assertTrue(false, "Attach Failed : " . $e->getMessage()); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
public function multipleIssue() |
142
|
|
|
{ |
143
|
|
|
|
144
|
|
|
try { |
145
|
|
|
$issueFieldOne = new IssueField(); |
146
|
|
|
|
147
|
|
|
$issueFieldOne->setProjectKey("TEST") |
148
|
|
|
->setSummary("something's wrong") |
149
|
|
|
->setPriorityName("Critical") |
150
|
|
|
->setIssueType("Bug") |
151
|
|
|
->setDescription("Full description for issue"); |
152
|
|
|
|
153
|
|
|
$issueFieldTwo = new IssueField(); |
154
|
|
|
|
155
|
|
|
$issueFieldTwo->setProjectKey("TEST") |
156
|
|
|
->setSummary("something else is wrong") |
157
|
|
|
->setPriorityName("Critical") |
158
|
|
|
->setIssueType("Bug") |
159
|
|
|
->setDescription("Full description for second issue"); |
160
|
|
|
|
161
|
|
|
$issueService = new IssueService(); |
162
|
|
|
|
163
|
|
|
$ret = $issueService->createMultiple([$issueFieldOne, $issueFieldTwo]); |
164
|
|
|
|
165
|
|
|
//If success, returns an array of the created issues |
166
|
|
|
var_dump($ret); |
|
|
|
|
167
|
|
|
} catch (SenhorVerdugoException $e) { |
|
|
|
|
168
|
|
|
print("Error Occured! " . $e->getMessage()); |
169
|
|
|
} |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
public function issue() |
173
|
|
|
{ |
174
|
|
|
try { |
175
|
|
|
$issueField = new IssueField(); |
176
|
|
|
|
177
|
|
|
$issueField->setProjectKey("TEST") |
178
|
|
|
->setSummary("something's wrong") |
179
|
|
|
->setAssigneeName("lesstif") |
180
|
|
|
->setPriorityName("Critical") |
181
|
|
|
->setIssueType("Bug") |
182
|
|
|
->setDescription("Full description for issue") |
183
|
|
|
->addVersion(["1.0.1", "1.0.3"]) |
184
|
|
|
->addComponents(['Component-1', 'Component-2']) |
185
|
|
|
// set issue security if you need. |
186
|
|
|
->setSecurityId(10001 /* security scheme id */) |
187
|
|
|
->setDueDate('2019-06-19'); |
188
|
|
|
|
189
|
|
|
$issueService = new IssueService(); |
190
|
|
|
|
191
|
|
|
$ret = $issueService->create($issueField); |
192
|
|
|
|
193
|
|
|
//If success, Returns a link to the created issue. |
194
|
|
|
var_dump($ret); |
|
|
|
|
195
|
|
|
} catch (SenhorVerdugoException $e) { |
|
|
|
|
196
|
|
|
print("Error Occured! " . $e->getMessage()); |
197
|
|
|
} |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
public function field() |
201
|
|
|
{ |
202
|
|
|
|
203
|
|
|
try { |
204
|
|
|
$field = new Field(); |
205
|
|
|
|
206
|
|
|
$field->setName("New custom field") |
207
|
|
|
->setDescription("Custom field for picking groups") |
208
|
|
|
->setType("com.atlassian.SenhorVerdugo.plugin.system.customfieldtypes:grouppicker") |
209
|
|
|
->setSearcherKey("com.atlassian.SenhorVerdugo.plugin.system.customfieldtypes:grouppickersearcher"); |
210
|
|
|
|
211
|
|
|
$fieldService = new FieldService(); |
212
|
|
|
|
213
|
|
|
$ret = $fieldService->create($field); |
214
|
|
|
|
215
|
|
|
var_dump($ret); |
|
|
|
|
216
|
|
|
} catch (SenhorVerdugoException $e) { |
|
|
|
|
217
|
|
|
$this->assertTrue(false, 'Field Create Failed : '.$e->getMessage()); |
218
|
|
|
} |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
public function project(ProjectModel $project) |
222
|
|
|
{ |
223
|
|
|
|
224
|
|
|
try { |
225
|
|
|
$p = new Project(); |
226
|
|
|
|
227
|
|
|
$p->setKey('EX') |
228
|
|
|
->setName('Example') |
229
|
|
|
->setProjectTypeKey('organizer') |
230
|
|
|
->setProjectTemplateKey('com.atlassian.SenhorVerdugo-core-project-templates:SenhorVerdugo-core-project-management') |
231
|
|
|
->setDescription('Example Project description') |
232
|
|
|
->setLead('lesstif') |
233
|
|
|
->setUrl('http://example.com') |
234
|
|
|
->setAssigneeType('PROJECT_LEAD') |
235
|
|
|
->setAvatarId(10130) |
236
|
|
|
->setIssueSecurityScheme(10000) |
237
|
|
|
->setPermissionScheme(10100) |
238
|
|
|
->setNotificationScheme(10100) |
239
|
|
|
->setCategoryId(10100); |
240
|
|
|
|
241
|
|
|
$proj = new ProjectService(); |
242
|
|
|
|
243
|
|
|
$pj = $proj->createProject($p); |
244
|
|
|
|
245
|
|
|
// "http://example.com/rest/api/2/project/10042" |
246
|
|
|
var_dump($pj->self); |
|
|
|
|
247
|
|
|
// 10042 |
248
|
|
|
var_dump($pj->id); |
249
|
|
|
} catch (SenhorVerdugoException $e) { |
|
|
|
|
250
|
|
|
print("Error Occured! " . $e->getMessage()); |
251
|
|
|
} |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
public function user() |
255
|
|
|
{ |
256
|
|
|
try { |
257
|
|
|
$us = new UserService(); |
258
|
|
|
|
259
|
|
|
// create new user |
260
|
|
|
$user = $us->create( |
261
|
|
|
[ |
262
|
|
|
'name'=>'charlie', |
263
|
|
|
'password' => 'abracadabra', |
264
|
|
|
'emailAddress' => '[email protected]', |
265
|
|
|
'displayName' => 'Charlie of Atlassian', |
266
|
|
|
] |
267
|
|
|
); |
268
|
|
|
|
269
|
|
|
var_dump($user); |
|
|
|
|
270
|
|
|
} catch (SenhorVerdugoException $e) { |
|
|
|
|
271
|
|
|
print("Error Occured! " . $e->getMessage()); |
272
|
|
|
} |
273
|
|
|
} |
274
|
|
|
} |
275
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.