-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqa-assistant.php
More file actions
187 lines (158 loc) · 4.72 KB
/
Copy pathqa-assistant.php
File metadata and controls
187 lines (158 loc) · 4.72 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?php
/*
Plugin Name: QA Assistant
Plugin URI: https://obayedmamur.com/qa-assistant
Description: A comprehensive tool for SQA Engineers with GitHub Desktop-like Git branch switching functionality.
Version: 2.1.0
Author: Obayed Mamur
Author URI: https://obayedmamur.com
License: GPLv3
*/
if (!defined('ABSPATH')) {
exit;
}
// Define plugin constants
define('QA_ASSISTANT_VERSION', '2.1.0');
define('QA_ASSISTANT_PLUGIN_FILE', __FILE__);
define('QA_ASSISTANT_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('QA_ASSISTANT_PLUGIN_URL', plugin_dir_url(__FILE__));
define('QA_ASSISTANT_PLUGIN_BASENAME', plugin_basename(__FILE__));
/**
* Get the absolute path to a plugin directory using WordPress best practices
*
* @param string $plugin_dir The plugin directory name
* @return string The absolute path to the plugin directory
*/
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Uses 'qa_assistant' prefix matching the plugin slug.
function qa_assistant_get_plugin_path($plugin_dir)
{
// Use WordPress function to get plugins directory
$plugins_dir = dirname(plugin_dir_path(__FILE__));
return trailingslashit($plugins_dir) . $plugin_dir;
}
require_once __DIR__ . '/vendor/autoload.php';
/**
* The main plugin class
*/
final class Qa_Assistant
{
/**
* Plugin version
*
* @var string
*/
const version = QA_ASSISTANT_VERSION;
/**
* Git manager instance
*
* @var QaAssistant\GitManager
*/
protected $gitManager;
/**
* Class constructor
*/
private function __construct()
{
$this->define_constants();
$this->gitManager = new QaAssistant\GitManager();
register_activation_hook(__FILE__, [$this, 'activate']);
add_action('plugins_loaded', [$this, 'init_plugin']);
// Add "Settings" link to plugin action links on the Plugins page
add_filter('plugin_action_links_' . QA_ASSISTANT_PLUGIN_BASENAME, [$this, 'plugin_action_links']);
}
/**
* Initialize a singleton instance
*
* @return \Qa_Assistant
*/
public static function init()
{
static $instance = false;
if (!$instance) {
$instance = new self();
}
return $instance;
}
/**
* Define the required plugin constants
*
* @return void
*/
public function define_constants()
{
// QA_ASSISTANT_VERSION, QA_ASSISTANT_PLUGIN_FILE, QA_ASSISTANT_PLUGIN_DIR, and
// QA_ASSISTANT_PLUGIN_URL are already defined at the top of the file.
// Only define the two additional aliases needed internally.
define('QA_ASSISTANT_PATH', __DIR__);
define('QA_ASSISTANT_URL', plugins_url('', __FILE__));
define('QA_ASSISTANT_ASSETS', QA_ASSISTANT_URL . '/assets');
}
/**
* Initialize the plugin
*
* @return void
*/
public function init_plugin()
{
new QaAssistant\Assets();
if (defined('DOING_AJAX') && DOING_AJAX) {
new QaAssistant\Ajax($this->gitManager);
}
if (is_admin()) {
new QaAssistant\Admin();
} else {
new QaAssistant\Frontend();
}
// Initialize Admin Bar (GitManager not needed; it only renders HTML)
if (is_user_logged_in()) {
new QaAssistant\Admin\AdminBar();
}
new QaAssistant\API();
}
/**
* Add "Settings" link to plugin action links
*
* @param array $links Existing plugin action links
* @return array Modified plugin action links
*/
public function plugin_action_links($links)
{
$settings_link = '<a href="' . admin_url('tools.php?page=qa-assistant') . '">Settings</a>';
array_unshift($links, $settings_link);
return $links;
}
/**
* Do stuff upon plugin activation
*
* @return void
*/
public function activate()
{
$installer = new QaAssistant\Installer();
$installer->run();
}
/**
* Get current Git branch for a given path
*
* @param string $path Repository path
* @param bool $force_refresh Whether to bypass cache and fetch fresh data
* @return string|false Current branch name or false on failure
*/
public function get_git_branch($path, $force_refresh = false)
{
return $this->gitManager->getCurrentBranch($path, $force_refresh);
}
}
/**
* Initializes the main plugin
*
* @return \Qa_Assistant
*/
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Uses 'qa_assistant' prefix matching the plugin slug.
function qa_assistant()
{
return Qa_Assistant::init();
}
// Call the plugin
qa_assistant();
// Test uncommitted change for git pull modal