Skip to content

Commit c5c03f8

Browse files
authored
Code Updates
Updated the functions in order to display repository details based on shortcute attributes defined by each user.
1 parent 965e74d commit c5c03f8

1 file changed

Lines changed: 26 additions & 22 deletions

File tree

functions.php

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,21 @@ function time_since_creation($created_at) {
1313
}
1414
}
1515

16-
function github_issues_shortcode($atts) {
16+
function gitsync_issues_shortcode($atts) {
1717
$atts = shortcode_atts(array(
18-
'repository' => get_option('github_plugin_repository', 'opensourcepos'),
19-
'owner' => get_option('github_plugin_owner', 'opensourcepos'),
20-
), $atts, 'github_data');
18+
'token' => '',
19+
'repository' => '',
20+
'owner' => '',
21+
), $atts, 'gitsync_issues');
2122

2223
// Make API request for open issues using cURL
2324
$issues_api_url = "https://api.github.com/repos/{$atts['owner']}/{$atts['repository']}/issues?state=open";
2425
$headers = array(
25-
'Authorization: Your-Token-Here',
26+
'Authorization: token ' . $atts['token'],
2627
'User-Agent: Your-User-Agent', // Add your own User-Agent here
2728
);
2829

29-
// Initialize cURL session for issues
30+
// Initialize cURL session for issues
3031
$ch = curl_init();
3132
curl_setopt($ch, CURLOPT_URL, $issues_api_url);
3233
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@@ -60,7 +61,6 @@ function github_issues_shortcode($atts) {
6061
$last_10_issues = array_slice($issues_data, 0, 10);
6162

6263
// Display issues
63-
// $output .= '<h2>Open Issues</h2>';
6464
$output .= '<ul>';
6565
foreach ($last_10_issues as $issue) {
6666
// Check if the issue is not a pull request
@@ -96,17 +96,20 @@ function github_issues_shortcode($atts) {
9696

9797
return $output;
9898
}
99-
add_shortcode('github_issues', 'github_issues_shortcode');
100-
function github_commits_shortcode($atts) {
99+
100+
add_shortcode('gitsync_issues', 'gitsync_issues_shortcode');
101+
102+
function gitsync_commits_shortcode($atts) {
101103
$atts = shortcode_atts(array(
102-
'repository' => get_option('github_plugin_repository', 'opensourcepos'),
103-
'owner' => get_option('github_plugin_owner', 'opensourcepos'),
104-
), $atts, 'github_data');
104+
'token' => '',
105+
'repository' => '',
106+
'owner' => '',
107+
), $atts, 'gitsync_commits');
105108

106109
// Make API request for open commits using cURL
107110
$commits_api_url = "https://api.github.com/repos/{$atts['owner']}/{$atts['repository']}/commits?per_page=10&sort=author-date&direction=desc";
108111
$headers = array(
109-
'Authorization: Your-Token-Here',
112+
'Authorization: token ' . $atts['token'],
110113
'User-Agent: Your-User-Agent', // Add your own User-Agent here
111114
);
112115

@@ -132,7 +135,8 @@ function github_commits_shortcode($atts) {
132135
$commits_data = json_decode($commits_response, true);
133136

134137
// Display the data
135-
// $output = '<h2>New Commits</h2>';
138+
$output = ''; // Initialize output variable
139+
136140
if (!empty($commits_data)) {
137141
// Display commits
138142
$output .= '<ul>';
@@ -181,19 +185,20 @@ function github_commits_shortcode($atts) {
181185

182186
return $output;
183187
}
184-
add_shortcode('github_commits', 'github_commits_shortcode');
185188

189+
add_shortcode('gitsync_commits', 'gitsync_commits_shortcode');
186190

187-
function github_pull_requests_shortcode($atts) {
191+
function gitsync_pull_requests_shortcode($atts) {
188192
$atts = shortcode_atts(array(
189-
'repository' => 'opensourcepos',
190-
'owner' => 'opensourcepos',
191-
), $atts, 'github_data');
193+
'token' => '',
194+
'repository' => '',
195+
'owner' => '',
196+
), $atts, 'gitsync_pull_requests');
192197

193198
// Make API request for open pull requests using cURL
194199
$pulls_api_url = "https://api.github.com/repos/{$atts['owner']}/{$atts['repository']}/pulls?state=open";
195200
$headers = array(
196-
'Authorization: Your-Token-Here',
201+
'Authorization: token ' . $atts['token'],
197202
'User-Agent: Your-User-Agent', // Add your own User-Agent here
198203
);
199204

@@ -231,7 +236,6 @@ function github_pull_requests_shortcode($atts) {
231236
$last_10_pulls = array_slice($pulls_data, 0, 10);
232237

233238
// Display pull requests
234-
// $output .= '<h2>Open Pull Requests</h2>';
235239
$output .= '<ul>';
236240
foreach ($last_10_pulls as $pull) {
237241
// Generate list items for each pull request
@@ -264,5 +268,5 @@ function github_pull_requests_shortcode($atts) {
264268

265269
return $output;
266270
}
267-
add_shortcode('github_pull_requests', 'github_pull_requests_shortcode');
268271

272+
add_shortcode('gitsync_pull_requests', 'gitsync_pull_requests_shortcode');

0 commit comments

Comments
 (0)