Skip to content

Commit fe1b503

Browse files
committed
New url_base() method to avoid code duplication
1 parent 061884f commit fe1b503

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

SourceBitBucket/SourceBitBucket.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,23 @@ public function show_file( $p_repo, $p_changeset, $p_file ) {
5959
return "$p_file->action - $t_filename";
6060
}
6161

62+
public function url_base( $p_repo ) {
63+
return $this->main_url . $p_repo->info['bit_username'] . '/' . $p_repo->info['bit_reponame'];
64+
}
65+
6266
public function url_repo( $p_repo, $p_changeset = null ) {
6367
if( empty($p_repo->info) ) return '';
6468

65-
$t_username = $p_repo->info['bit_username'];
66-
$t_reponame = $p_repo->info['bit_reponame'];
67-
$t_ref = '';
69+
$t_ref = '';
6870
if( !is_null( $p_changeset ) )
6971
$t_ref = "/src/?at=$p_changeset->revision";
7072

71-
return $this->main_url . "$t_username/$t_reponame$t_ref";
73+
return $this->url_base( $p_repo ) . $t_ref;
7274
}
7375

7476
public function url_changeset( $p_repo, $p_changeset ) {
75-
$t_username = $p_repo->info['bit_username'];
76-
$t_reponame = $p_repo->info['bit_reponame'];
77-
$t_ref = $p_changeset->revision;
78-
return $this->main_url . "$t_username/$t_reponame/commits/$t_ref";
77+
$t_ref = $p_changeset->revision;
78+
return $this->url_base( $p_repo ) . "/commits/$t_ref";
7979
}
8080

8181
public function url_file( $p_repo, $p_changeset, $p_file ) {
@@ -86,7 +86,7 @@ public function url_file( $p_repo, $p_changeset, $p_file ) {
8686

8787
$t_ref = $p_changeset->revision;
8888
$t_filename = $p_file->getFilename();
89-
return $this->main_url . "$t_username/$t_reponame/src/$t_ref/$t_filename";
89+
return $this->url_base( $p_repo ) . "/src/$t_ref/$t_filename";
9090
}
9191

9292
public function url_diff( $p_repo, $p_changeset, $p_file ) {
@@ -97,7 +97,7 @@ public function url_diff( $p_repo, $p_changeset, $p_file ) {
9797

9898
$t_ref = $p_changeset->revision;
9999
$t_filename = $p_file->getFilename();
100-
return $this->main_url . "$t_username/$t_reponame/diff/$t_filename?diff2=$t_ref";
100+
return $this->url_base( $p_repo ) . "/diff/$t_filename?diff2=$t_ref";
101101
}
102102

103103
public function update_repo_form( $p_repo ) {

SourceGithub/SourceGithub.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@ class SourceGithubPlugin extends MantisSourceGitBasePlugin {
1818
const PLUGIN_VERSION = '2.3.1';
1919
const FRAMEWORK_VERSION_REQUIRED = '2.5.0';
2020

21+
/**
22+
* GitHub URLs
23+
*/
24+
const URL_MAIN = 'https://github.com/';
2125
const URL_API = 'https://api.github.com/';
22-
const URL_OAUTH = 'https://github.com/login/oauth/';
26+
const URL_OAUTH = self::URL_MAIN . 'login/oauth/';
2327

2428
public $linkPullRequest = '/pull/%s';
2529

@@ -216,27 +220,25 @@ public function show_file( $p_repo, $p_changeset, $p_file ) {
216220
return "$p_file->action - $p_file->filename";
217221
}
218222

223+
public function url_base( $p_repo ) {
224+
return self::URL_MAIN . $p_repo->info['hub_username'] . '/' . $p_repo->info['hub_reponame'];
225+
}
226+
219227
public function url_repo( $p_repo, $p_changeset=null ) {
220228
if( empty( $p_repo->info ) ) {
221229
return '';
222230
}
223-
$t_username = $p_repo->info['hub_username'];
224-
$t_reponame = $p_repo->info['hub_reponame'];
225-
$t_ref = "";
226231

232+
$t_ref = '';
227233
if ( !is_null( $p_changeset ) ) {
228234
$t_ref = "/tree/$p_changeset->revision";
229235
}
230236

231-
return "https://github.com/$t_username/$t_reponame$t_ref";
237+
return $this->url_base( $p_repo ) . $t_ref;
232238
}
233239

234240
public function url_changeset( $p_repo, $p_changeset ) {
235-
$t_username = $p_repo->info['hub_username'];
236-
$t_reponame = $p_repo->info['hub_reponame'];
237-
$t_ref = $p_changeset->revision;
238-
239-
return "https://github.com/$t_username/$t_reponame/commit/$t_ref";
241+
return $this->url_base( $p_repo ) . '/commit/' . $p_changeset->revision;
240242
}
241243

242244
public function url_file( $p_repo, $p_changeset, $p_file ) {
@@ -245,12 +247,10 @@ public function url_file( $p_repo, $p_changeset, $p_file ) {
245247
return '';
246248
}
247249

248-
$t_username = $p_repo->info['hub_username'];
249-
$t_reponame = $p_repo->info['hub_reponame'];
250250
$t_ref = $p_changeset->revision;
251251
$t_filename = $p_file->getFilename();
252252

253-
return "https://github.com/$t_username/$t_reponame/blob/$t_ref/$t_filename";
253+
return $this->url_base( $p_repo ) . "/blob/$t_ref/$t_filename";
254254
}
255255

256256
/**

0 commit comments

Comments
 (0)