forked from doctrine/jira-github-issues
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimport_status.php
47 lines (37 loc) · 1.3 KB
/
import_status.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
<?php
require_once 'vendor/autoload.php';
require_once 'jira_markdown.php';
$dotenv = new Dotenv\Dotenv(__DIR__);
$dotenv->load();
if (!isset($argv[1])) {
printf("Missing argument: Project Key\n");
exit(1);
}
$project = $argv[1];
$projects = require 'projects.php';
$client = new \Buzz\Browser();
if (!isset($projects[$project])) {
printf("Unknown project: $project\n");
exit(2);
}
$githubRepository = $projects[$project];
$githubHeaders = [
'User-Agent: Jira Migration',
'Authorization: token ' . $_SERVER['GITHUB_TOKEN'],
'Accept: application/vnd.github.golden-comet-preview+json'
];
$jiraHeaders = ['Authorization: Basic ' . base64_encode(sprintf('%s:%s', $_SERVER['JIRA_USER'], $_SERVER['JIRA_PASSWORD']))];
$ticketStatus = [];
if (file_exists('data/' . $project . '.status.json')) {
$ticketStatus = json_decode(file_get_contents('data/' . $project . '.status.json'), true);
}
if (isset($ticketStatus[$argv[2]])) {
$response = $client->get($ticketStatus[$argv[2]]['url'], $githubHeaders);
if ($response->getStatusCode() >= 400) {
var_dump($response->getContent());
exit(2);
}
$issue = json_decode(file_get_contents('data/' . $project . '/' . $argv[2] . '.json'), true);
var_dump($issue);
var_dump(json_decode($response->getcontent(), true));
}