Repository navigation
Expand file tree
/
Copy pathRepositoryFiles.php
More file actions
149 lines (134 loc) · 5.34 KB
/
Copy pathRepositoryFiles.php
File metadata and controls
149 lines (134 loc) · 5.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
declare(strict_types=1);
/*
* This file is part of the Gitlab API library.
*
* (c) Matt Humphrey <matth@windsor-telecom.co.uk>
* (c) Graham Campbell <hello@gjcampbell.co.uk>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Gitlab\Api;
use Symfony\Component\OptionsResolver\OptionsResolver;
class RepositoryFiles extends AbstractApi
{
/**
* @param int|string $project_id
* @param string $file_path
* @param string $ref
*
* @return mixed
*/
public function getFile($project_id, string $file_path, string $ref)
{
return $this->get($this->getProjectPath($project_id, 'repository/files/'.self::encodePath($file_path)), [
'ref' => $ref,
]);
}
/**
* @param int|string $project_id
* @param string $file_path
* @param string $ref
*
* @return mixed
*/
public function getRawFile($project_id, string $file_path, string $ref)
{
return $this->get($this->getProjectPath($project_id, 'repository/files/'.self::encodePath($file_path).'/raw'), [
'ref' => $ref,
]);
}
/**
* @param int|string $project_id
* @param array $parameters {
*
* @var string $file_path Url encoded full path to new file. Ex. lib%2Fclass%2Erb.
* @var string $branch name of the branch
* @var string $start_branch name of the branch to start the new commit from
* @var string $encoding change encoding to 'base64' (default is text)
* @var string $author_email specify the commit author's email address
* @var string $author_name specify the commit author's name
* @var string $content file content
* @var string $commit_message Commit message.
* }
*
* @return mixed
*/
public function createFile($project_id, array $parameters = [])
{
$resolver = new OptionsResolver();
$resolver->setRequired('file_path');
$resolver->setRequired('branch');
$resolver->setDefined('start_branch');
$resolver->setDefined('encoding')
->setAllowedValues('encoding', ['text', 'base64'])
;
$resolver->setDefined('author_email');
$resolver->setDefined('author_name');
$resolver->setRequired('content');
$resolver->setRequired('commit_message');
$resolved = $resolver->resolve($parameters);
return $this->post($this->getProjectPath($project_id, 'repository/files/'.self::encodePath($resolved['file_path'])), $resolved);
}
/**
* @param int|string $project_id
* @param array $parameters {
*
* @var string $file_path Url encoded full path to new file. Ex. lib%2Fclass%2Erb.
* @var string $branch name of the branch
* @var string $start_branch name of the branch to start the new commit from
* @var string $encoding change encoding to 'base64' (default is text)
* @var string $author_email specify the commit author's email address
* @var string $author_name specify the commit author's name
* @var string $content file content
* @var string $commit_message commit message
* @var string $last_commit_id last known file commit id
* }
*
* @return mixed
*/
public function updateFile($project_id, array $parameters = [])
{
$resolver = new OptionsResolver();
$resolver->setRequired('file_path');
$resolver->setRequired('branch');
$resolver->setDefined('start_branch');
$resolver->setDefined('encoding')
->setAllowedValues('encoding', ['text', 'base64'])
;
$resolver->setDefined('author_email');
$resolver->setDefined('author_name');
$resolver->setRequired('content');
$resolver->setRequired('commit_message');
$resolver->setDefined('last_commit_id');
$resolved = $resolver->resolve($parameters);
return $this->put($this->getProjectPath($project_id, 'repository/files/'.self::encodePath($resolved['file_path'])), $resolved);
}
/**
* @param int|string $project_id
* @param array $parameters {
*
* @var string $file_path Url encoded full path to new file. Ex. lib%2Fclass%2Erb.
* @var string $branch name of the branch
* @var string $start_branch name of the branch to start the new commit from
* @var string $author_email specify the commit author's email address
* @var string $author_name specify the commit author's name
* @var string $commit_message Commit message.
* }
*
* @return mixed
*/
public function deleteFile($project_id, array $parameters = [])
{
$resolver = new OptionsResolver();
$resolver->setRequired('file_path');
$resolver->setRequired('branch');
$resolver->setDefined('start_branch');
$resolver->setDefined('author_email');
$resolver->setDefined('author_name');
$resolver->setRequired('commit_message');
$resolved = $resolver->resolve($parameters);
return $this->delete($this->getProjectPath($project_id, 'repository/files/'.self::encodePath($resolved['file_path'])), $resolved);
}
}