contents.php
5.49 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<?php
/**
* @package Joomla.Platform
* @subpackage GitHub
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* GitHub API Repositories Contents class for the Joomla Platform.
*
* These API methods let you retrieve the contents of files within a repository as Base64 encoded content.
* See media types for requesting raw or other formats.
*
* @documentation https://developer.github.com/v3/repos/contents
*
* @since 1.7.3
* @deprecated 4.0 Use the `joomla/github` package via Composer instead
*/
class JGithubPackageRepositoriesContents extends JGithubPackage
{
/**
* Get the README
*
* This method returns the preferred README for a repository.
*
* GET /repos/:owner/:repo/readme
*
* Parameters
*
* ref
* Optional string - The String name of the Commit/Branch/Tag. Defaults to master.
*
* Response
*
* Status: 200 OK
* X-RateLimit-Limit: 5000
* X-RateLimit-Remaining: 4999
*
* {
* "type": "file",
* "encoding": "base64",
* "_links": {
* "git": "https://api.github.com/repos/octokit/octokit.rb/git/blobs/3d21ec53a331a6f037a91c368710b99387d012c1",
* "self": "https://api.github.com/repos/octokit/octokit.rb/contents/README.md",
* "html": "https://github.com/octokit/octokit.rb/blob/master/README.md"
* },
* "size": 5362,
* "name": "README.md",
* "path": "README.md",
* "content": "encoded content ...",
* "sha": "3d21ec53a331a6f037a91c368710b99387d012c1"
* }
*
* @param string $owner The name of the owner of the GitHub repository.
* @param string $repo The name of the GitHub repository.
* @param string $ref The String name of the Commit/Branch/Tag. Defaults to master.
*
* @since 3.3 (CMS)
*
* @return object
*/
public function getReadme($owner, $repo, $ref = '')
{
// Build the request path.
$path = '/repos/' . $owner . '/' . $repo . '/readme';
if ($ref)
{
$path .= '?ref=' . $ref;
}
// Send the request.
return $this->processResponse(
$this->client->get($this->fetchUrl($path))
);
}
/**
* Get contents
*
* This method returns the contents of any file or directory in a repository.
*
* GET /repos/:owner/:repo/contents/:path
*
* Parameters
*
* path
* Optional string - The content path.
* ref
* Optional string - The String name of the Commit/Branch/Tag. Defaults to master.
*
* Response
*
* Status: 200 OK
* X-RateLimit-Limit: 5000
* X-RateLimit-Remaining: 4999
*
* {
* "type": "file",
* "encoding": "base64",
* "_links": {
* "git": "https://api.github.com/repos/octokit/octokit.rb/git/blobs/3d21ec53a331a6f037a91c368710b99387d012c1",
* "self": "https://api.github.com/repos/octokit/octokit.rb/contents/README.md",
* "html": "https://github.com/octokit/octokit.rb/blob/master/README.md"
* },
* "size": 5362,
* "name": "README.md",
* "path": "README.md",
* "content": "encoded content ...",
* "sha": "3d21ec53a331a6f037a91c368710b99387d012c1"
* }
*
* @param string $owner The name of the owner of the GitHub repository.
* @param string $repo The name of the GitHub repository.
* @param string $path The content path.
* @param string $ref The String name of the Commit/Branch/Tag. Defaults to master.
*
* @since 3.3 (CMS)
*
* @return object
*/
public function get($owner, $repo, $path, $ref = '')
{
// Build the request path.
$rPath = '/repos/' . $owner . '/' . $repo . '/contents/' . $path;
if ($ref)
{
$rPath .= '?ref=' . $ref;
}
// Send the request.
return $this->processResponse(
$this->client->get($this->fetchUrl($rPath))
);
}
/**
* Get archive link
*
* This method will return a 302 to a URL to download a tarball or zipball archive for a repository.
* Please make sure your HTTP framework is configured to follow redirects or you will need to use the Location header to make a second GET request.
*
* Note: For private repositories, these links are temporary and expire quickly.
*
* GET /repos/:owner/:repo/:archive_format/:ref
*
* Parameters
*
* archive_format
* Either tarball or zipball
* ref
* Optional string - valid Git reference, defaults to master
*
* Response
*
* Status: 302 Found
* Location: http://github.com/me/myprivate/tarball/master?SSO=thistokenexpires
* X-RateLimit-Limit: 5000
* X-RateLimit-Remaining: 4999
*
* To follow redirects with curl, use the -L switch:
*
* curl -L https://api.github.com/repos/octokit/octokit.rb/tarball > octokit.tar.gz
*
* @param string $owner The name of the owner of the GitHub repository.
* @param string $repo The name of the GitHub repository.
* @param string $archive_format Either tarball or zipball.
* @param string $ref The String name of the Commit/Branch/Tag. Defaults to master.
*
* @throws UnexpectedValueException
* @since 3.3 (CMS)
*
* @return object
*/
public function getArchiveLink($owner, $repo, $archive_format = 'zipball', $ref = '')
{
if (false == in_array($archive_format, array('tarball', 'zipball')))
{
throw new UnexpectedValueException('Archive format must be either "tarball" or "zipball".');
}
// Build the request path.
$path = '/repos/' . $owner . '/' . $repo . '/' . $archive_format;
if ($ref)
{
$path .= '?ref=' . $ref;
}
// Send the request.
return $this->processResponse(
$this->client->get($this->fetchUrl($path)),
302
);
}
}