Skip to content

Commit 321df08

Browse files
Changed the whole structure of the project.
1 parent 5c0d700 commit 321df08

File tree

5 files changed

+128
-50
lines changed

5 files changed

+128
-50
lines changed

code.php

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,38 @@
1717

1818
}
1919

20-
20+
print GITHUB_INSTRUCTION;
2121
print '<form name ="searchForm" method="post">';
2222
print '<div class="alert alert-secondary">
2323
Code Search
2424
<div class="input-group mb-3">
2525
<input name="searchTB" type="text" class="form-control" aria-label="Text input with segmented dropdown button" placeholder="keywords for search" value ="'.$searchTB_text.'" >
26+
<select class="custom-select" name="github_account" required>
27+
<option selected value="0">Choose GITHUB account</option>';
28+
foreach (GITHUB_CREDENTIALS as $key => $credential) {
29+
if(isset($_POST['github_account']) && $_POST['github_account'] == $key){$select_str = 'selected';}else{$select_str = '';}
30+
print '<option value="'.$key.'" '.$select_str.'>USERNAME: '.$credential['username'].', PASSWORD: '.substr($credential['password'], 0, 2).'*****'.substr($credential['password'], -2).'</option>';
31+
}
32+
33+
print '</select>
2634
<div class="input-group-append">
2735
<button name="searchButton" type="submit" class="btn btn-primary" value="1">Search</button>
2836
<button class="btn btn-success" type="button" data-toggle="collapse" data-target="#collapseAdvancedSearch" aria-expanded="false" aria-controls="collapseAdvancedSearch">Advanced Search</button>
2937
</div>
3038
</div>
39+
<small id="BasicHelp" class="form-text text-muted">N.B. One or more search keywords. For example: UML.</small>
40+
3141
</div>';
3242

3343
print '<div id="collapseAdvancedSearch" class="'.$collapse_class.' alert alert-secondary">
3444
3545
36-
<div class="row"><div class="col-sm-3">
46+
<div class="row"><div class="col-sm-6">
3747
'.create_input('Extension','text','extension',$extension_text,'','','Help: matches code files with a certain file extension.', false).'
3848
</div><div class="col-sm-3">
3949
40-
</div><div class="col-sm-3">
41-
42-
</div><div class="col-sm-3">
43-
44-
</div></div>
50+
</div>
51+
</div>
4552
4653
4754
@@ -64,18 +71,24 @@
6471

