summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValery Sizov <valery@gitlab.com>2015-02-02 17:01:07 -0800
committerValery Sizov <valery@gitlab.com>2015-02-05 12:50:34 -0800
commit33349dd54928a0b074b4ae3ebfabf214799fc085 (patch)
tree593a14d0f6df812410349f353e252e3a58d8cacd
parent713bc152bde5396bb95a1555907bcd9a2847839d (diff)
downloadgitlab-ce-33349dd54928a0b074b4ae3ebfabf214799fc085.tar.gz
GitLab.com integration: refactoring
-rw-r--r--app/controllers/import/github_controller.rb (renamed from app/controllers/importers/githubs_controller.rb)6
-rw-r--r--app/controllers/import/gitlab_controller.rb (renamed from app/controllers/importers/gitlabs_controller.rb)8
-rw-r--r--app/views/import/github/create.js.haml (renamed from app/views/importers/githubs/create.js.haml)0
-rw-r--r--app/views/import/github/status.html.haml (renamed from app/views/importers/githubs/status.html.haml)4
-rw-r--r--app/views/import/gitlab/create.js.haml (renamed from app/views/importers/gitlabs/create.js.haml)0
-rw-r--r--app/views/import/gitlab/status.html.haml (renamed from app/views/importers/gitlabs/status.html.haml)4
-rw-r--r--app/views/projects/new.html.haml4
-rw-r--r--config/routes.rb8
-rw-r--r--doc/integration/gitlab.md2
-rw-r--r--lib/gitlab/github_import/client.rb2
-rw-r--r--lib/gitlab/github_import/importer.rb9
-rw-r--r--lib/gitlab/gitlab_import/client.rb4
-rw-r--r--lib/gitlab/gitlab_import/importer.rb10
-rw-r--r--lib/gitlab/import_formatter.rb15
-rw-r--r--spec/controllers/import/github_controller_spec.rb (renamed from spec/controllers/importers/githubs_controller_spec.rb)4
-rw-r--r--spec/controllers/import/gitlab_controller_spec.rb (renamed from spec/controllers/importers/gitlabs_controller_spec.rb)4
16 files changed, 52 insertions, 32 deletions
diff --git a/app/controllers/importers/githubs_controller.rb b/app/controllers/import/github_controller.rb
index b3d42e32dfa..3f0461ead51 100644
--- a/app/controllers/importers/githubs_controller.rb
+++ b/app/controllers/import/github_controller.rb
@@ -1,4 +1,4 @@
-class Importers::GithubsController < ApplicationController
+class Import::GithubController < ApplicationController
before_filter :github_auth, except: :callback
rescue_from Octokit::Unauthorized, with: :github_unauthorized
@@ -7,7 +7,7 @@ class Importers::GithubsController < ApplicationController
token = client.auth_code.get_token(params[:code]).token
current_user.github_access_token = token
current_user.save
- redirect_to status_importers_github_url
+ redirect_to status_import_github_url
end
def status
@@ -69,7 +69,7 @@ class Importers::GithubsController < ApplicationController
def go_to_github_for_permissions
redirect_to client.auth_code.authorize_url({
- redirect_uri: callback_importers_github_url,
+ redirect_uri: callback_import_github_url,
scope: "repo, user, user:email"
})
end
diff --git a/app/controllers/importers/gitlabs_controller.rb b/app/controllers/import/gitlab_controller.rb
index d020c870a4f..3712af6f024 100644
--- a/app/controllers/importers/gitlabs_controller.rb
+++ b/app/controllers/import/gitlab_controller.rb
@@ -1,13 +1,13 @@
-class Importers::GitlabsController < ApplicationController
+class Import::GitlabController < ApplicationController
before_filter :gitlab_auth, except: :callback
rescue_from OAuth2::Error, with: :gitlab_unauthorized
def callback
- token = client.get_token(params[:code], callback_importers_gitlab_url)
+ token = client.get_token(params[:code], callback_import_gitlab_url)
current_user.gitlab_access_token = token
current_user.save
- redirect_to status_importers_gitlab_url
+ redirect_to status_import_gitlab_url
end
def status
@@ -60,7 +60,7 @@ class Importers::GitlabsController < ApplicationController
end
def go_to_gitlab_for_permissions
- redirect_to client.authorize_url(callback_importers_gitlab_url)
+ redirect_to client.authorize_url(callback_import_gitlab_url)
end
def gitlab_unauthorized
diff --git a/app/views/importers/githubs/create.js.haml b/app/views/import/github/create.js.haml
index cd4c9fbf360..cd4c9fbf360 100644
--- a/app/views/importers/githubs/create.js.haml
+++ b/app/views/import/github/create.js.haml
diff --git a/app/views/importers/githubs/status.html.haml b/app/views/import/github/status.html.haml
index af04ae0d1bf..9797f5983ea 100644
--- a/app/views/importers/githubs/status.html.haml
+++ b/app/views/import/github/status.html.haml
@@ -43,11 +43,11 @@
if tr.find(".import-target input").length > 0
new_namespace = tr.find(".import-target input").prop("value")
tr.find(".import-target").empty().append(new_namespace + "/" + tr.find(".import-target").data("project_name"))
- $.post "#{importers_github_url}", {repo_id: id, new_namespace: new_namespace}, dataType: 'script'
+ $.post "#{import_github_url}", {repo_id: id, new_namespace: new_namespace}, dataType: 'script'
setInterval (->
- $.get "#{jobs_importers_github_path}", (data)->
+ $.get "#{jobs_import_github_path}", (data)->
$.each data, (i, job) ->
job_item = $("#project_" + job.id)
status_field = job_item.find(".job-status")
diff --git a/app/views/importers/gitlabs/create.js.haml b/app/views/import/gitlab/create.js.haml
index cd4c9fbf360..cd4c9fbf360 100644
--- a/app/views/importers/gitlabs/create.js.haml
+++ b/app/views/import/gitlab/create.js.haml
diff --git a/app/views/importers/gitlabs/status.html.haml b/app/views/import/gitlab/status.html.haml
index d2ddd716220..ff0ab189c0b 100644
--- a/app/views/importers/gitlabs/status.html.haml
+++ b/app/views/import/gitlab/status.html.haml
@@ -43,11 +43,11 @@
if tr.find(".import-target input").length > 0
new_namespace = tr.find(".import-target input").prop("value")
tr.find(".import-target").empty().append(new_namespace + "/" + tr.find(".import-target").data("project_name"))
- $.post "#{importers_gitlab_url}", {repo_id: id, new_namespace: new_namespace}, dataType: 'script'
+ $.post "#{import_gitlab_url}", {repo_id: id, new_namespace: new_namespace}, dataType: 'script'
setInterval (->
- $.get "#{jobs_importers_gitlab_path}", (data)->
+ $.get "#{jobs_import_gitlab_path}", (data)->
$.each data, (i, job) ->
job_item = $("#project_" + job.id)
status_field = job_item.find(".job-status")
diff --git a/app/views/projects/new.html.haml b/app/views/projects/new.html.haml
index ae1dd88b696..713370e3bfe 100644
--- a/app/views/projects/new.html.haml
+++ b/app/views/projects/new.html.haml
@@ -44,7 +44,7 @@
.col-sm-2
.col-sm-10
- if github_import_enabled?
- = link_to status_importers_github_path do
+ = link_to status_import_github_path do
%i.fa.fa-github
Import projects from GitHub
- else
@@ -57,7 +57,7 @@
.col-sm-2
.col-sm-10
- if gitlab_import_enabled?
- = link_to status_importers_gitlab_path do
+ = link_to status_import_gitlab_path do
%i.fa.fa-heart
Import projects from GitLab.com
- else
diff --git a/config/routes.rb b/config/routes.rb
index fde76b16064..3aadb732e6d 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -53,16 +53,16 @@ Gitlab::Application.routes.draw do
#
- # Importers
+ # Import
#
- namespace :importers do
- resource :github, only: [:create, :new] do
+ namespace :import do
+ resource :github, only: [:create, :new], controller: :github do
get :status
get :callback
get :jobs
end
- resource :gitlab, only: [:create, :new] do
+ resource :gitlab, only: [:create, :new], controller: :gitlab do
get :status
get :callback
get :jobs
diff --git a/doc/integration/gitlab.md b/doc/integration/gitlab.md
index 47f187b021c..b3b1d897225 100644
--- a/doc/integration/gitlab.md
+++ b/doc/integration/gitlab.md
@@ -15,7 +15,7 @@ To enable the GitLab OmniAuth provider you must register your application with G
- Redirect URI:
```
- http://gitlab.example.com/importers/gitlab/callback
+ http://gitlab.example.com/import/gitlab/callback
http://gitlab.example.com/users/auth/gitlab/callback
```
diff --git a/lib/gitlab/github_import/client.rb b/lib/gitlab/github_import/client.rb
index 2e454e7c10f..cf43d36c6c3 100644
--- a/lib/gitlab/github_import/client.rb
+++ b/lib/gitlab/github_import/client.rb
@@ -14,7 +14,7 @@ module Gitlab
private
def config
- Gitlab.config.omniauth.providers.select{|provider| provider.name == "github"}.first
+ Gitlab.config.omniauth.providers.find{|provider| provider.name == "github"}
end
def github_options
diff --git a/lib/gitlab/github_import/importer.rb b/lib/gitlab/github_import/importer.rb
index 180ad6c3018..91a4595b9ea 100644
--- a/lib/gitlab/github_import/importer.rb
+++ b/lib/gitlab/github_import/importer.rb
@@ -5,6 +5,7 @@ module Gitlab
def initialize(project)
@project = project
+ @formatter = Gitlab::ImportFormatter.new
end
def execute
@@ -13,12 +14,14 @@ module Gitlab
#Issues && Comments
client.list_issues(project.import_source, state: :all).each do |issue|
if issue.pull_request.nil?
- body = "*Created by: #{issue.user.login}*\n\n#{issue.body}"
+
+ body = @formatter.author_line(issue.user.login, issue.body)
if issue.comments > 0
- body += "\n\n\n**Imported comments:**\n"
+ body += @formatter.comments_header
+
client.issue_comments(project.import_source, issue.number).each do |c|
- body += "\n\n*By #{c.user.login} on #{c.created_at}*\n\n#{c.body}"
+ body += @formatter.comment_to_md(c.user.login, c.created_at, c.body)
end
end
diff --git a/lib/gitlab/gitlab_import/client.rb b/lib/gitlab/gitlab_import/client.rb
index 64e369e9c12..2206b68da99 100644
--- a/lib/gitlab/gitlab_import/client.rb
+++ b/lib/gitlab/gitlab_import/client.rb
@@ -13,7 +13,7 @@ module Gitlab
)
if access_token
- @api = OAuth2::AccessToken.from_hash(@client, :access_token => access_token)
+ @api = OAuth2::AccessToken.from_hash(@client, access_token: access_token)
end
end
@@ -67,7 +67,7 @@ module Gitlab
end
def config
- Gitlab.config.omniauth.providers.select{|provider| provider.name == "gitlab"}.first
+ Gitlab.config.omniauth.providers.find{|provider| provider.name == "gitlab"}
end
def github_options
diff --git a/lib/gitlab/gitlab_import/importer.rb b/lib/gitlab/gitlab_import/importer.rb
index 3e9087a556c..a529483c1e2 100644
--- a/lib/gitlab/gitlab_import/importer.rb
+++ b/lib/gitlab/gitlab_import/importer.rb
@@ -6,6 +6,7 @@ module Gitlab
def initialize(project)
@project = project
@client = Client.new(project.creator.gitlab_access_token)
+ @formatter = Gitlab::ImportFormatter.new
end
def execute
@@ -15,15 +16,16 @@ module Gitlab
issues = client.issues(project_identifier)
issues.each do |issue|
- body = "*Created by: #{issue["author"]["name"]}*\n\n#{issue["description"]}"
-
+ body = @formatter.author_line(issue["author"]["name"], issue["description"])
comments = client.issue_comments(project_identifier, issue["id"])
+
if comments.any?
- body += "\n\n\n**Imported comments:**\n"
+ body += @formatter.comments_header
end
+
comments.each do |comment|
- body += "\n\n*By #{comment["author"]["name"]} on #{comment["created_at"]}*\n\n#{comment["body"]}"
+ body += @formatter.comment_to_md(comment["author"]["name"], comment["created_at"], comment["body"])
end
project.issues.create!(
diff --git a/lib/gitlab/import_formatter.rb b/lib/gitlab/import_formatter.rb
new file mode 100644
index 00000000000..a9283eaf2a5
--- /dev/null
+++ b/lib/gitlab/import_formatter.rb
@@ -0,0 +1,15 @@
+module Gitlab
+ class ImportFormatter
+ def comment_to_md(author, date, body)
+ "\n\n*By #{author} on #{date}*\n\n#{body}"
+ end
+
+ def comments_header
+ "\n\n\n**Imported comments:**\n"
+ end
+
+ def author_line(author, body)
+ "*Created by: #{author}*\n\n#{body}"
+ end
+ end
+end \ No newline at end of file
diff --git a/spec/controllers/importers/githubs_controller_spec.rb b/spec/controllers/import/github_controller_spec.rb
index e21b5f8a470..ef93ff6f92f 100644
--- a/spec/controllers/importers/githubs_controller_spec.rb
+++ b/spec/controllers/import/github_controller_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe Importers::GithubsController do
+describe Import::GithubController do
let(:user) { create(:user, github_access_token: 'asd123') }
before do
@@ -16,7 +16,7 @@ describe Importers::GithubsController do
get :callback
user.reload.github_access_token.should == token
- controller.should redirect_to(status_importers_github_url)
+ controller.should redirect_to(status_import_github_url)
end
end
diff --git a/spec/controllers/importers/gitlabs_controller_spec.rb b/spec/controllers/import/gitlab_controller_spec.rb
index af42d14ded3..36995091c69 100644
--- a/spec/controllers/importers/gitlabs_controller_spec.rb
+++ b/spec/controllers/import/gitlab_controller_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe Importers::GitlabsController do
+describe Import::GitlabController do
let(:user) { create(:user, gitlab_access_token: 'asd123') }
before do
@@ -16,7 +16,7 @@ describe Importers::GitlabsController do
get :callback
user.reload.gitlab_access_token.should == token
- controller.should redirect_to(status_importers_gitlab_url)
+ controller.should redirect_to(status_import_gitlab_url)
end
end