Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Api/Projects.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace Gitlab\Api;

use Psr\Http\Message\StreamInterface;
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
use Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException;
use Symfony\Component\OptionsResolver\Options;
Expand Down Expand Up @@ -1118,6 +1119,14 @@ public function uploadFile(int|string $project_id, string $file): mixed
return $this->post($this->getProjectPath($project_id, 'uploads'), [], [], ['file' => $file]);
}

/**
* @see https://docs.gitlab.com/api/project_markdown_uploads/#download-an-uploaded-file-by-secret-and-filename
*/
public function downloadUpload(int|string $project_id, string $secret, string $filename): StreamInterface
{
return $this->getAsResponse($this->getProjectPath($project_id, 'uploads/'.self::encodePath($secret).'/'.self::encodePath($filename)))->getBody();
}

public function uploadAvatar(int|string $project_id, string $file): mixed
{
return $this->put('projects/'.self::encodePath($project_id), [], [], ['avatar' => $file]);
Expand Down
15 changes: 15 additions & 0 deletions tests/Api/ProjectsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use DateTime;
use Gitlab\Api\Projects;
use GuzzleHttp\Psr7\Response;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject;
Expand Down Expand Up @@ -3380,6 +3381,20 @@ public function shouldUploadAvatar(): void
\unlink($fileName);
}

#[Test]
public function shouldDownloadUpload(): void
{
$returnedStream = new Response(200, [], 'foobar');

$api = $this->getApiMock();
$api->expects($this->once())
->method('getAsResponse')
->with('projects/1/uploads/66dbcd21ec5d24ed6ea225176098d52b/example.txt')
->willReturn($returnedStream);

$this->assertEquals('foobar', $api->downloadUpload(1, '66dbcd21ec5d24ed6ea225176098d52b', 'example.txt')->getContents());
}

#[Test]
public function shouldAddProtectedTag(): void
{
Expand Down