Skip to content

Commit 75a0e45

Browse files
authored
Merge pull request #174 from glaubinix/t/file-author
File: allow autor for create/update/delete
2 parents 3248628 + 9850c27 commit 75a0e45

File tree

3 files changed

+127
-22
lines changed

3 files changed

+127
-22
lines changed

lib/Gitlab/Api/Repositories.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -266,16 +266,20 @@ public function getFile($project_id, $file_path, $ref)
266266
* @param string $branch_name
267267
* @param string $commit_message
268268
* @param string $encoding
269+
* @param string $author_email
270+
* @param string $author_name
269271
* @return mixed
270272
*/
271-
public function createFile($project_id, $file_path, $content, $branch_name, $commit_message, $encoding = null)
273+
public function createFile($project_id, $file_path, $content, $branch_name, $commit_message, $encoding = null, $author_email = null, $author_name = null)
272274
{
273275
return $this->post($this->getProjectPath($project_id, 'repository/files'), array(
274276
'file_path' => $file_path,
275277
'branch_name' => $branch_name,
276278
'content' => $content,
277279
'commit_message' => $commit_message,
278-
'encoding' => $encoding
280+
'encoding' => $encoding,
281+
'author_email' => $author_email,
282+
'author_name' => $author_name,
279283
));
280284
}
281285

