mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Replace Requests with HTTP Client (#13689)
This commit is contained in:
@@ -27,8 +27,7 @@
|
||||
namespace LibreNMS\Util;
|
||||
|
||||
use Exception;
|
||||
use Requests;
|
||||
use Requests_Response;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class GitHub
|
||||
{
|
||||
@@ -112,9 +111,9 @@ class GitHub
|
||||
*/
|
||||
public function getRelease($tag)
|
||||
{
|
||||
$release = Requests::get($this->github . "/releases/tags/$tag", $this->getHeaders());
|
||||
$release = Http::withHeaders($this->getHeaders())->get($this->github . "/releases/tags/$tag");
|
||||
|
||||
return json_decode($release->body, true);
|
||||
return $release->json();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -122,8 +121,8 @@ class GitHub
|
||||
*/
|
||||
public function getPullRequest()
|
||||
{
|
||||
$pull_request = Requests::get($this->github . "/pulls/{$this->pr}", $this->getHeaders());
|
||||
$this->pr = json_decode($pull_request->body, true);
|
||||
$pull_request = Http::withHeaders($this->getHeaders())->get($this->github . "/pulls/{$this->pr}");
|
||||
$this->pr = $pull_request->json();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -180,9 +179,8 @@ class GitHub
|
||||
}
|
||||
GRAPHQL;
|
||||
|
||||
$data = json_encode(['query' => $query]);
|
||||
$prs = Requests::post($this->graphql, $this->getHeaders(), $data);
|
||||
$prs = json_decode($prs->body, true);
|
||||
$prs = Http::withHeaders($this->getHeaders())->post($this->graphql, ['query' => $query]);
|
||||
$prs = $prs->json();
|
||||
if (! isset($prs['data'])) {
|
||||
var_dump($prs);
|
||||
}
|
||||
@@ -367,14 +365,14 @@ GRAPHQL;
|
||||
$this->createChangelog(false);
|
||||
}
|
||||
|
||||
$release = Requests::post($this->github . '/releases', $this->getHeaders(), json_encode([
|
||||
$release = Http::withHeaders($this->getHeaders())->post($this->github . '/releases', [
|
||||
'tag_name' => $this->tag,
|
||||
'target_commitish' => $updated_sha,
|
||||
'body' => $this->markdown,
|
||||
'draft' => false,
|
||||
]));
|
||||
]);
|
||||
|
||||
return $release->status_code == 201;
|
||||
return $release->status() == 201;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -420,19 +418,18 @@ GRAPHQL;
|
||||
* @param string $file Path in git repo
|
||||
* @param string $contents new file contents
|
||||
* @param string $message The commit message
|
||||
* @return Requests_Response
|
||||
*/
|
||||
private function pushFileContents($file, $contents, $message)
|
||||
private function pushFileContents($file, $contents, $message): string
|
||||
{
|
||||
$existing = Requests::get($this->github . '/contents/' . $file, $this->getHeaders());
|
||||
$existing_sha = json_decode($existing->body)->sha;
|
||||
$existing = Http::withHeaders($this->getHeaders())->get($this->github . '/contents/' . $file);
|
||||
$existing_sha = $existing->json()['sha'];
|
||||
|
||||
$updated = Requests::put($this->github . '/contents/' . $file, $this->getHeaders(), json_encode([
|
||||
$updated = Http::withHeaders($this->getHeaders())->put($this->github . '/contents/' . $file, [
|
||||
'message' => $message,
|
||||
'content' => base64_encode($contents),
|
||||
'sha' => $existing_sha,
|
||||
]));
|
||||
]);
|
||||
|
||||
return json_decode($updated->body)->commit->sha;
|
||||
return $updated->json()['commit']['sha'];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user