-
Notifications
You must be signed in to change notification settings - Fork 134
Expand file tree
/
Copy pathMantisSourcePlugin.class.php
More file actions
262 lines (223 loc) · 7.29 KB
/
Copy pathMantisSourcePlugin.class.php
File metadata and controls
262 lines (223 loc) · 7.29 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
<?php
# Copyright (c) 2012 John Reese
# Licensed under the MIT license
require_once( 'MantisSourceBase.class.php' );
/**
* Abstract class for simplifying creation of source control plugins.
* @author John Reese
*/
abstract class MantisSourcePlugin extends MantisSourceBase {
/**
* @var string Plugin Version string - MUST BE SET BY VCS PLUGIN
*/
const PLUGIN_VERSION = '0';
/**
* @var string Minimum framework version - MUST BE SET BY VCS PLUGIN
*/
const FRAMEWORK_VERSION_REQUIRED = '0';
/**
* @var string A short, unique, lowercase string representing the plugin's source control type.
*/
public $type = null;
/**
* @var bool Override this to "true" if there are configuration options for the vcs plugin.
*/
public $configuration = false;
/**
* Standard plugin registration.
*
* Child plugins are expected to override the following class constants
* - PLUGIN_VERSION
* - FRAMEWORK_VERSION_REQUIRED
*/
public function register() {
$this->name = plugin_lang_get( 'title' );
$this->description = plugin_lang_get( 'description' );
$this->version = static::PLUGIN_VERSION;
$this->requires = array(
'MantisCore' => static::MANTIS_VERSION,
'Source' => static::FRAMEWORK_VERSION_REQUIRED,
);
$this->author = 'John Reese';
$this->contact = 'john@noswap.com';
$this->url = 'https://github.com/mantisbt-plugins/source-integration/';
}
public function hooks() {
return array(
'EVENT_SOURCE_INTEGRATION' => 'integration',
'EVENT_SOURCE_PRECOMMIT' => '_precommit',
);
}
/**
* Define the VCS's ability to handle links to Pull Requests.
* If false, Pull Request links are not supported; otherwise this should be
* a sprintf template used to build an URL linking to a Pull Request, by
* appending it at the end of url_repo().
* e.g. '/pull/%s', %s being the PR's number
* @var false|string linkPullRequest
*/
public $linkPullRequest = false;
/**
* Get a long, proper string representing the plugin's source control type.
* Should be localized if possible.
* @return string Source control name
*/
abstract public function show_type();
/**
* Get a string representing the given repository and changeset.
* @param SourceRepo $p_repo Repository
* @param SourceChangeset $p_changeset Changeset
* @return string Changeset string
*/
abstract public function show_changeset( $p_repo, $p_changeset);
/**
* Get a string representing a file for a given repository and changeset.
* @param SourceRepo $p_repo Repository
* @param SourceChangeset $p_changeset Changeset
* @param SourceFile $p_file File
* @return string File string
*/
abstract public function show_file( $p_repo, $p_changeset, $p_file );
/**
* Get a URL to a view of the repository at the given changeset.
* @param SourceRepo $p_repo Repository
* @param SourceChangeset $p_changeset Changeset
* @return string URL
*/
abstract public function url_repo( $p_repo, $p_changeset=null );
/**
* Get a URL to a diff view of the given changeset.
* @param SourceRepo $p_repo Repository
* @param SourceChangeset $p_changeset Changeset
* @return string URL
*/
abstract public function url_changeset( $p_repo, $p_changeset );
/**
* Get a URL to a view of the given file at the given changeset.
*
* Return empty string if URL is not relevant in the given context
* (e.g. deleted file) or not supported by VCS.
*
* @param SourceRepo $p_repo Repository
* @param SourceChangeset $p_changeset Changeset
* @param SourceFile $p_file File
* @return string URL
*/
abstract public function url_file( $p_repo, $p_changeset, $p_file );
/**
* Get a URL to a diff view of the given file at the given changeset.
*
* Return empty string if URL is not relevant in the given context
* (e.g. deleted file) or not supported by VCS.
*
* @param SourceRepo $p_repo Repository
* @param SourceChangeset $p_changeset Changeset
* @param SourceFile $p_file File
* @return string URL
*/
abstract public function url_diff( $p_repo, $p_changeset, $p_file );
/**
* Output additional action buttons on the Manage Repository page.
* @param SourceRepo $p_repo Repository
*/
public function show_manage_actions( $p_repo ) {}
/**
* Output form elements for custom repository data.
* @param SourceRepo $p_repo Repository
*/
public function update_repo_form( $p_repo ) {}
/**
* Process form elements for custom repository data.
* @param SourceRepo $p_repo Repository
*/
public function update_repo( $p_repo ) {}
/**
* Output form elements for configuration options.
*
* They are displayed at the bottom of the plugin's config page
* (see manage_config_page.php). The first row should have class 'spacer',
* and the function should output an even number of rows (including the
* spacer row), to ensure that the VCS-specific section always start on an
* even row (i.e. with white background). Add an empty row if needed.
*/
public function update_config_form() {}
/**
* Process form elements for configuration options.
*/
public function update_config() {}
/**
* If necessary, check GPC inputs to determine if the checkin data
* is for a repository handled by this VCS type.
* @return array|null Array with "repo"=>Repository, "data"=>...
*/
public function precommit() {}
/**
* Translate commit data to Changeset objects for the given repo.
* @param SourceRepo $p_repo Repository
* @param mixed $p_data Commit data
* @return array Changesets
*/
public function commit( $p_repo, $p_data ) {}
/**
* Initiate an import of changeset data for the entire repository.
* @param SourceRepo $p_repo Repository
* @return SourceChangeset[] Changesets
*/
public function import_full( $p_repo ) {}
/**
* Initiate an import of changeset data not yet imported.
* @param SourceRepo $p_repo Repository
* @return SourceChangeset Changesets
*/
public function import_latest( $p_repo ) {}
/**
* Initialize contact with the integration framework.
* @return MantisSourcePlugin The plugin object
*/
final public function integration( $p_event ) {
return $this;
}
/**
* Pass the precommit event to the interface without the event paremater.
* @param mixed $p_event Unused
* @return array|null
*/
final public function _precommit( $p_event ) {
return $this->precommit();
}
}
/**
* Generic Source integration plugin to handle anything it can once
* other plugins have passed on handling the information.
* Most generic source control integration possible.
* Does not check source types, and should always be the last plugin
* to execute the event.
*/
class SourceGenericPlugin extends MantisSourcePlugin {
public $type = 'generic';
function register() {
$this->name = plugin_lang_get( 'title', 'Source' );
$this->version = self::FRAMEWORK_VERSION;
}
function show_type() {
return 'Generic';
}
function show_changeset( $p_repo, $p_changeset ) {
return $p_repo->type . ' ' . $p_changeset->revision;
}
function show_file( $p_repo, $p_changeset, $p_file ) {
return $p_file->filename . ' (' . $p_file->revision . ')';
}
function url_repo( $p_repo, $p_changeset=null ) {
return $p_repo->url;
}
function url_changeset( $p_repo, $p_changeset ) {
return $p_repo->url;
}
function url_file( $p_repo, $p_changeset, $p_file ) {
return $p_repo->url;
}
function url_diff( $p_repo, $p_changeset, $p_file ) {
return $p_repo->url;
}
}