Skip to content

Commit 2148472

Browse files
committed
Restore the services/apiref/issue method
1 parent 9019be4 commit 2148472

File tree

5 files changed

+61
-20
lines changed

5 files changed

+61
-20
lines changed

etc/webhooks/postcommit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ def deploy(git_revision):
220220
else "none"
221221
)
222222
assert signature[:5] == "sha1="
223-
223+
224224
print "Your request body is:"
225225
print
226226
print body
@@ -254,7 +254,7 @@ def deploy(git_revision):
254254
if data['ref'] != "refs/heads/master":
255255
print "These commits did not change the 'master' branch. Aborting."
256256
sys.exit(0)
257-
257+
258258
new_revision = data['after']
259259
filenames = []
260260
for commit_data in data['commits']:

okapi/services/apiref/issue.php

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use okapi\OkapiServiceRunner;
1313
use okapi\OkapiInternalRequest;
1414
use okapi\Cache;
15+
use okapi\Settings;
1516

1617
class WebService
1718
{
@@ -30,17 +31,53 @@ public static function call(OkapiRequest $request)
3031
if ((!preg_match("/^[0-9]+$/", $issue_id)) || (strlen($issue_id) > 6))
3132
throw new InvalidParam('issue_id');
3233

33-
# In October 2013, Google Code feed at:
34-
# http://code.google.com/feeds/issues/p/opencaching-api/issues/$issue_id/comments/full
35-
# stopped working. We are forced to respond with a simple placeholder.
34+
$cache_key = "apiref/issue#".$issue_id;
35+
$result = Cache::get($cache_key);
36+
if ($result == null)
37+
{
38+
# Download the number of comments from GitHub Issue Tracker.
3639

37-
$result = array(
38-
'id' => $issue_id + 0,
39-
'last_updated' => null,
40-
'title' => null,
41-
'url' => "https://github.com/opencaching/okapi/issues/".$issue_id,
42-
'comment_count' => null
43-
);
40+
try
41+
{
42+
$extra_headers = array();
43+
$extra_headers[] = "Accept: application/vnd.github.v3.html+json";
44+
$extra_headers[] = "User-Agent: https://github.com/opencaching/okapi/";
45+
if (Settings::get('GITHUB_ACCESS_TOKEN')) {
46+
$extra_headers[] = "Authorization: token ".Settings::get('GITHUB_ACCESS_TOKEN');
47+
}
48+
$opts = array(
49+
'http' => array(
50+
'method' => "GET",
51+
'timeout' => 2.0,
52+
'header' => implode("\r\n", $extra_headers),
53+
)
54+
);
55+
$context = stream_context_create($opts);
56+
$json = file_get_contents("https://api.github.com/repos/opencaching/okapi/issues/$issue_id",
57+
false, $context);
58+
}
59+
catch (ErrorException $e)
60+
{
61+
throw new BadRequest("Sorry, we could not retrieve issue stats from the GitHub site. ".
62+
"This is probably due to a temporary connection problem. Try again later or contact ".
63+
"us if this seems permanent.");
64+
}
65+
66+
$doc = json_decode($json, true);
67+
$result = array(
68+
'id' => $issue_id + 0,
69+
'last_updated' => $doc['updated_at'],
70+
'title' => $doc['title'],
71+
'url' => $doc['html_url'],
72+
'comment_count' => $doc['comments']
73+
);
74+
75+
# On one hand, we want newly added comments to show up quickly.
76+
# On the other, we don't want OKAPI to spam GitHub with queries.
77+
# So it's difficult to choose the best timeout for this.
78+
79+
Cache::set($cache_key, $result, 3600);
80+
}
4481
return Okapi::formatted_response($request, $result);
4582
}
4683
}

okapi/services/apiref/issue.xml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@
22
<brief>Retrieve information on given issue</brief>
33
<issue-id>11</issue-id>
44
<desc>
5-
<p><b>Important:</b> This method stopped working properly in October 2013.
6-
Now, it returns a simple placeholder.
7-
<a href='https://github.com/opencaching/okapi/issues/288'>Read more</a>.</p>
8-
95
<p>OKAPI is trying to be as <b>integrated</b> with its
106
<a href='https://github.com/opencaching/okapi/'>Main Project Page</a> as it can.
117
This method retrieves basic information on a given issue from our project
12-
<a href='https://github.com/opencaching/okapi/issues/'>Issue Tracker</a>.
8+
<a href='https://github.com/opencaching/okapi/issues/'>Issue Tracker</a>
9+
(currently GitHub).
1310
In future, it <b>might</b> also return some of the latest comments (we're not yet
1411
sure if we want them displayed on our documentation pages).</p>
1512
</desc>

okapi/services/apisrv/installation.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
<p><b>okapi_version_number</b> - integer; the version number of
2828
the OKAPI instance installed on this Opencaching site, <b>or
2929
null</b>, if the version number could not be determined.</p>
30-
30+
3131
<p>The version number will be incremented with each new
3232
revision of OKAPI (that is, after every commit to OKAPI
3333
repository).</p>
34-
34+
3535
<p>You can use it to check if this OKAPI installation will be
3636
compatbile with your client application: if the number is
3737
equal to or higher than the one you have expected, then it will
@@ -40,7 +40,7 @@
4040
<li>
4141
<p><b>okapi_revision</b> - this is an older alias of
4242
<b>okapi_version_number</b>.</p>
43-
43+
4444
<p>For a number of years, OKAPI used SVN for version control.
4545
SVN uses integers for commit IDs. Hence, version numbers and
4646
revision numbers were exactly the same thing. (In fact, the

okapi/settings.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,13 @@ final class Settings
172172
* suspicious activity of some certain users.
173173
*/
174174
'OCPL_ENABLE_GEOCACHE_ACCESS_LOGS' => false,
175+
176+
/**
177+
* GitHub access token. If given, it will allow OKAPI to make more
178+
* frequent queries to the GitHub API (e.g. in the services/apiref/issue
179+
* method). Providing this is not required, but it is highly recommended.
180+
*/
181+
'GITHUB_ACCESS_TOKEN' => null,
175182
);
176183

177184
/**

0 commit comments

Comments
 (0)