-
Notifications
You must be signed in to change notification settings - Fork 0
/
import.php
120 lines (111 loc) · 4.4 KB
/
import.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Import log</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
</head>
<body>
<div class="container">
<div class="row justify-content-center">
<div class="col-10 py-5">
<div class="card">
<div class="card-header">
<h1>Import Log</h1>
</div>
<div class="card-body">
<pre>
<?php
echo 'Loading config <br>';
require 'vendor/autoload.php';
$config = require(__DIR__ . '/config.php');
$githubdata = $config['github-data'];
$userNameMapping = $config['username-map'];
$milestoneMapping = $config['milestone-map'];
$labelMapping = $config['label-map'];
use GuzzleHttp\Client;
use GuzzleHttp\Pool;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use League\HTMLToMarkdown\HtmlConverter;
use GuzzleHttp\Exception\RequestException;
if (isset($_FILES['file'])) {
$file = $_FILES['file'];
if ($file['type'] == 'text/xml') {
echo "Upload: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
echo "Stored in: " . $_FILES["file"]["tmp_name"] . "<br><br>";
$content = file_get_contents($file['tmp_name']);
$xml = new SimpleXMLElement($content);
$export = [];
$converter = new HtmlConverter();
foreach ($xml->channel->item as $issue) {
if ($issue->type != 'Epic') {
echo "Converting: " . (string) $issue->key . ' ' . (string) $issue->summary . '<br>';
$temp = [
"title" => (string) $issue->summary,
"body" => $converter->convert((string) $issue->description),
"labels" => []
];
if (array_key_exists((string) $issue->assignee->attributes()->{'username'}, $userNameMapping)) {
$temp["assignees"] = [$userNameMapping[(string) $issue->assignee->attributes()->{'username'}]];
}
if (array_key_exists((string) $issue->fixVersion, $milestoneMapping)) {
$temp["milestone"] = $milestoneMapping[(string) $issue->fixVersion];
}
array_push($temp['labels'], (array_key_exists((string) $issue->type, $labelMapping)) ? $labelMapping[(string) $issue->type] : (string) $issue->type);
array_push($export, $temp);
} else {
echo "Skiped Epic Issue! <br>";
}
}
$client = new Client([
'base_uri' => 'https://api.github.com',
'timeout' => 2.0
]);
$requests = function ($total) use ($export, $client, $githubdata) {
foreach ($export as $item) {
echo 'Requesting: ' . $item['title'] . '<br>';
yield new Request(
'POST',
'/repos/' . $githubdata['owner'] . '/' . $githubdata['repo'] . '/issues?access_token=' . $githubdata['token'],
['Content-type' => 'application/json'],
json_encode($item)
);
}
};
$pool = new Pool(
$client,
$requests(100),
[
'concurrency' => 5,
'fulfilled' => function (Response $response, $index) {
echo $response->getReasonPhrase() . '<br>';
},
'rejected' => function (RequestException $reason, $index) {
echo $reason->getResponse()->getReasonPhrase() . '<br>';
var_dump($reason->getRequest());
},
]
);
// Initiate the transfers and create a promise
$promise = $pool->promise();
// Force the pool of requests to complete.
$promise->wait();
} else {
echo 'The uploaded file is not an xml file.';
}
} else {
echo 'No file was uploaded!';
}
?>
</pre>
</div>
</div>
</div>
</div>
</div>
</body>
</html>