Skip to content

Commit a997d2f

Browse files
[11.4] Add "revert a commit" (#624)
Co-authored-by: Graham Campbell <[email protected]>
1 parent b60993f commit a997d2f

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/Api/Repositories.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,20 @@ public function createCommit($project_id, array $parameters = [])
329329
return $this->post($this->getProjectPath($project_id, 'repository/commits'), $resolver->resolve($parameters));
330330
}
331331

332+
/**
333+
* @param int|string $project_id
334+
* @param string $branch
335+
* @param string $sha
336+
*
337+
* @return mixed
338+
*/
339+
public function revertCommit($project_id, string $branch, string $sha)
340+
{
341+
return $this->post($this->getProjectPath($project_id, 'repository/commits/'.self::encodePath($sha).'/revert'), [
342+
'branch' => $branch,
343+
]);
344+
}
345+
332346
/**
333347
* @param int|string $project_id
334348
* @param string $sha

tests/Api/RepositoriesTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,23 @@ public function shouldCreateCommit(): void
428428
]));
429429
}
430430

431+
/**
432+
* @test
433+
*/
434+
public function shouldRevertCommit(): void
435+
{
436+
$expectedArray = ['title' => 'Initial commit.', 'author_name' => 'John Doe', 'author_email' => '[email protected]'];
437+
438+
$api = $this->getApiMock();
439+
$api->expects($this->once())
440+
->method('post')
441+
->with('projects/1/repository/commits/abcd1234/revert')
442+
->will($this->returnValue($expectedArray))
443+
;
444+
445+
$this->assertEquals($expectedArray, $api->revertCommit(1, 'develop', 'abcd1234'));
446+
}
447+
431448
/**
432449
* @test
433450
*/

0 commit comments

Comments
 (0)