Skip to content

Commit

Permalink
update all other github request header check to regex match
Browse files Browse the repository at this point in the history
  • Loading branch information
gq1 committed Sep 24, 2024
1 parent 00c7a9c commit 8738fd5
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion public_html/launch.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function launch_pipeline_web($pipeline, $release) {
$gh_launch_schema_url = "https://api.github.com/repos/sanger-tol/{$pipeline}/contents/nextflow_schema.json?ref={$gh_launch_schema_url}";
$gh_launch_schema_json = file_get_contents($gh_launch_schema_url, false, $api_opts);

if (strpos($http_response_header[0], 'HTTP/1.1 200') === false) {
if (preg_match('/HTTP\/\d\.*\d* 200/', $http_response_header[0]) === false) {
# Remember for next time
file_put_contents($gh_pipeline_no_schema_fn, '');
echo '<script>console.log("Sent request to ' .
Expand Down
8 changes: 4 additions & 4 deletions public_html/pipeline_health.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,12 @@ public function get_branch_data() {
$gh_branch_url =
'https://api.github.com/repos/sanger-tol/' . basename($this->name) . '/branches/' . $branch . '/protection';
$gh_branch = json_decode(@file_get_contents($gh_branch_url, false, GH_API_OPTS));
if (strpos($http_response_header[0], 'HTTP/1.0 200') !== false && is_object($gh_branch)) {
if (preg_match('/HTTP\/\d\.*\d* 200/', $http_response_header[0]) !== false && is_object($gh_branch)) {
$this->{'gh_branch_' . $branch} = $gh_branch;
$this->_save_cache_data($gh_branch_cache, $this->{'gh_branch_' . $branch});
} else {
// Write an empty cache file
if (strpos($http_response_header[0], 'HTTP/1.0 404') === false) {
if (preg_match('/HTTP\/\d\.*\d* 404/', $http_response_header[0]) === false) {
// A 404 is fine, that just means that there is no branch protection. Warn if anything else.
$gh_branch = htmlspecialchars($gh_branch, ENT_QUOTES, 'UTF-8');
echo '<div class="alert alert-danger">Could not fetch branch protection data for <code>' .
Expand Down Expand Up @@ -555,9 +555,9 @@ public function _send_gh_api_data($url, $content, $method = 'POST') {
],
]);
$result = json_decode(file_get_contents($url, false, $context));
if (strpos($http_response_header[0], 'HTTP/1.0 204') !== false) {
if (preg_match('/HTTP\/\d\.*\d* 204/', $http_response_header[0]) !== false) {
return true;
} elseif (strpos($http_response_header[0], 'HTTP/1.0 200') !== false) {
} elseif (preg_match('/HTTP\/\d\.*\d* 200/', $http_response_header[0]) !== false) {
return $result;
} else {
echo '<div class="alert alert-danger m-3">
Expand Down
4 changes: 2 additions & 2 deletions update_issue_stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
}
$num_api_calls += 1;
$gh_issues = json_decode(file_get_contents($gh_issues_url, false, $gh_api_opts), true);
if (strpos($http_response_header[0], 'HTTP/1.0 200') === false) {
if (preg_match('/HTTP\/\d\.*\d* 200/', $http_response_header[0]) === false) {
var_dump($http_response_header);
echo "\nCould not fetch nf-core/$repo issues! $gh_issues_url\n";
continue;
Expand Down Expand Up @@ -269,7 +269,7 @@
$num_api_calls += 1;
$gh_new_comments = json_decode(file_get_contents($gh_comments_url, false, $gh_api_opts), true);
$gh_comments = array_merge($gh_comments, $gh_new_comments);
if (strpos($http_response_header[0], 'HTTP/1.0 200') === false) {
if (preg_match('/HTTP\/\d\.*\d* 200/', $http_response_header[0]) === false) {
var_dump($http_response_header);
echo "\nCould not fetch nf-core/$repo issue #$id! $gh_comments_url\n";
continue;
Expand Down
2 changes: 1 addition & 1 deletion update_module_details.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function github_query($gh_query_url) {
$gh_query_url = $next_page;
}
$tmp_results = json_decode(file_get_contents($gh_query_url, false, $gh_api_opts), true);
if (strpos($http_response_header[0], 'HTTP/1.0 200') === false) {
if (preg_match('/HTTP\/\d\.*\d* 200/', $http_response_header[0]) === false) {
var_dump($http_response_header);
echo "\nCould not fetch $gh_query_url";
continue;
Expand Down
2 changes: 1 addition & 1 deletion update_pipeline_details.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function get_gh_api($gh_api_url) {
$gh_api_url = $next_page;
}
$tmp_results = json_decode(file_get_contents($gh_api_url, false, $gh_api_opts));
if (strpos($http_response_header[0], 'HTTP/1.0 200') === false) {
if (preg_match('/HTTP\/\d\.*\d* 200/', $http_response_header[0]) === false) {
die("\n-------- START ERROR " . date('Y-m-d h:i:s') . " --------\nCould not fetch $gh_api_url \n");
var_dump($http_response_header);
echo "\n$tmp_results\n";
Expand Down
26 changes: 13 additions & 13 deletions update_stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ function github_query($gh_query_url) {
// If the data hasn't been cached when you query a repository's statistics, you'll receive a 202 response;
// a background job is also fired to start compiling these statistics.
// Give the job a few moments to complete, and then submit the request again
if (strpos($http_response_header[0], 'HTTP/1.0 202') !== false) {
if (preg_match('/HTTP\/\d\.*\d* 202/', $http_response_header[0]) !== false) {
echo "Waiting for GitHub API to return results for $gh_query_url \n";
sleep(10);
$first_page = true;
continue;
}
if (strpos($http_response_header[0], 'HTTP/1.0 200') === false) {
if (preg_match('/HTTP\/\d\.*\d* 200/', $http_response_header[0]) === false) {
var_dump($http_response_header);
echo "\nCould not fetch $gh_query_url";
continue;
Expand Down Expand Up @@ -357,7 +357,7 @@ function github_query($gh_query_url) {
$gh_members_url = $next_page;
}
$gh_members = json_decode(file_get_contents($gh_members_url, false, $gh_api_opts));
if (strpos($http_response_header[0], 'HTTP/1.0 200') === false) {
if (preg_match('/HTTP\/\d\.*\d* 200/', $http_response_header[0]) === false) {
var_dump($http_response_header);
echo "Could not fetch nf-core members! $gh_members_url";
continue;
Expand All @@ -378,7 +378,7 @@ function github_query($gh_query_url) {
echo "Get the list of repos from Github\n";
$gh_repos_url = 'https://api.github.com/orgs/sanger-tol/repos?per_page=100';
$gh_repos = json_decode(file_get_contents($gh_repos_url, false, $gh_api_opts));
if (strpos($http_response_header[0], 'HTTP/1.0 200') === false) {
if (preg_match('/HTTP\/\d\.*\d* 200/', $http_response_header[0]) === false) {
var_dump($http_response_header);
die("Could not fetch nf-core repositories! $gh_repos_url");
}
Expand Down Expand Up @@ -410,7 +410,7 @@ function github_query($gh_query_url) {
// Annoyingly, two values are only available if we query for just this repo
$gh_repo_url = 'https://api.github.com/repos/sanger-tol/' . basename($repo->name);
$gh_repo = json_decode(file_get_contents($gh_repo_url, false, $gh_api_opts));
if (strpos($http_response_header[0], 'HTTP/1.0 200') === false) {
if (preg_match('/HTTP\/\d\.*\d* 200/', $http_response_header[0]) === false) {
var_dump($http_response_header);
echo "Could not fetch nf-core repo! $gh_repo_url";
continue;
Expand All @@ -428,9 +428,9 @@ function github_query($gh_query_url) {
// Views
$gh_views_url = 'https://api.github.com/repos/sanger-tol/' . $repo_name . '/traffic/views';
$gh_views = json_decode(file_get_contents($gh_views_url, false, $gh_api_opts));
if (strpos($http_response_header[0], 'HTTP/1.0 200') === false) {
if (preg_match('/HTTP\/\d\.*\d* 200/', $http_response_header[0]) === false) {
// Pipelines are removed from the cache earlier as we know their names
if ($repo_type == 'core_repos' && strpos($http_response_header[0], 'HTTP/1.0 404') !== false) {
if ($repo_type == 'core_repos' && preg_match('/HTTP\/\d\.*\d* 404/', $http_response_header[0]) !== false) {
echo 'Removing ' . $repo_name . " from the cached results as it appears to have been deleted.\n";
unset($results['core_repos'][$repo_name]);
} else {
Expand All @@ -447,7 +447,7 @@ function github_query($gh_query_url) {
// Clones
$gh_clones_url = 'https://api.github.com/repos/sanger-tol/' . $repo_name . '/traffic/clones';
$gh_clones = json_decode(file_get_contents($gh_clones_url, false, $gh_api_opts));
if (strpos($http_response_header[0], 'HTTP/1.0 200') === false) {
if (preg_match('/HTTP\/\d\.*\d* 200/', $http_response_header[0]) === false) {
var_dump($http_response_header);
echo "Could not fetch nf-core repo clones! $gh_clones_url";
continue;
Expand All @@ -464,12 +464,12 @@ function github_query($gh_query_url) {
// If the data hasn't been cached when you query a repository's statistics, you'll receive a 202 response;
// a background job is also fired to start compiling these statistics.
// Give the job a few moments to complete, and then submit the request again
if (strpos($http_response_header[0], 'HTTP/1.0 202') !== false) {
if (preg_match('/HTTP\/\d\.*\d* 202/', $http_response_header[0]) !== false) {
$contribs_try_again[$repo_name] = [
'repo_type' => $repo_type,
'gh_contributors_url' => $gh_contributors_url,
];
} elseif (strpos($http_response_header[0], 'HTTP/1.0 200') === false) {
} elseif (preg_match('/HTTP\/\d\.*\d* 200/', $http_response_header[0]) === false) {
var_dump($http_response_header);
echo "Could not fetch nf-core repo contributors! $gh_contributors_url";
continue;
Expand Down Expand Up @@ -509,10 +509,10 @@ function github_query($gh_query_url) {
$gh_contributors_raw = file_get_contents($gh_contributors_url, false, $gh_api_opts);
file_put_contents($contribs_fn_root . $repo_name . '.json', $gh_contributors_raw);
$gh_contributors = json_decode($gh_contributors_raw);
if (strpos($http_response_header[0], 'HTTP/1.0 202') !== false) {
if (preg_match('/HTTP\/\d\.*\d* 202/', $http_response_header[0]) !== false) {
echo "Tried getting contributors after delay for $repo_name, but took too long.\n";
continue;
} elseif (strpos($http_response_header[0], 'HTTP/1.0 200') === false) {
} elseif (preg_match('/HTTP\/\d\.*\d* 200/', $http_response_header[0]) === false) {
var_dump($http_response_header);
echo "Could not fetch nf-core repo contributors! $gh_contributors_url";
continue;
Expand Down Expand Up @@ -579,7 +579,7 @@ function github_query($gh_query_url) {
],
]);
$slack_users = json_decode(file_get_contents($slack_api_url, false, $slack_api_opts));
if (strpos($http_response_header[0], 'HTTP/1.0 200') === false || !isset($slack_users->ok) || !$slack_users->ok) {
if (preg_match('/HTTP\/\d\.*\d* 200/', $http_response_header[0]) === false || !isset($slack_users->ok) || !$slack_users->ok) {
var_dump($http_response_header);
echo 'Could not fetch slack user list!';
} else {
Expand Down

0 comments on commit 8738fd5

Please sign in to comment.