@@ -286,16 +290,20 @@ public function createFile($project_id, $file_path, $content, $branch_name, $com
286290
* @param string $branch_name
287291
* @param string $commit_message
288292
* @param string $encoding
293+
* @param string $author_email
294+
* @param string $author_name
289295
* @return mixed
290296
*/
291-
public function updateFile($project_id, $file_path, $content, $branch_name, $commit_message, $encoding = null)
297+
public function updateFile($project_id, $file_path, $content, $branch_name, $commit_message, $encoding = null, $author_email = null, $author_name = null)
292298
{
293299
return $this->put($this->getProjectPath($project_id, 'repository/files'), array(
294300
'file_path' => $file_path,
295301
'branch_name' => $branch_name,
296302
'content' => $content,
297303
'commit_message' => $commit_message,
298-
'encoding' => $encoding
304+
'encoding' => $encoding,
305+
'author_email' => $author_email,
306+
'author_name' => $author_name,
299307
));
300308
}
301309

@@ -304,14 +312,18 @@ public function updateFile($project_id, $file_path, $content, $branch_name, $com
304312
* @param string $file_path
305313
* @param string $branch_name
306314
* @param string $commit_message
315+
* @param string $author_email
316+
* @param string $author_name
307317
* @return mixed
308318
*/
309-
public function deleteFile($project_id, $file_path, $branch_name, $commit_message)
319+
public function deleteFile($project_id, $file_path, $branch_name, $commit_message, $author_email = null, $author_name = null)
310320
{
311321
return $this->delete($this->getProjectPath($project_id, 'repository/files'), array(
312322
'file_path' => $file_path,
313323
'branch_name' => $branch_name,
314-
'commit_message' => $commit_message
324+
'commit_message' => $commit_message,
325+
'author_email' => $author_email,
326+
'author_name' => $author_name,
315327
));
316328
}
317329

lib/Gitlab/Model/Project.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -141,24 +141,24 @@ public function update(array $params)
141141

142142
return static::fromArray($this->getClient(), $data);
143143
}
144-
144+
145145
/**
146146
* @return Project
147147
*/
148148
public function archive()
149149
{
150150
$data = $this->api("projects")->archive($this->id);
151-
151+
152152
return static::fromArray($this->getClient(), $data);
153153
}
154-
154+
155155
/**
156156
* @return Project
157157
*/
158158
public function unarchive()
159159
{
160160
$data = $this->api("projects")->unarchive($this->id);
161-
161+
162162
return static::fromArray($this->getClient(), $data);
163163
}
164164

@@ -582,11 +582,13 @@ public function getFile($sha, $filepath)
582582
* @param string $content
583583
* @param string $branch_name
584584
* @param string $commit_message
585+
* @param string $author_email
586+
* @param string $author_name
585587
* @return File
586588
*/
587-
public function createFile($file_path, $content, $branch_name, $commit_message)
589+
public function createFile($file_path, $content, $branch_name, $commit_message, $author_email = null, $author_name = null)
588590
{
589-
$data = $this->api('repo')->createFile($this->id, $file_path, $content, $branch_name, $commit_message);
591+
$data = $this->api('repo')->createFile($this->id, $file_path, $content, $branch_name, $commit_message, null, $author_email, $author_name);
590592

591593
return File::fromArray($this->getClient(), $this, $data);
592594
}
@@ -596,11 +598,13 @@ public function createFile($file_path, $content, $branch_name, $commit_message)
596598
* @param string $content
597599
* @param string $branch_name
598600
* @param string $commit_message
601+
* @param string $author_email
602+
* @param string $author_name
599603
* @return File
600604
*/
601-
public function updateFile($file_path, $content, $branch_name, $commit_message)
605+
public function updateFile($file_path, $content, $branch_name, $commit_message, $author_email = null, $author_name = null)
602606
{
603-
$data = $this->api('repo')->updateFile($this->id, $file_path, $content, $branch_name, $commit_message);
607+
$data = $this->api('repo')->updateFile($this->id, $file_path, $content, $branch_name, $commit_message, null, $author_email, $author_name);
604608

605609
return File::fromArray($this->getClient(), $this, $data);
606610
}
@@ -609,11 +613,13 @@ public function updateFile($file_path, $content, $branch_name, $commit_message)
609613
* @param string $file_path
610614
* @param string $branch_name
611615
* @param string $commit_message
616+
* @param string $author_email
617+
* @param string $author_name
612618
* @return bool
613619
*/
614-
public function deleteFile($file_path, $branch_name, $commit_message)
620+
public function deleteFile($file_path, $branch_name, $commit_message, $author_email = null, $author_name = null)
615621
{
616-
$this->api('repo')->deleteFile($this->id, $file_path, $branch_name, $commit_message);
622+
$this->api('repo')->deleteFile($this->id, $file_path, $branch_name, $commit_message, $author_email, $author_name);
617623

618624
return true;
619625
}

test/Gitlab/Tests/Api/RepositoriesTest.php

Lines changed: 93 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,9 @@ public function shouldCreateFile()
500500
'branch_name' => 'master',
501501
'encoding' => null,
502502
'content' => 'some contents',
503-
'commit_message' => 'Added new file'
503+
'commit_message' => 'Added new file',
504+
'author_email' => null,
505+
'author_name' => null,
504506
))
505507
->will($this->returnValue($expectedArray))
506508
;
@@ -523,14 +525,41 @@ public function shouldCreateFileWithEncoding()
523525
'branch_name' => 'master',
524526
'encoding' => 'text',
525527
'content' => 'some contents',
526-
'commit_message' => 'Added new file'
528+
'commit_message' => 'Added new file',
529+
'author_email' => null,
530+
'author_name' => null,
527531
))
528532
->will($this->returnValue($expectedArray))
529533
;
530534

531535
$this->assertEquals($expectedArray, $api->createFile(1, 'dir/file1.txt', 'some contents', 'master', 'Added new file', 'text'));
532536
}
533537

