Created
May 3, 2020 12:57
-
-
Save riatw/09855e97e277d9cee19572cee06368a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// setting | |
$backlog_spaceurl = "https://xxx.backlog.jp"; | |
$backlog_projectid = "PROJECTID"; | |
$backlog_apikey = "BACKLOG_APIKEY"; | |
$esa_spaceid = "ESA-ID"; | |
$esa_apikey = "ESA_APIKEY"; | |
$backlog_endpoint_wiki_list = $backlog_spaceurl . "/api/v2/wikis?projectIdOrKey=" . $backlog_projectid . "&apiKey=" . $backlog_apikey; | |
// backlogからデータを取得 | |
$curl = curl_init(); | |
curl_setopt($curl, CURLOPT_URL, $backlog_endpoint_wiki_list); | |
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET'); | |
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | |
$response = curl_exec($curl); | |
$entries = json_decode($response, true); | |
curl_close($curl); | |
$arr = array(); | |
for ( $i = 0; $i < count($entries); $i++ ) { | |
$entry = $entries[$i]; | |
$id = $entry["id"]; | |
$title = preg_replace("/.*\/(.*)/","$1",$entry["name"]); | |
$category = preg_replace("/(.*)\/.*/","$1",$entry["name"]); | |
$email = $entry["createdUser"]["mailAddress"]; | |
$backlog_endpoint_wiki_detail = $backlog_spaceurl . "/api/v2/wikis/" . $id . "?apiKey=" . $backlog_apikey; | |
$curl = curl_init(); | |
curl_setopt($curl, CURLOPT_URL, $backlog_endpoint_wiki_detail); | |
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET'); | |
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | |
$response = curl_exec($curl); | |
$details = json_decode($response, true); | |
curl_close($curl); | |
$body = $details["content"]; | |
$arr[] = array( | |
"id" => $id, | |
"name" => $title, | |
"category" => $category, | |
"email" => $email, | |
"body_md" => $body | |
); | |
} | |
// esaにデータを登録する | |
for ( $i = 0; $i < count($arr); $i++ ) { | |
$item = $arr[$i]; | |
$data = array( | |
"post" => array( | |
"name" => $item["name"], | |
"category" => $item["category"], | |
"body_md" => $item["body_md"], | |
"user"=> str_replace("@domain","",$item["email"]), | |
"wip" => false | |
) | |
); | |
$header = [ | |
'Authorization: Bearer '. $esa_apikey, | |
'Content-Type: application/json', | |
]; | |
$curl = curl_init(); | |
curl_setopt($curl, CURLOPT_URL, 'https://api.esa.io/v1/teams/' . $esa_spaceid .'/posts'); | |
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST'); | |
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data)); | |
curl_setopt($curl, CURLOPT_HTTPHEADER, $header); | |
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($curl, CURLOPT_HEADER, true); | |
$response = curl_exec($curl); | |
$header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE); | |
$header = substr($response, 0, $header_size); | |
$body = substr($response, $header_size); | |
$result = json_decode($body, true); | |
curl_close($curl); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment