Skip to content

Commit 39c5db6

Browse files
committed
Merge branch 'master' into feature/native-searchtools
# Conflicts: # administrator/components/com_patchtester/PatchTester/Model/PullsModel.php # administrator/components/com_patchtester/PatchTester/View/Pulls/PullsHtmlView.php # administrator/components/com_patchtester/language/en-GB/com_patchtester.ini
2 parents 2f62b57 + 869d6fd commit 39c5db6

File tree

131 files changed

+2593
-986
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+2593
-986
lines changed

.github/workflows/crowdin-wf.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Crowdin Action
2+
# Controls when the action will run.
3+
on:
4+
schedule:
5+
- cron: '43 * * * *'
6+
7+
# Allows you to run this workflow manually from the Actions tab
8+
workflow_dispatch:
9+
10+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
11+
jobs:
12+
# This workflow contains a single job called "build"
13+
synchronize-with-crowdin:
14+
# The type of runner that the job will run on
15+
runs-on: ubuntu-latest
16+
17+
# Steps represent a sequence of tasks that will be executed as part of the job
18+
steps:
19+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
20+
- name: Checkout
21+
uses: actions/checkout@v2
22+
23+
# Runs the Crowdin action command - https://github.com/crowdin/github-action
24+
- name: crowdin action
25+
uses: crowdin/github-action@1.1.2
26+
with:
27+
# Upload sources to Crowdin
28+
upload_sources: true
29+
# Upload translations to Crowdin, only use true at initial run
30+
upload_translations: false
31+
# Make pull request of Crowdin translations
32+
download_translations: true
33+
# Only download translated strings
34+
skip_untranslated_strings: false
35+
# Download translations with pushing to branch
36+
push_translations: true
37+
# To download translations to the specified version branch
38+
localization_branch_name: 'l10n_crowdin_translations'
39+
# Create pull request after pushing to branch
40+
create_pull_request: true
41+
# Configuration file to use
42+
config: 'crowdin.yml'
43+
# Use true for dryrun to test the run without actually processing anything
44+
dryrun_action: false
45+
env:
46+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
47+
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Patch Tester [![Build Status](https://ci.joomla.org/api/badges/joomla-extensions/patchtester/status.svg)](https://ci.joomla.org/joomla-extensions/patchtester)
2-
[![Crowdin](https://badges.crowdin.net/e/fc3dad2620189bfc76653c4d0b71c9ab/localized.svg)](https://joomla.crowdin.com/patch-tester-extension)
2+
[![Crowdin](https://badges.crowdin.net/e/f166ad1cd11fb51fd49eb6a863f64f08/localized.svg)](https://joomla.crowdin.com/joomla-official-extensions)
33
=============
44

55
* [In English](#license)
@@ -43,7 +43,7 @@ To use an account that has two factor authentication enabled, you'll have to [cr
4343
Translations
4444
=============
4545

46-
Translations for the patch tester component are managed on [Crowdin](https://joomla.crowdin.com/patch-tester-extension).
46+
Translations for the patch tester component are managed on [Crowdin](https://joomla.crowdin.com/joomla-official-extensions).
4747

4848

4949
fr-FR - Patch Tester en français

administrator/components/com_patchtester/PatchTester/GitHub/GitHub.php

Lines changed: 123 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,71 @@ public function __construct(Registry $options = null, Http $client = null)
5151
$this->client = $client ?: HttpFactory::getHttp($options);
5252
}
5353

54+
/**
55+
* Get the HTTP client for this connector.
56+
*
57+
* @return Http
58+
*
59+
* @since 3.0.0
60+
*/
61+
public function getClient()
62+
{
63+
return $this->client;
64+
}
65+
66+
/**
67+
* Get the diff for a pull request.
68+
*
69+
* @param string $user The name of the owner of the GitHub repository.
70+
* @param string $repo The name of the GitHub repository.
71+
* @param integer $pullId The pull request number.
72+
*
73+
* @return Response
74+
*
75+
* @since 3.0.0
76+
*/
77+
public function getDiffForPullRequest($user, $repo, $pullId)
78+
{
79+
// Build the request path.
80+
$path = "/repos/$user/$repo/pulls/" . (int) $pullId;
81+
82+
// Build the request headers.
83+
$headers = array('Accept' => 'application/vnd.github.diff');
84+
85+
$prepared = $this->prepareRequest($path, 0, 0, $headers);
86+
87+
return $this->processResponse(
88+
$this->client->get($prepared['url'], $prepared['headers'])
89+
);
90+
}
91+
92+
/**
93+
* Method to build and return a full request URL for the request.
94+
*
95+
* This method will add appropriate pagination details if necessary and also prepend the API url to have a complete URL for the request.
96+
*
97+
* @param string $path Path to process
98+
* @param integer $page Page to request
99+
* @param integer $limit Number of results to return per page
100+
* @param array $headers The headers to send with the request
101+
*
102+
* @return array Associative array containing the prepared URL and request headers
103+
*
104+
* @since 3.0.0
105+
*/
106+
protected function prepareRequest($path, $page = 0, $limit = 0,
107+
array $headers = array()
108+
) {
109+
$url = $this->fetchUrl($path, $page, $limit);
110+
111+
if ($token = $this->options->get('gh.token', false))
112+
{
113+
$headers['Authorization'] = "token $token";
114+
}
115+
116+
return array('url' => $url, 'headers' => $headers);
117+
}
118+
54119
/**
55120
* Build and return a full request URL.
56121
*
@@ -70,27 +135,6 @@ protected function fetchUrl($path, $page = 0, $limit = 0)
70135
// Get a new Uri object using the API URL and given path.
71136
$uri = new Uri($this->options->get('api.url') . $path);
72137

73-
// Only apply basic authentication if an access token is not set
74-
if ($this->options->get('gh.token', false) === false)
75-
{
76-
// Use basic authentication
77-
if ($this->options->get('api.username', false))
78-
{
79-
$username = $this->options->get('api.username');
80-
$username = str_replace('@', '%40', $username);
81-
$username = str_replace('#', '%23', $username);
82-
$uri->setUser($username);
83-
}
84-
85-
if ($this->options->get('api.password', false))
86-
{
87-
$password = $this->options->get('api.password');
88-
$password = str_replace('@', '%40', $password);
89-
$password = str_replace('#', '%23', $password);
90-
$uri->setPass($password);
91-
}
92-
}
93-
94138
// If we have a defined page number add it to the JUri object.
95139
if ($page > 0)
96140
{
@@ -107,39 +151,32 @@ protected function fetchUrl($path, $page = 0, $limit = 0)
107151
}
108152

109153
/**
110-
* Get the HTTP client for this connector.
111-
*
112-
* @return Http
113-
*
114-
* @since 3.0.0
115-
*/
116-
public function getClient()
117-
{
118-
return $this->client;
119-
}
120-
121-
/**
122-
* Get the diff for a pull request.
154+
* Process the response and return it.
123155
*
124-
* @param string $user The name of the owner of the GitHub repository.
125-
* @param string $repo The name of the GitHub repository.
126-
* @param integer $pullId The pull request number.
156+
* @param Response $response The response.
157+
* @param integer $expectedCode The expected response code.
127158
*
128159
* @return Response
129160
*
130161
* @since 3.0.0
162+
* @throws Exception\UnexpectedResponse
131163
*/
132-
public function getDiffForPullRequest($user, $repo, $pullId)
164+
protected function processResponse(Response $response, $expectedCode = 200)
133165
{
134-
// Build the request path.
135-
$path = "/repos/$user/$repo/pulls/" . (int) $pullId;
136-
137-
// Build the request headers.
138-
$headers = array('Accept' => 'application/vnd.github.diff');
166+
// Validate the response code.
167+
if ($response->code != $expectedCode)
168+
{
169+
// Decode the error response and throw an exception.
170+
$body = json_decode($response->body);
171+
$error = isset($body->error) ? $body->error
172+
: (isset($body->message) ? $body->message : 'Unknown Error');
139173

140-
$prepared = $this->prepareRequest($path, 0, 0, $headers);
174+
throw new Exception\UnexpectedResponse(
175+
$response, $error, $response->code
176+
);
177+
}
141178

142-
return $this->processResponse($this->client->get($prepared['url'], $prepared['headers']));
179+
return $response;
143180
}
144181

145182
/**
@@ -168,7 +205,9 @@ public function getFileContents($user, $repo, $path, $ref = null)
168205
$prepared['url'] = (string) $url;
169206
}
170207

171-
return $this->processResponse($this->client->get($prepared['url'], $prepared['headers']));
208+
return $this->processResponse(
209+
$this->client->get($prepared['url'], $prepared['headers'])
210+
);
172211
}
173212

174213
/**
@@ -189,7 +228,9 @@ public function getFilesForPullRequest($user, $repo, $pullId)
189228

190229
$prepared = $this->prepareRequest($path);
191230

192-
return $this->processResponse($this->client->get($prepared['url'], $prepared['headers']));
231+
return $this->processResponse(
232+
$this->client->get($prepared['url'], $prepared['headers'])
233+
);
193234
}
194235

195236
/**
@@ -206,9 +247,36 @@ public function getFilesForPullRequest($user, $repo, $pullId)
206247
*/
207248
public function getOpenIssues($user, $repo, $page = 0, $limit = 0)
208249
{
209-
$prepared = $this->prepareRequest("/repos/$user/$repo/issues", $page, $limit);
250+
$prepared = $this->prepareRequest(
251+
"/repos/$user/$repo/issues", $page, $limit
252+
);
253+
254+
return $this->processResponse(
255+
$this->client->get($prepared['url'], $prepared['headers'])
256+
);
257+
}
258+
259+
/**
260+
* Get a list of the open pull requests for a repository.
261+
*
262+
* @param string $user The name of the owner of the GitHub repository.
263+
* @param string $repo The name of the GitHub repository.
264+
* @param integer $page The page number from which to get items.
265+
* @param integer $limit The number of items on a page.
266+
*
267+
* @return Response
268+
*
269+
* @since 3.0.0
270+
*/
271+
public function getOpenPulls($user, $repo, $page = 0, $limit = 0)
272+
{
273+
$prepared = $this->prepareRequest(
274+
"/repos/$user/$repo/pulls", $page, $limit
275+
);
210276

211-
return $this->processResponse($this->client->get($prepared['url'], $prepared['headers']));
277+
return $this->processResponse(
278+
$this->client->get($prepared['url'], $prepared['headers'])
279+
);
212280
}
213281

214282
/**
@@ -244,7 +312,9 @@ public function getPullRequest($user, $repo, $pullId)
244312

245313
$prepared = $this->prepareRequest($path);
246314

247-
return $this->processResponse($this->client->get($prepared['url'], $prepared['headers']));
315+
return $this->processResponse(
316+
$this->client->get($prepared['url'], $prepared['headers'])
317+
);
248318
}
249319

250320
/**
@@ -258,59 +328,9 @@ public function getRateLimit()
258328
{
259329
$prepared = $this->prepareRequest('/rate_limit');
260330

261-
return $this->processResponse($this->client->get($prepared['url'], $prepared['headers']));
262-
}
263-
264-
/**
265-
* Process the response and return it.
266-
*
267-
* @param Response $response The response.
268-
* @param integer $expectedCode The expected response code.
269-
*
270-
* @return Response
271-
*
272-
* @since 3.0.0
273-
* @throws Exception\UnexpectedResponse
274-
*/
275-
protected function processResponse(Response $response, $expectedCode = 200)
276-
{
277-
// Validate the response code.
278-
if ($response->code != $expectedCode)
279-
{
280-
// Decode the error response and throw an exception.
281-
$body = json_decode($response->body);
282-
$error = isset($body->error) ? $body->error : (isset($body->message) ? $body->message : 'Unknown Error');
283-
284-
throw new Exception\UnexpectedResponse($response, $error, $response->code);
285-
}
286-
287-
return $response;
288-
}
289-
290-
/**
291-
* Method to build and return a full request URL for the request.
292-
*
293-
* This method will add appropriate pagination details if necessary and also prepend the API url to have a complete URL for the request.
294-
*
295-
* @param string $path Path to process
296-
* @param integer $page Page to request
297-
* @param integer $limit Number of results to return per page
298-
* @param array $headers The headers to send with the request
299-
*
300-
* @return array Associative array containing the prepared URL and request headers
301-
*
302-
* @since 3.0.0
303-
*/
304-
protected function prepareRequest($path, $page = 0, $limit = 0, array $headers = array())
305-
{
306-
$url = $this->fetchUrl($path, $page, $limit);
307-
308-
if ($token = $this->options->get('gh.token', false))
309-
{
310-
$headers['Authorization'] = "token $token";
311-
}
312-
313-
return array('url' => $url, 'headers' => $headers);
331+
return $this->processResponse(
332+
$this->client->get($prepared['url'], $prepared['headers'])
333+
);
314334
}
315335

316336
/**

administrator/components/com_patchtester/PatchTester/Helper.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,6 @@ public static function initializeGithub()
4848
{
4949
$options->set('headers', ['Authorization' => 'token ' . $params->get('gh_token', '')]);
5050
}
51-
// Set the username and password if set in the params
52-
elseif ($params->get('gh_user', '') && $params->get('gh_password'))
53-
{
54-
$options->set('api.username', $params->get('gh_user', ''));
55-
$options->set('api.password', $params->get('gh_password', ''));
56-
}
5751
// Display a message about the lowered API limit without credentials
5852
else
5953
{

0 commit comments

Comments
 (0)