538+
/**
539+
* @test
540+
*/
541+
public function shouldCreateFileWithAuthor()
542+
{
543+
$expectedArray = array('file_name' => 'file1.txt', 'file_path' => 'dir/file1.txt');
544+
545+
$api = $this->getApiMock();
546+
$api->expects($this->once())
547+
->method('post')
548+
->with('projects/1/repository/files', array(
549+
'file_path' => 'dir/file1.txt',
550+
'branch_name' => 'master',
551+
'encoding' => null,
552+
'content' => 'some contents',
553+
'commit_message' => 'Added new file',
554+
'author_email' => '[email protected]',
555+
'author_name' => 'GitLab User',
556+
))
557+
->will($this->returnValue($expectedArray))
558+
;
559+
560+
$this->assertEquals($expectedArray, $api->createFile(1, 'dir/file1.txt', 'some contents', 'master', 'Added new file', null, '[email protected]', 'GitLab User'));
561+
}
562+
534563
/**
535564
* @test
536565
*/
@@ -546,7 +575,9 @@ public function shouldUpdateFile()
546575
'branch_name' => 'master',
547576
'encoding' => null,
548577
'content' => 'some new contents',
549-
'commit_message' => 'Updated new file'
578+
'commit_message' => 'Updated new file',
579+
'author_email' => null,
580+
'author_name' => null,
550581
))
551582
->will($this->returnValue($expectedArray))
552583
;
@@ -569,14 +600,41 @@ public function shouldUpdateFileWithEncoding()
569600
'branch_name' => 'master',
570601
'encoding' => 'base64',
571602
'content' => 'some new contents',
572-
'commit_message' => 'Updated file'
603+
'commit_message' => 'Updated file',
604+
'author_email' => null,
605+
'author_name' => null,
573606
))
574607
->will($this->returnValue($expectedArray))
575608
;
576609

577610
$this->assertEquals($expectedArray, $api->updateFile(1, 'dir/file1.txt', 'some new contents', 'master', 'Updated file', 'base64'));
578611
}
579612

613+
/**
614+
* @test
615+
*/
616+
public function shouldUpdateFileWithAuthor()
617+
{
618+
$expectedArray = array('file_name' => 'file1.txt', 'file_path' => 'dir/file1.txt');
619+
620+
$api = $this->getApiMock();
621+
$api->expects($this->once())
622+
->method('put')
623+
->with('projects/1/repository/files', array(
624+
'file_path' => 'dir/file1.txt',
625+
'branch_name' => 'master',
626+
'encoding' => null,
627+
'content' => 'some new contents',
628+
'commit_message' => 'Updated file',
629+
'author_email' => '[email protected]',
630+
'author_name' => 'GitLab User',
631+
))
632+
->will($this->returnValue($expectedArray))
633+
;
634+
635+
$this->assertEquals($expectedArray, $api->updateFile(1, 'dir/file1.txt', 'some new contents', 'master', 'Updated file', null, '[email protected]', 'GitLab User'));
636+
}
637+
580638
/**
581639
* @test
582640
*/
@@ -587,13 +645,42 @@ public function shouldDeleteFile()
587645
$api = $this->getApiMock();
588646
$api->expects($this->once())
589647
->method('delete')
590-
->with('projects/1/repository/files', array('file_path' => 'dir/file1.txt', 'branch_name' => 'master', 'commit_message' => 'Deleted file'))
648+
->with('projects/1/repository/files', array(
649+
'file_path' => 'dir/file1.txt',
650+
'branch_name' => 'master',
651+
'commit_message' => 'Deleted file',
652+
'author_email' => null,
653+
'author_name' => null,
654+
))
591655
->will($this->returnValue($expectedBool))
592656
;
593657

594658
$this->assertEquals($expectedBool, $api->deleteFile(1, 'dir/file1.txt', 'master', 'Deleted file'));
595659
}
596660

661+
/**
662+
* @test
663+
*/
664+
public function shouldDeleteFileWithAuthor()
665+
{
666+
$expectedBool = true;
667+
668+
$api = $this->getApiMock();
669+
$api->expects($this->once())
670+
->method('delete')
671+
->with('projects/1/repository/files', array(
672+
'file_path' => 'dir/file1.txt',
673+
'branch_name' => 'master',
674+
'commit_message' => 'Deleted file',
675+
'author_email' => '[email protected]',
676+
'author_name' => 'GitLab User',
677+
))
678+
->will($this->returnValue($expectedBool))
679+
;
680+
681+
$this->assertEquals($expectedBool, $api->deleteFile(1, 'dir/file1.txt', 'master', 'Deleted file', '[email protected]', 'GitLab User'));
682+
}
683+
597684
/**
598685
* @test
599686
*/
@@ -618,4 +705,4 @@ protected function getApiClass()
618705
{
619706
return 'Gitlab\Api\Repositories';
620707
}
621-
}
708+
}

0 commit comments

Comments
 (0)