-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic-setup.php
More file actions
71 lines (57 loc) · 2.75 KB
/
Copy pathbasic-setup.php
File metadata and controls
71 lines (57 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/**
* ghissue-php Basic Setup Example
*
* This shows how to set up ghissue-php on your website.
* Copy this to your project and modify as needed.
*/
// Option A: No Composer — use the built-in autoloader
require_once __DIR__ . '/../ghissue.php';
// Option B: With Composer (if you prefer)
// require_once __DIR__ . '/../vendor/autoload.php';
use GhIssue\GhIssue;
// =============================================================================
// 1. CONFIGURATION
// =============================================================================
// --- Option A: Config file (recommended) ---
// Copy ghissue-config.example.php to your project, fill in your values, then:
// $tracker = GhIssue::fromConfig(__DIR__ . '/ghissue-config.php');
// --- Option B: Inline configuration ---
// Create a GitHub Personal Access Token at:
// https://github.com/settings/tokens
// Required scopes: repo (for private repos) or public_repo (for public repos)
$tracker = new GhIssue(
token: getenv('GHISSUE_TOKEN') ?: 'ghp_your_token_here',
owner: 'your-github-username', // or your org name
repo: 'your-issue-repo', // the repo where issues will be created
project: 'my-website', // project identifier for multi-site setups
options: [
'storage_dir' => '/tmp/ghissue', // writable directory for rate limiting & cache
]
);
// =============================================================================
// 2. ONE-TIME SETUP — Run this once to create labels in your repo
// =============================================================================
// Uncomment and run once:
// $tracker->setupLabels();
// echo "Labels created!\n";
// exit;
// =============================================================================
// 3. REGISTER ERROR HANDLER — Auto-reports PHP errors to GitHub Issues
// =============================================================================
$tracker->registerErrorHandler([
// URL where users can submit comments about errors
'comment_endpoint' => '/ghissue/comment.php',
// Show the built-in error page (set false if you have your own)
'show_error_page' => true,
]);
// That's it! Now any unhandled exception or fatal error will:
// - Create a GitHub Issue (or add to existing one if duplicate)
// - Show a user-friendly error page with optional comment field
// =============================================================================
// 4. YOUR APPLICATION CODE
// =============================================================================
// Your normal application code goes here...
// Any uncaught exceptions will be automatically reported.
// Example: manually report something
// $tracker->report('Database connection slow', 'Response time exceeded 5s threshold', 'warning');