6572
$page =1;
6673
$count_file = 0;
74+
$account_no = $_POST['github_account'];
6775
while (1) {
6876
$data = array('q'=> $searchTB_text, 'page' => $page, 'per_page'=> 100);
6977
$url = 'https://api.github.com/search/code';
70-
$result_json = callAPI('GET', $url, $data, $header_array, GITHUB_USERNAME, GITHUB_PASSWORD);
78+
$result_json = callAPI('GET', $url, $data, $header_array, GITHUB_CREDENTIALS[$account_no]['username'], GITHUB_CREDENTIALS[$account_no]['password']);
7179
$result = json_decode($result_json, true);
72-
80+
if(!isset($result['total_count'])){
81+
printf('<div class="alert alert-danger">Search operation is stopped. Reason is given below.</div>');
82+
lau($result);
83+
}
84+
7385
if(isset($result['items'])){
7486
$data = $result['items'];
7587
}else{
7688
$data = array();
7789
}
7890
if($page==1){
91+
$total_count = $result['total_count'];
7992
$table_str= "<table id='mytable' class='table table-striped table-bordered' style='width:100%'><thead><tr>";
8093

8194
$table_str.= '<th>#</th><th>File Name</th><th>File Path</th><th>Repository Name</th><th>Repository Owner Name</th><th>File Score</th>';
@@ -107,14 +120,18 @@
107120
if($count_file >= 1000){
108121
$max_str = '(GITHUB Limitation: Maximum 1000 entries are returned. For more details at <a target="_blank" href ="https://developer.github.com/v3/search/#search-repositories">Click Here</a>.)';
109122
}
110-
$count_str = '<div class="alert alert-success">Showing <b>'.$count_file.'</b> of <b>'. $result['total_count'].'</b> repositories. '.$max_str.'</div>';
123+
$count_str = '<div class="alert alert-success">Showing <b>'.$count_file.'</b> of <b>'.$total_count.'</b> repositories. '.$max_str.'</div>';
111124

112125
print $count_str.$table_str ;
113126
}
114127
print '
115128
<script type="text/javascript">
116129
$(document).ready(function() {
117130
var t = $(\'#mytable\').DataTable({
131+
dom: \'Bfrtip\',
132+
buttons: [
133+
\'copy\', \'excel\', \'pdf\'
134+
],
118135
"order": [[ 3, "desc" ]]
119136
});
120137

commits_details.php

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,55 @@
11
<?php
22
include "header.php";
33

4-
$urlTB = 'https://api.github.com/repos/FelipeCortez/Calendala';
4+
//$urlTB = 'https://api.github.com/repos/FelipeCortez/Calendala';
5+
$owner_username ='FelipeCortez';
6+
$repository_username = 'Calendala';
57
$fileFormatTB = 'uml';
8+
$start_commit_no = '1';
69

710
if(isset($_POST['searchButton']) || isset($_REQUEST['url'])){
8-
$urlTB = $_POST['urlTB'];
11+
//$urlTB = $_POST['urlTB'];
12+
$owner_username =$_POST['owner_username'];
13+
$repository_username = $_POST['repository_username'];
914
$fileFormatTB = $_POST['fileFormatTB'];
15+
$start_commit_no = $_POST['start_commit_no'];
1016
}
1117

1218

13-
19+
print GITHUB_INSTRUCTION;
1420
print '<form name ="searchForm" method="post">
1521
<div class="alert alert-secondary">
16-
<b>Filtered by</b><input name="urlTB" type="text" class="form-control" aria-label="Text input with segmented dropdown button" placeholder="repo api url" value ="'.$urlTB.'" >
17-
<input name="fileFormatTB" type="text" class="form-control" aria-label="Text input with segmented dropdown button" placeholder="File Format for search" value ="'.$fileFormatTB.'" >
18-
<button name="searchButton" type="submit" class="btn btn-primary" value="1">Search</button></div>';
19-
20-
22+
<div class="input-group">
23+
<div class="input-group-prepend">
24+
<span class="input-group-text">Search</span>
25+
</div>
26+
<input name="fileFormatTB" type="text" class="form-control" aria-label="Text input with segmented dropdown button" placeholder="File Format for search" value ="'.$fileFormatTB.'" >
27+
<span class="input-group-text">format/extension files in </span>
28+
<input name="owner_username" type="text" class="form-control" aria-label="Text input with segmented dropdown button" placeholder="repository owner name" value ="'.$owner_username.'" >
29+
<span class="input-group-text">owner\'s </span>
30+
<input name="repository_username" type="text" class="form-control" aria-label="Text input with segmented dropdown button" placeholder="repository name" value ="'.$repository_username.'" >
31+
<span class="input-group-text">repository.</span>
32+
</div>
33+
34+
<div class="input-group">
35+
<div class="input-group-prepend">
36+
<span class="input-group-text">Search from commit no </span>
37+
</div>
38+
<input name="start_commit_no" type="text" class="form-control" aria-label="Text input with segmented dropdown button" placeholder="start commit no." value ="1" >
39+
<span class="input-group-text"> to next 4000 commits </span>
40+
<select class="custom-select" name="github_account" required>
41+
<option selected value="0">Choose GITHUB account</option>';
42+
foreach (GITHUB_CREDENTIALS as $key => $credential) {
43+
if(isset($_POST['github_account']) && $_POST['github_account'] == $key){$select_str = 'selected';}else{$select_str = '';}
44+
print '<option value="'.$key.'" '.$select_str.'>USERNAME: '.$credential['username'].', PASSWORD: '.substr($credential['password'], 0, 2).'*****'.substr($credential['password'], -2).'</option>';
45+
}
46+
47+
print '</select>
48+
49+
<button name="searchButton" type="submit" class="btn btn-primary" value="1">Do it now!</button>
50+
</div>
51+
52+
</div>';
2153

2254

2355
print '</form>';
@@ -41,16 +73,21 @@
4173

4274

4375
$total_commits_count = 0;
44-
$commit_page=1;
76+
$commit_page = intval($start_commit_no/100) + 1;
77+
$request_count = 0;
78+
$account_no = $_POST['github_account'];
79+
4580
while (1) {
4681
$data_commits = array( 'page' => $commit_page, 'per_page'=> 100);
47-
$commits_json = callAPI('GET', $urlTB.'/commits',$data_commits, $header_array, GITHUB_USERNAME, GITHUB_PASSWORD);
82+
$commits_json = callAPI('GET', 'https://api.github.com/repos/'.$owner_username.'/'.$repository_username.''.'/commits',$data_commits, $header_array, GITHUB_CREDENTIALS[$account_no]['username'], GITHUB_CREDENTIALS[$account_no]['password']);
4883

4984
$commits_result = json_decode($commits_json, true);
5085

5186
foreach ($commits_result as $key => $commit) {
52-
$empty_array = array();
53-
$commit_json = callAPI('GET', $urlTB.'/commits/'.$commit['sha'], $empty_array, $header_array, GITHUB_USERNAME, GITHUB_PASSWORD);
87+
88+
$empty_array = array();
89+
$commit_json = callAPI('GET', 'https://api.github.com/repos/'.$owner_username.'/'.$repository_username.'/commits/'.$commit['sha'], $empty_array, $header_array, GITHUB_CREDENTIALS[$account_no]['username'], GITHUB_CREDENTIALS[$account_no]['password']);
90+
$request_count = $request_count + 1;
5491
$commit_result = json_decode($commit_json, true);
5592

5693
foreach ($commit_result['files'] as $key => $file) {
@@ -73,14 +110,10 @@
73110
}
74111
}
75112

76-
77-
78-
79-
80113
$commits_count = count($commits_result);
81114
$total_commits_count = $total_commits_count + $commits_count;
82115

83-
if($commits_count==0){
116+
if($commits_count==0 || $request_count >= 4000){
84117
break;
85118
}
86119
$commit_page = $commit_page + 1;

definedVariables.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44
define('APP_DETAILS', 'The '.APP_NAME.' helps you to search for model based repositories (.uml, .xmi etc.). For example, you can search for .uml based repositories. The option is not integrate in Advanced Search in GitHub Website. Also Think of it the way, you want to search a repository that has language: Java and repository has model files(.uml or .xmi etc), then this app will help you to find those repository. Just like searching on GitHub, you sometimes want to see a few pages of search results so that you can find the item that best meets your needs. To satisfy that need, the '.APP_NAME.' provides best result based on search criterias.');
55

66

7-
define('GITHUB_USERNAME', 'USERNAME_FROM_GITHUB');
8-
define('GITHUB_PASSWORD', 'PASSWORD_FROM_GITHUB');
9-
?>
7+
8+
define('GITHUB_CREDENTIALS', array(
9+
array('username'=>'sayedmohsinreza', 'password' => '#Denver123#'),
10+
array('username'=>'rahadiit@gmail.com', 'password' => 'khandoker123'),
11+
array('username'=>'sreza3@miners.utep.edu', 'password' => 'Laila2019#')
12+
)
13+
);
14+
15+
define('GITHUB_INSTRUCTION', '<div class="alert alert-danger">Note: This Application is develped based on GitHub Search API. The Search API has a custom rate limit. For requests using Basic Authentication, OAuth, or client ID and secret, you can make up to <b>30 requests per minute</b>. For unauthenticated requests, the rate limit allows you to make up to <b>10 requests per minute</b>. Also To satisfy customer need, the GitHub Search API provides up to <b>1,000 results</b> for each search and those results can be fetched using <b>5000 requests</b> in <b>1 hour</b> For More details, visit <a href="https://developer.github.com/v3/search/#rate-limit" target="_blank">https://developer.github.com/v3/search/#rate-limit</a>.</div>');
16+
17+
18+
?>

header.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
2-
include 'dbConnection.php';
32
include 'designFunctions.php';
43
include 'processFunctions.php';
4+
55
print '<!doctype html>
66
<html lang="en">
77
<head>
@@ -80,7 +80,7 @@
8080
print' <div class="container-fluid"><br>';
8181

8282

83-
83+
8484

8585

8686
?>

repository.php

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,41 @@
44
$collapse_class = 'collapse';
55
$searchTB_text = '';
66
$size_text = '';
7+
$stars_text = '';
78
$language_text = '';
8-
$createdAt_text = '';
9-
$pushedAt_text = '';
9+
$created_text = '';
10+
$pushed_text = '';
1011
if(isset($_POST['searchButton'])){
1112
$collapse_class = 'collapse';
12-
$searchTB_text = $_POST['searchTB'];
13-
$createdAt_text = $_POST['createdAtTB'];
14-
$pushedAt_text = $_POST['pushedAtTB'];
1513
}
16-
17-
1814
if(isset($_POST['advancedSearchButton'])){
1915
$collapse_class = '';
20-
$searchTB_text = $_POST['searchTB'];
16+
}
17+
18+
if(isset($_POST['searchButton']) || isset($_POST['advancedSearchButton'])){
19+
$searchTB_text = $_POST['searchTB'];
2120
$size_text = $_POST['size'];
21+
$stars_text = $_POST['stars'];
2222
$language_text = $_POST['language'];
23-
$createdAt_text = $_POST['createdAtTB'];
24-
$pushedAt_text = $_POST['pushedAtTB'];
25-
23+
$created_text = $_POST['created'];
24+
$pushed_text = $_POST['pushed'];
2625
}
2726

28-
27+
print GITHUB_INSTRUCTION;
2928
print '<form name ="searchForm" method="post">';
3029

3130
print '<div class="alert alert-secondary">
3231
Repository Search
3332
<div class="input-group mb-3">
3433
<input name="searchTB" type="text" class="form-control" aria-label="Text input with segmented dropdown button" placeholder="keywords for search" value ="'.$searchTB_text.'">
34+
<select class="custom-select" name="github_account" required>
35+
<option selected value="0">Choose GITHUB account</option>';
36+
foreach (GITHUB_CREDENTIALS as $key => $credential) {
37+
if(isset($_POST['github_account']) && $_POST['github_account'] == $key){$select_str = 'selected';}else{$select_str = '';}
38+
print '<option value="'.$key.'" '.$select_str.'>USERNAME: '.$credential['username'].', PASSWORD: '.substr($credential['password'], 0, 2).'*****'.substr($credential['password'], -2).'</option>';
39+
}
40+
41+
print '</select>
3542
<div class="input-group-append">
3643
<button name="searchButton" type="submit" class="btn btn-primary" value="1">Search</button>
3744
<button class="btn btn-success" type="button" data-toggle="collapse" data-target="#collapseAdvancedSearch" aria-expanded="false" aria-controls="collapseAdvancedSearch">Advanced Search</button>
@@ -48,16 +55,16 @@
4855
<div class="row"><div class="col-sm-4">
4956
'.create_input('Size','text','size',$size_text,'','','Help: matches repositories that are at least 30000 (30 MB).', false).'
5057
</div><div class="col-sm-4">
51-
'.create_input('Number of stars','text','stars','','','','Help: matches repositories with the at least 500 stars.', false).'
58+
'.create_input('Number of stars','text','stars',$stars_text,'','','Help: matches repositories with the at least 500 stars.', false).'
5259
</div><div class="col-sm-4">
5360
'.create_input('language','text','language',$language_text,'','','Help: matches repositories with the word "rails" that are written in JavaScript.', false).'
5461
</div></div>
5562
5663
5764
<div class="row"><div class="col-sm-4">
58-
'.create_input('Created','text','created','','','','Help: matches repositories that were created before 2011.', false).'
65+
'.create_input('Created','text','created',$created_text,'','','Help: matches repositories that were created before 2011.', false).'
5966
</div><div class="col-sm-4">
60-
'.create_input('Pushed','text','pushed','','','','Help: matches repositories with the word "css" that were pushed to after January 2013.', false).'
67+
'.create_input('Pushed','text','pushed',$pushed_text,'','','Help: matches repositories with the word "css" that were pushed to after January 2013.', false).'
6168
</div><div class="col-sm-4">
6269
6370
</div></div>
@@ -133,23 +140,31 @@
133140
$header_array = array('Accept: application/vnd.github.machine-man-preview+json', 'User-Agent: Awesome-Octocat-App');
134141

135142
if(!empty($_POST['size'] )){$searchTB_text.=' size:>='.$size_text;}
143+
if(!empty($_POST['stars'] )){$searchTB_text.=' stars>:'.$stars_text;}
136144
if(!empty($_POST['language'] )){$searchTB_text.=' language:'.$language_text;}
145+
if(!empty($_POST['created'] )){$searchTB_text.=' created:>='.$created_text;}
146+
if(!empty($_POST['pushed'] )){$searchTB_text.=' pushed:>='.$pushed_text;}
137147

138148
$page =1;
139149
$count_repo = 0;
150+
$account_no = $_POST['github_account'];
140151
while (1) {
141152
$data = array('q'=> $searchTB_text, 'page' => $page, 'per_page'=> 100);
142153
$url = 'https://api.github.com/search/repositories';
143-
$result_json = callAPI('GET', $url, $data, $header_array, GITHUB_USERNAME, GITHUB_PASSWORD);
154+
$result_json = callAPI('GET', $url, $data, $header_array, GITHUB_CREDENTIALS[$account_no]['username'], GITHUB_CREDENTIALS[$account_no]['password']);
144155
$result = json_decode($result_json, true);
145-
lau($result);
156+
if(!isset($result['total_count'])){
157+
printf('<div class="alert alert-danger">Search operation is stopped. Reason is given below.</div>');
158+
lau($result);
159+
}
146160
if(isset($result['items'])){
147161
$data = $result['items'];
148162
}else{
149163
$data = array();
150164
}
151165

152166
if($page==1){
167+
$total_count = $result['total_count'];
153168
$table_str= "<table id='mytable' class='table table-striped table-bordered' style='width:100%'><thead><tr>";
154169
$table_str.= '<th>#</th><th>Name</th><th>Owner Name</th><th>Size</th><th>Stars</th><th>Watchers</th><th>Language</th><th>Created Date</th><th>Last Updated</th><th>Last Pushed</th>';
155170
$table_str.= '<th>Action</th></tr></thead><tbody>';
@@ -188,7 +203,7 @@
188203
if($count_repo >= 1000){
189204
$max_str = '(GITHUB Limitation: Maximum 1000 entries are returned. For more details at <a target="_blank" href ="https://developer.github.com/v3/search/#search-repositories">Click Here</a>).';
190205
}
191-
$count_str = '<div class="alert alert-success">Showing <b>'.$count_repo.'</b> of <b>'. $result['total_count'].'</b> repositories. '.$max_str.'</div>';
206+
$count_str = '<div class="alert alert-success">Showing <b>'.$count_repo.'</b> of <b>'.$total_count.'</b> repositories. '.$max_str.'</div>';
192207

193208

194209
print $count_str.$table_str ;
@@ -199,6 +214,10 @@
199214
<script type="text/javascript">
200215
$(document).ready(function() {
201216
var t = $(\'#mytable\').DataTable({
217+
dom: \'Bfrtip\',
218+
buttons: [
219+
\'copy\', \'excel\', \'pdf\'
220+
],
202221
"order": [[ 3, "desc" ]]
203222
});
204223

0 commit comments

Comments
 (0)