This repository has been archived by the owner on Jul 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.php
735 lines (628 loc) · 22.1 KB
/
index.php
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
<?php
class GitHubObject {
public $available_labels;
public $available_milestones;
public $body;
public $comment;
public $issue;
public $labels;
public $labelsChanged;
public $org;
public $org_token;
public $payload;
public $proxy;
public $repo;
public $sender;
public $token;
public $user;
public $request;
public function init($org, $user, $repo, $token, $org_token, $secret) {
$this->org = $org;
$this->user = $user;
$this->repo = $repo;
$this->token = $token;
$this->org_token = $org_token;
$this->secret = $secret;
$this->comment = "";
$this->request = Array();
}
public function set_proxy($proxy) {
$this->proxy = $proxy;
}
public function set_payload($payload) {
$this->payload = $payload;
$this->sender = $payload['sender']['login'];
$this->labels = Array();
$this->labelsChanged = false;
if (isset($payload['issue'])) {
$this->issue = $payload['issue']['number'];
foreach ($payload['issue']['labels'] as $label) {
print_debug("set_payload: " . $label['name'] . "\n");
$this->labels[count($this->labels)] = $label['name'];
}
} elseif (isset($payload['pull_request'])) {
$this->issue = $payload['pull_request']['number'];
} else {
print_debug("not an issue nor a pull_request !\n");
print_debug(json_encode($payload) . "\n");
}
}
public function set_body_from($from) {
$this->body = $this->payload[$from]['body'];
}
public function add_comment($comment) {
print_debug($comment."\n");
$this->comment = $this->comment . $comment . "\n" ;
}
/* issue a github comment */
public function comment_github_issue() {
// create curl resource
$ch = curl_init();
// set url
$curlopt_url = "https://api.github.com/repos/" .
$this->user . "/" . $this->repo . "/issues/" .
$this->issue . "/comments";
curl_setopt($ch, CURLOPT_URL, $curlopt_url);
// set proxy
if (isset($this->proxy))
curl_setopt($ch, CURLOPT_PROXY, $this->proxy);
// set header
$headers = array('User-Agent: curl-php',
'Authorization: token '.$this->token);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// set request
curl_setopt($ch, CURLOPT_POST, 1);
$comment = array();
$comment['body'] = $this->comment;
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($comment));
// return the transfer as string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// $output contains the output string
$output = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
print "POST comment to: $curlopt_url\n";
print "POST comment returned " . $httpCode . "\n";
print "POST comment on issue " . $this->issue . " was :\n" .
json_encode($comment) ;
// close curl resource
curl_close($ch);
}
/* issue a github patch request */
public function patch_github_issue() {
// create curl resource
$ch = curl_init();
// set url
$curlopt_url = "https://api.github.com/repos/" .
$this->user . "/" . $this->repo . "/issues/" . $this->issue;
curl_setopt($ch, CURLOPT_URL, $curlopt_url);
// set proxy
if (isset($this->proxy))
curl_setopt($ch, CURLOPT_PROXY, $this->proxy);
// set header
$headers = array('User-Agent: curl-php',
'Authorization: token '.$this->token);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// this is a PATCH request
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
// set request
curl_setopt($ch, CURLOPT_POST, 1);
if ($this->labelsChanged) {
$this->request['labels'] = array_values($this->labels);
}
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($this->request));
// return the transfer as string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// $output contains the output string
$output = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
print "PATCH request to: $curlopt_url\n";
print "PATCH request returned " . $httpCode . "\n";
if ($httpCode != 200) {
$this->add_comment("Something has gone wrong (error " . $httpCode . ").\n");
global $maintainers;
$this->add_comment("$maintainers Please have a look at it!\n");
}
// close curl resource
curl_close($ch);
}
}
function print_debug ($str) {
print $str;
}
function HandleHeaderLine( $curl, $header_line ) {
$subStr = substr($header_line, 0, 7);
if (strcmp($subStr ,"ETag: \"") == 0) {
global $etag;
$etag = substr($header_line, 7, -3);
}
return strlen($header_line);
}
/* issue a github get request */
function get_github($gh, $request, &$httpCode) {
global $etag;
print("---\norg=$gh->org\nuser=$gh->user\nrepo=$gh->repo\ntoken=$gh->token\n");
// create curl resource
$ch = curl_init();
// set url
print "https://api.github.com/repos/".$gh->user."/".$gh->repo."/".$request."\n";
print "Authorization: token ".$gh->token."\n";
if (isset($gh->proxy)) {
print "PROXY\n";
} else {
print "NO PROXY\n";
}
curl_setopt($ch, CURLOPT_URL, "https://api.github.com/repos/".$gh->user."/".$gh->repo."/".$request);
// set proxy
if (isset($gh->proxy)) curl_setopt($ch, CURLOPT_PROXY, $gh->proxy);
// set header
$headers = array('User-Agent: curl-php', 'Authorization: token '.$gh->token);
if (isset($etag)) {
$headers[2] = 'If-None-Match: "' . $etag . '"';
}
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// return the transfer as string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// handle the received header
curl_setopt($ch, CURLOPT_HEADERFUNCTION, "HandleHeaderLine");
// $output contains the output string
$output = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// close curl resource
curl_close($ch);
if ($httpCode != 200 && $httpCode != 304) {
print "Could not get " . $request . " error " . $httpCode . "\n";
exit(1);
} else {
print "httpCode = " . $httpCode . "\noutput = " . $output . "\n" ;
}
return json_decode($output, true);
}
function is_organization_member($gh, $reviewer) {
// create curl resource
$ch = curl_init();
// set url
curl_setopt($ch, CURLOPT_URL, "https://api.github.com/orgs/".$gh->org."/members/".$reviewer);
// set proxy
if (isset($proxy)) curl_setopt($ch, CURLOPT_PROXY, $gh->proxy);
// set header
$headers = array('User-Agent: curl-php', 'Authorization: token '.$gh->org_token);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// return the transfer as string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// $output contains the output string
$output = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// close curl resource
curl_close($ch);
if ($httpCode == 204) {
return true;
} else {
return false;
}
}
/* return true if the given label exists (case-insensitive search) */
function label_exists ($gh, $label) {
global $etag;
global $cache_dir;
global $file_prefix;
$file = "$cache_dir/$file_prefix" . "labels.json";
if (!isset($gh->available_labels)) {
/* Read the file if it exists, or just give us an empty array
* if it doesn't */
if (file_exists($file)) {
$fd = fopen($file, "r");
$labels = json_decode(fread($fd, filesize($file)), true);
$etag = $labels['ETag'];
fclose($fd);
} else {
$labels = Array();
unset($GLOBALS['etag']);
}
/* Always try to read from Github. Note that sometimes
* reading from Github may fail, because Github uses API rate
* limiting (https://developer.github.com/v3/#rate-limiting).
* Hopefully, we'll have already loaded a cache file in that
* case! */
$reply = get_github($gh, "labels", $httpCode);
if ($httpCode == 200) {
/* If the read from Github succeeded, check to merge in
* newer content from the Github read, and write out a new
* cache file. */
$labels['ETag'] = $etag;
for($i=0; $i < count($reply); $i++) {
$labels[$reply[$i]['name']] = 'L';
}
$fd = fopen($file, "w") or die("could not open $file\n");
$output = json_encode($labels);
fwrite($fd, $output, strlen($output));
fclose($fd);
} else {
print_debug("getting labels failed: code $httpCode\n");
}
unset($labels['ETag']);
$gh->available_labels = $labels;
}
/* Look through the labels (with case-insensitive searching) and
* see if we can find the desired label */
foreach ($gh->available_labels as $l => $dummy) {
if (strcasecmp($l, $label) == 0) {
return true;
}
}
return false;
}
/* return true if the given milestone exists (case-insensitive
* search) */
function milestone_exists($gh, $milestone) {
global $etag;
global $cache_dir;
global $file_prefix;
/* See comments in label_exists() for a description of the cache
* file/read from Github scheme. */
$file = "$cache_dir/$file_prefix" . "milestones.json";
if (!isset($gh->available_milestones)) {
if (file_exists($file)) {
$fd = fopen($file, "r");
$milestones= json_decode(fread($fd, filesize($file)), true);
$etag = $milestones['ETag'];
fclose($fd);
} else {
$milestones = Array();
unset($GLOBALS['etag']);
}
$reply = get_github($gh, "milestones", $httpCode);
if ($httpCode == 200) {
$milestones['ETag'] = $etag;
for($i=0; $i < count($reply); $i++) {
$milestones[$reply[$i]['title']] = $reply[$i]['number'];
}
$fd = fopen($file, "w") or die ("could not open $file\n");
$output = json_encode($milestones);
fwrite($fd, $output, strlen($output));
fclose($fd);
} else {
print_debug("getting milestones failed: code $httpCode\n");
}
unset($milestones['ETag']);
$gh->available_milestones = $milestones;
}
/* Look through the milestones (with case-insensitive searching)
* and see if we can find the desired milestone */
foreach ($gh->available_milestones as $m => $n) {
if (strcasecmp($m, $milestone) == 0) {
return true;
}
}
return false;
}
/*
* Case-insensitive search to see if a given label is set
*/
function label_set_on_issue($gh, $label) {
foreach ($gh->labels as $idx => $name) {
if (strcasecmp($name, $label) == 0) {
return true;
}
}
return false;
}
/*
* Set a (case-insensitive) label on an issue
*/
function set_issue_label($gh, $label) {
$found = false;
foreach ($gh->labels as $name => $dummy) {
if (strcasecmp($name, $label) == 0) {
print_debug("set_issue_label " . $idx . " => " . $name . "\n");
$found = true;
/* Use the actual label name (since this was a
* case-insensitive search) */
$label = $name;
}
}
if (!$found) {
print "set_issue_label: NOT found ".$label."\n";
$gh->labels[count($gh->labels)] = $label;
$gh->labelsChanged = true;
if ((strcmp($label, "reviewed") == 0) || (strcmp($label, "rm-approved") == 0)) {
remove_issue_label($gh, "pushed-back");
}
} else {
print "set_issue_label: FOUND ".$label."\n";
}
}
/*
* Remove a (case-insensitive) label on an issue
*/
function remove_issue_label($gh, $label) {
foreach ($gh->labels as $idx => $name) {
if (strcasecmp($name, $label) == 0) {
unset($gh->labels[$idx]);
$gh->labelsChanged = true;
$label = $name;
}
}
if ((strcmp($label, "reviewed") ==0) || (strcmp($label, "RM-approved") == 0)) {
set_issue_label($gh, "pushed-back");
}
}
function milestone_set_on_issue($gh) {
return isset($gh->payload['issue']['milestone']);
}
/*
* Set a (case-insensitive) label on a milestone
*/
function set_issue_milestone($gh, $milestone) {
foreach ($gh->available_milestones as $m => $n) {
if (strcasecmp($m, $milestone) == 0) {
$gh->request['milestone'] = $n;
return;
}
}
}
function remove_issue_milestone($gh) {
$gh->request['milestone'] = null;
}
function issue_assigned($gh) {
return isset($gh->payload['issue']['assignee']);
}
/*
* No need for case-insensitive searches here; we're assuming that
* GitHub will treat username "foo" the same as username "Foo".
*/
function set_issue_assignee($gh, $user) {
$gh->request['assignee'] = $user;
}
function remove_issue_assignee($gh) {
$gh->request['assignee'] = null;
}
/*
* Search for label:<name>
*/
function find_label($gh)
{
/* Hard-coded shortcuts: ":+1:", ":thumbsup:", and "👍" are
* shortcuts for the "reviewed"/i label (if it exists). Note that
* : are \W characters, so we have to use \B here instead of
* \b. */
if ((preg_match_all("/\B:\+1:\B/m", $gh->body, $matches) > 0 ||
preg_match_all("/\B:thumbsup:\B/m", $gh->body, $matches) > 0 ||
preg_match_all("/👍/m", $gh->body, $matches) > 0) &&
label_exists($gh, "reviewed")) {
$gh->body .= "\nbot:label:reviewed\n";
}
if (0 == preg_match_all("/\bbot:label:(\S+)\b/m", $gh->body, $matches)) {
return;
}
foreach ($matches[1] as $label) {
print "handling label ". $label ."\n";
if (label_set_on_issue($gh, $label)) {
$gh->add_comment("OMPIBot error: Label \"$label\" is already set on issue $gh->issue.");
} else if (!label_exists($gh, $label)) {
$gh->add_comment("OMPIBot error: Label \"$label\" does not exist.");
} else {
set_issue_label($gh, $label);
}
}
}
/*
* Search for nolabel:<name
*/
function find_nolabel($gh)
{
/* Hard-coded shortcuts: ":-1:", ":thumbsdown:", and "👎" are
* shortcuts for removing the "reviewed"/i label (if it exists).
* Note that : are \W characters, so we have to use \B here
* instead of \b. */
if ((preg_match_all("/\B:\-1:\B/m", $gh->body, $matches) > 0 ||
preg_match_all("/\B:thumbsdown:\B/m", $gh->body, $matches) > 0 ||
preg_match_all("/👎/m", $gh->body, $matches) > 0) &&
label_exists($gh, "reviewed")) {
$gh->body .= "\nbot:nolabel:reviewed\n";
}
if (0 == preg_match_all("/\bbot:nolabel:(\S+)\b/m", $gh->body, $matches)) {
return;
}
foreach ($matches[1] as $label) {
if ((strcmp($label, "reviewed") != 0) && !label_set_on_issue($gh, $label)) {
$gh->add_comment("OMPIBot error: Label \"$label\" is not set on issue $gh->issue.");
} else if (!label_exists($gh, $label)) {
$gh->add_comment("OMPIBot error: Label \"$label\" does not exist.");
} else {
remove_issue_label($gh, $label);
}
}
}
/*
* Search for milestone:<name>
*/
function find_milestone($gh)
{
if (0 == preg_match_all("/\bbot:milestone:(\S+)\b/m", $gh->body, $matches)) {
return;
}
if (count($matches[1]) == 1) {
$milestone = $matches[1][0];
/* rror if the milestone does not exist */
if (!milestone_exists($gh, $milestone)) {
$gh->add_comment("OMPIBot error: Milestone \"$milestone\" does not exist.");
} else {
/* It's ok to override a milestone that was already set */
set_issue_milestone($gh, $milestone);
}
} else if (count($matches[1]) > 1) {
$gh->add_comment("OMPIBot error: Cannot set more than one milestone on an issue.");
}
}
/*
* Search for nomilestone:
*/
function find_nomilestone($gh)
{
if (0 == preg_match_all("/\bbot:nomilestone\b/m", $gh->body, $matches)) {
return;
}
if (count($matches) == 1) {
/* Error if a milestone is not already set on the issue */
if (!milestone_set_on_issue($gh)) {
$gh->add_comment("OMPIBot error: No milestone is set on issue $gh->issue.");
} else {
remove_issue_milestone($gh);
}
} else {
$gh->add_comment("OMPIBot error: Cannot remove more than one milestone from an issue.");
}
}
/*
* Search for assign:<name>
*/
function find_assign($gh)
{
if (0 != preg_match_all("/\bbot:assign:(\S+)\b/m", $gh->body, $matches)) {
if (count($matches[1]) == 1) {
$user = $matches[1][0];
/* If the username begins with @, strip it off (for
* convenience). */
if (preg_match("/^\@/", $user)) {
$user = substr($user, 1);
}
} else if (count($matches[1]) > 1) {
$gh->add_comment("OMPIBot error: Cannot assign more than one user on an issue.");
return;
}
} else if (0 != preg_match_all("/\bbot:assign:(\s+)@(\S+)\b/m", $gh->body, $matches)) {
if (count($matches[1]) == 1) {
$user = $matches[2][0];
} else if (count($matches[1]) > 1) {
$gh->add_comment("OMPIBot error: Cannot assign more than one user on an issue.");
return;
}
} else {
return;
}
/* Error if the user does not exist or is not part of this
* organization. Strictly speaking, the bot should test if the
* user is part of the assignees list, and in the case of the
* ompi-release repo, both tests should be equivalent */
if (!is_organization_member($gh, $user)) {
$gh->add_comment("OMPIBot error: User $user is not valid for issue $gh->issue.");
} else {
/* It's ok to override a user that was already assigned */
set_issue_assignee($gh, $user);
}
}
/*
* Search for unassign:
*/
function find_noassign($gh)
{
if (0 == preg_match_all("/\bbot:unassign\b/m", $gh->body, $matches)) {
return;
}
if (count($matches) == 1) {
/* Error if the user is not already set on the issue */
if (!issue_assigned($gh)) {
$gh->add_comment("OMPIBot error: No user is assigned to issue $gh->issue.");
} else {
remove_issue_assignee($gh);
}
} else {
$gh->add_comment("OMPIBot error: Cannot remove more than one user from an issue.");
}
}
function process_comment_body($gh)
{
print_debug("Checking body: ".$gh->body."\n\n");
find_nolabel($gh);
find_label($gh);
find_nomilestone($gh);
find_milestone($gh);
find_noassign($gh);
find_assign($gh);
if ($gh->labelsChanged || count($gh->request)>0) {
if ((isset($gh->request['assignee']) && (strcmp($gh->request['assignee'],$gh->sender) == 0)) ||
is_organization_member($gh, $gh->sender)) {
$gh->patch_github_issue();
} else {
$gh->add_comment ("@" . $gh->sender . ": Sorry, only this repo's organization members can interact with this bot. If you're a member of this organization, make your membership public so that this bot can verify your membership (go to http://github.com/orgs/" . $gh->org . "/people, find yourself on that page, then change your membership from \"Private\" to \"Public\").\n");
}
} else {
print "NO PATCH\n";
}
if (strlen($gh->comment) > 0) {
$gh->comment_github_issue();
}
}
/* a comment has been posted to an issue */
function process_issue_comment($gh) {
if(strcmp($gh->payload['action'], "created") == 0) {
$gh->set_body_from('comment');
process_comment_body($gh);
} else {
print_debug("nothing to do for action " . $payload['action']);
}
}
/* an issue has been created */
function process_issues($gh) {
if(strcmp($gh->payload['action'], "opened") == 0 ||
strcmp($gh->payload['action'], "created") == 0) {
$gh->set_body_from('issue');
process_comment_body($gh);
} else {
print_debug("nothing to do for action " . $payload['action']);
}
}
/* a pull request has been opened */
function process_pull_request($gh) {
if(strcmp($gh->payload['action'], "opened") == 0) {
$gh->set_body_from('pull_request');
process_comment_body($gh);
} else {
print_debug("nothing to do for action " . $payload['action']);
}
}
/****************************************************************************
* main
****************************************************************************/
/* check the existence of the X-Hub-Signature and X-GitHub-Event headers */
if (!isset($_SERVER['HTTP_X_HUB_SIGNATURE']) ||
!isset($_SERVER['HTTP_X_GITHUB_EVENT'])) {
header("HTTP/1.0 403 Forbidden");
return;
}
$data = file_get_contents('php://input');
require_once "config.inc";
/* check the request signature */
$ctx = hash_init("sha1", HASH_HMAC, $secret);
hash_update($ctx, $data);
$hash = hash_final($ctx);
if (strcmp("sha1=".$hash, $_SERVER['HTTP_X_HUB_SIGNATURE']) != 0) {
header("HTTP/1.0 403 Forbidden");
return;
}
/* the request has been authenticated and can be processed */
header("HTTP/1.1 202 Accepted", true, 202);
$payload = json_decode($data, true);
$event = $_SERVER['HTTP_X_GITHUB_EVENT'];
$fn = "process_" . $event;
if (!function_exists($fn)) {
print_debug("Nothing to do: unknown event\n");
return;
}
if (!isset($payload['sender']['login'])) {
print_debug("Unknown sender ! should not happen\n");
return;
}
$sender = $payload['sender']['login'];
if (strcmp($sender,$bot) == 0) {
print_debug("Nothing to do: sent by " . $bot . "\n");
return;
}
$gh = new GitHubObject;
$gh->init($org, $user, $repo, $token, $org_token, $secret);
if (isset($proxy)) {
$gh->set_proxy($proxy);
}
$gh->set_payload($payload);
$fn($gh);
?>