Skip to content

Commit 4e9605a

Browse files
bright-toolsdregad
authored andcommitted
Add support for ViewVC integration
New plugin to allow linking of changeset information to an SVN repository fronted by ViewVC - http://www.viewvc.org/
1 parent 2d031b4 commit 4e9605a

File tree

3 files changed

+214
-0
lines changed

3 files changed

+214
-0
lines changed

SourceViewVC/LICENSE

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Copyright (c) 2015 John Bailey
2+
3+
Permission is hereby granted, free of charge, to any person
4+
obtaining a copy of this software and associated documentation
5+
files (the "Software"), to deal in the Software without
6+
restriction, including without limitation the rights to use,
7+
copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the
9+
Software is furnished to do so, subject to the following
10+
conditions:
11+
12+
The above copyright notice and this permission notice shall be
13+
included in all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.
23+

SourceViewVC/SourceViewVC.php

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
<?php
2+
3+
# Copyright (c) 2015 John Bailey
4+
# Copyright (c) 2012 John Reese
5+
# Licensed under the MIT license
6+
7+
if ( false === include_once( config_get( 'plugin_path' ) . 'SourceSVN/SourceSVN.php' ) ) {
8+
return;
9+
}
10+
11+
class SourceViewVCPlugin extends SourceSVNPlugin {
12+
public function register() {
13+
$this->name = lang_get( 'plugin_SourceViewVC_title' );
14+
$this->description = lang_get( 'plugin_SourceViewVC_description' );
15+
16+
$this->version = '0.1';
17+
$this->requires = array(
18+
'MantisCore' => '1.2.0',
19+
'Source' => '0.16',
20+
'SourceSVN' => '0.16',
21+
);
22+
23+
$this->author = 'John Bailey';
24+
$this->contact = '[email protected]';
25+
$this->url = 'https://github.com/bright-tools/source-integration';
26+
}
27+
28+
public $type = 'viewvc';
29+
30+
public function show_type() {
31+
return lang_get( 'plugin_SourceViewVC_svn' );
32+
}
33+
34+
public function get_viewvc_url( $p_repo ) {
35+
return isset( $p_repo->info['viewvc_url'] )
36+
? $p_repo->info['viewvc_url']
37+
: '';
38+
}
39+
40+
public function get_viewvc_name( $p_repo ) {
41+
return isset( $p_repo->info['viewvc_name'] )
42+
? $p_repo->info['viewvc_name']
43+
: '';
44+
}
45+
46+
public function get_viewvc_use_checkout( $p_repo ) {
47+
return isset( $p_repo->info['viewvc_use_checkout'] )
48+
? $p_repo->info['viewvc_use_checkout']
49+
: false;
50+
}
51+
52+
public function get_viewvc_root_as_url( $p_repo ) {
53+
return isset( $p_repo->info['viewvc_root_as_url'] )
54+
? $p_repo->info['viewvc_root_as_url']
55+
: false;
56+
}
57+
58+
/**
59+
* Builds the ViewVC URL base string
60+
* @param object $p_repo repository
61+
* @param string $p_file optional filename (as absolute path from root)
62+
* @param array $p_opts optional additional ViewVC URL parameters
63+
* @return string ViewVC URL
64+
*/
65+
protected function url_base( $p_repo, $p_file = '', $p_opts=array() ) {
66+
$t_name = urlencode( $this->get_viewvc_name( $p_repo ) );
67+
$t_root_as_url = $this->get_viewvc_root_as_url( $p_repo );
68+
69+
$t_url = rtrim( $this->get_viewvc_url( $p_repo ), '/' );
70+
71+
if( $t_root_as_url ) {
72+
$t_url_name = '/'.$t_name;
73+
} else {
74+
$t_url_name = '';
75+
$p_opts['root']=$t_name;
76+
}
77+
78+
return $t_url . $t_url_name . $p_file . '?' . http_build_query( $p_opts );
79+
}
80+
81+
public function url_repo( $p_repo, $p_changeset=null ) {
82+
$t_opts = array();
83+
84+
if ( !is_null( $p_changeset ) ) {
85+
$t_opts['revision'] = $p_changeset->revision;
86+
}
87+
88+
return $this->url_base( $p_repo, '', $t_opts);
89+
}
90+
91+
public function url_changeset( $p_repo, $p_changeset ) {
92+
$t_rev = $p_changeset->revision;
93+
$t_opts = array();
94+
$t_opts['view'] = 'revision';
95+
$t_opts['revision'] = $t_rev;
96+
97+
return $this->url_base( $p_repo, '', $t_opts );
98+
}
99+
100+
public function url_file( $p_repo, $p_changeset, $p_file ) {
101+
102+
# if the file has been removed, it doesn't exist in current revision
103+
# so we generate a link to (current revision - 1)
104+
$t_revision = ($p_file->action == 'rm')
105+
? $p_changeset->revision - 1
106+
: $p_changeset->revision;
107+
$t_use_checkout = $this->get_viewvc_use_checkout( $p_repo );
108+
109+
$t_opts = array();
110+
$t_opts['revision'] = $t_revision;
111+
112+
if( !$t_use_checkout )
113+
{
114+
$t_opts['view'] = 'markup';
115+
}
116+
117+
return $this->url_base( $p_repo, $p_file->filename, $t_opts );
118+
}
119+
120+
public function url_diff( $p_repo, $p_changeset, $p_file ) {
121+
if ( $p_file->action == 'rm' || $p_file->action == 'add' ) {
122+
return '';
123+
}
124+
125+
$t_opts = array();
126+
$t_opts['r1'] = $p_changeset->revision;
127+
$t_opts['r2'] = $p_changeset->revision - 1;
128+
129+
return $this->url_base( $p_repo, $p_file->filename, $t_opts );
130+
}
131+
132+
public function update_repo_form( $p_repo ) {
133+
$t_url = $this->get_viewvc_url( $p_repo );
134+
$t_name = $this->get_viewvc_name( $p_repo );
135+
$t_use_checkout = $this->get_viewvc_use_checkout( $p_repo );
136+
$t_root_as_url = $this->get_viewvc_root_as_url( $p_repo );
137+
138+
?>
139+
<tr <?php echo helper_alternate_class() ?>>
140+
<td class="category"><?php echo lang_get( 'plugin_SourceViewVC_viewvc_url' ) ?></td>
141+
<td><input name="viewvc_url" maxlength="250" size="40" value="<?php echo string_attribute( $t_url ) ?>"/></td>
142+
</tr>
143+
<tr <?php echo helper_alternate_class() ?>>
144+
<td class="category"><?php echo lang_get( 'plugin_SourceViewVC_viewvc_name' ) ?></td>
145+
<td><input name="viewvc_name" maxlength="250" size="40" value="<?php echo string_attribute( $t_name ) ?>"/></td>
146+
</tr>
147+
<tr <?php echo helper_alternate_class() ?>>
148+
<td class="category"><?php echo lang_get( 'plugin_SourceViewVC_viewvc_root_as_url' ) ?></td>
149+
<td><input name="viewvc_root_as_url" type="checkbox" <?php echo ($t_root_as_url ? 'checked="checked"' : '') ?>/></td>
150+
</tr>
151+
<tr <?php echo helper_alternate_class() ?>>
152+
<td class="category"><?php echo lang_get( 'plugin_SourceViewVC_viewvc_use_checkout' ) ?></td>
153+
<td><input name="viewvc_use_checkout" type="checkbox" <?php echo ($t_use_checkout ? 'checked="checked"' : '') ?>/></td>
154+
</tr>
155+
<?php
156+
157+
return parent::update_repo_form( $p_repo );
158+
}
159+
160+
public function update_repo( $p_repo ) {
161+
162+
$p_repo->info['viewvc_url'] = gpc_get_string( 'viewvc_url' );
163+
$p_repo->info['viewvc_name'] = gpc_get_string( 'viewvc_name' );
164+
$p_repo->info['viewvc_use_checkout'] = gpc_get_bool( 'viewvc_use_checkout', false );
165+
$p_repo->info['viewvc_root_as_url'] = gpc_get_bool( 'viewvc_root_as_url', false );
166+
167+
return parent::update_repo( $p_repo );
168+
}
169+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
# Copyright (c) 2012 John Reese
4+
# Licensed under the MIT license
5+
6+
$s_plugin_SourceViewVC_ = '';
7+
$s_plugin_SourceViewVC_title = 'Subversion / ViewVC Integration';
8+
$s_plugin_SourceViewVC_description = 'Adds Subversion integration to the Source plugin framework using the ViewVC app.';
9+
10+
$s_plugin_SourceViewVC_svn = 'ViewVC';
11+
$s_plugin_SourceViewVC_viewvc_url = 'ViewVC URL<br/><span class="small">(With trailing slash)</span>';
12+
$s_plugin_SourceViewVC_viewvc_name = 'ViewVC Name<br/><span class="small">(Repository directory)</span>';
13+
$s_plugin_SourceViewVC_viewvc_root_as_url = 'ViewVC Root As URL Component Enabled?';
14+
$s_plugin_SourceViewVC_viewvc_use_checkout = 'ViewVC Checkout View Enabled?';
15+
16+
$s_plugin_SourceViewVC_svn_username = 'SVN Username';
17+
$s_plugin_SourceViewVC_svn_password = 'SVN Password';
18+
$s_plugin_SourceViewVC_standard_repo = 'Standard Repository<br/><span class="small">(trunk/branches/tags)</span>';
19+
$s_plugin_SourceViewVC_trunk_path = 'Trunk Path<br/><span class="small">(Non-standard repository)</span>';
20+
$s_plugin_SourceViewVC_branch_path = 'Branch Path<br/><span class="small">(Non-standard repository)</span>';
21+
$s_plugin_SourceViewVC_tag_path = 'Tag Path<br/><span class="small">(Non-standard repository)</span>';
22+
$s_plugin_SourceViewVC_ignore_paths = 'Ignore Other Paths<br/><span class="small">(Non-standard repository)</span>';

0 commit comments

Comments
 (0)