34 |
34 |
35 sub _link_template { |
35 sub _link_template { |
36 my ($self, $scm, $repo) = @_; |
36 my ($self, $scm, $repo) = @_; |
37 |
37 |
38 my $linkconf = "$scm:$repo"; |
38 my $linkconf = "$scm:$repo"; |
39 if(defined($self->{_template_cache}->{$linkconf})) { |
39 if(exists($self->{_template_cache}->{$linkconf})) { |
40 return $self->{_template_cache}->{$linkconf}; |
40 return $self->{_template_cache}->{$linkconf}; |
41 } |
41 } |
42 my $template = $self->config->{WebInterface}->{ScmLinks}->{$linkconf}; |
42 my $template = $self->config->{WebInterface}->{ScmLinks}->{$linkconf} // undef; |
|
43 |
|
44 # try striping repo path elements until a match |
|
45 if(!defined($template)) { |
|
46 my $rpath = $repo; |
|
47 while($rpath =~ m:^(.+)/[^/]+[/]?$:xms) { |
|
48 $rpath = $1; |
|
49 $linkconf = "$scm:$rpath"; |
|
50 $template = $self->config->{WebInterface}->{ScmLinks}->{$linkconf} // undef; |
|
51 if(defined($template)) { |
|
52 # keep full repo in cache (avoid loop) |
|
53 $linkconf = "$scm:$repo"; |
|
54 break; |
|
55 } |
|
56 } |
|
57 } |
43 |
58 |
44 # try the generic repository type |
59 # try the generic repository type |
45 if(!defined($template)) { |
60 if(!defined($template)) { |
46 $linkconf = $scm; |
61 $linkconf = $scm; |
47 if(defined($self->{_template_cache}->{$linkconf})) { |
62 if(exists($self->{_template_cache}->{$linkconf})) { |
48 return $self->{_template_cache}->{$linkconf}; |
63 return $self->{_template_cache}->{$linkconf}; |
49 } |
64 } |
50 $template = $self->config->{WebInterface}->{ScmLinks}->{$linkconf}; |
65 $template = $self->config->{WebInterface}->{ScmLinks}->{$linkconf} // undef; |
51 } |
66 } |
52 |
67 |
53 return undef if !defined($template); |
68 return if !defined($template); |
54 |
69 |
55 $self->app->log->debug("Building template for $linkconf"); |
70 $self->app->log->debug("Building template for $linkconf"); |
56 |
71 |
57 my $mt = Mojo::Template->new |
72 my $mt = Mojo::Template->new |
58 ->vars(1) |
73 ->vars(1) |