summaryrefslogtreecommitdiff
path: root/app/helpers
diff options
context:
space:
mode:
authorJason Hollingsworth <jhworth.developer@gmail.com>2014-02-03 20:35:48 -0600
committerJason Hollingsworth <jhworth.developer@gmail.com>2014-02-05 20:44:14 -0600
commitfcc906e6aa1749046b691bbd60b2020fc970bdfb (patch)
tree4787f1283151b64ce77776722fa831ab40d496d1 /app/helpers
parent883409b941b591a482a4d883a4925d87c00b18a6 (diff)
downloadgitlab-ce-fcc906e6aa1749046b691bbd60b2020fc970bdfb.tar.gz
Better submodule links.
Detect if submodule is hosted on this GitLab server, gitlab.com or github.com. Hash links directly to commit in repo.
Diffstat (limited to 'app/helpers')
-rw-r--r--app/helpers/submodule_helper.rb42
1 files changed, 42 insertions, 0 deletions
diff --git a/app/helpers/submodule_helper.rb b/app/helpers/submodule_helper.rb
new file mode 100644
index 00000000000..285f4081bf9
--- /dev/null
+++ b/app/helpers/submodule_helper.rb
@@ -0,0 +1,42 @@
+module SubmoduleHelper
+ include Gitlab::ShellAdapter
+
+ # links to files listing for submodule if submodule is a project on this server
+ def submodule_links(submodule_item)
+ url = submodule_item.submodule_url
+ return url, nil unless url =~ /([^\/:]+\/[^\/]+\.git)\Z/
+
+ project = $1
+ project.chomp!('.git')
+
+ if self_url?(url, project)
+ return project_path(project), project_tree_path(project, submodule_item.id)
+ elsif github_dot_com_url?(url)
+ standard_links('github.com', project, submodule_item.id)
+ elsif gitlab_dot_com_url?(url)
+ standard_links('gitlab.com', project, submodule_item.id)
+ else
+ return url, nil
+ end
+ end
+
+ protected
+
+ def github_dot_com_url?(url)
+ url =~ /github\.com[\/:][^\/]+\/[^\/]+\Z/
+ end
+
+ def gitlab_dot_com_url?(url)
+ url =~ /gitlab\.com[\/:][^\/]+\/[^\/]+\Z/
+ end
+
+ def self_url?(url, project)
+ return true if url == [ Gitlab.config.gitlab.url, '/', project, '.git' ].join('')
+ url == gitlab_shell.url_to_repo(project)
+ end
+
+ def standard_links(host, project, commit)
+ base = [ 'https://', host, '/', project ].join('')
+ return base, [ base, '/tree/', commit ].join('')
+ end
+end \ No newline at end of file