From 1e7598164beb6de7035101b984d4caa8073fdc78 Mon Sep 17 00:00:00 2001 From: Andrew Kumanyaev Date: Wed, 18 Jun 2014 11:20:56 +0400 Subject: Update markdown reference to external issues 1. Issue may be not only in jira. 2. Rewrite method for support different external issue trackers --- lib/gitlab/markdown.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/gitlab/markdown.rb b/lib/gitlab/markdown.rb index c04be788f07..e90de83a9b2 100644 --- a/lib/gitlab/markdown.rb +++ b/lib/gitlab/markdown.rb @@ -189,8 +189,12 @@ module Gitlab link_to("##{identifier}", url, options) end - elsif project.issues_tracker == 'jira' - reference_jira_issue(identifier, project) + else + config = Gitlab.config + external_issue_tracker = config.issues_tracker[project.issues_tracker] + if external_issue_tracker.present? + reference_external_issue(identifier, external_issue_tracker, project) + end end end @@ -226,9 +230,9 @@ module Gitlab end end - def reference_jira_issue(identifier, project = @project) + def reference_external_issue(identifier, issue_tracker, project = @project) url = url_for_issue(identifier) - title = Gitlab.config.issues_tracker[project.issues_tracker]["title"] + title = issue_tracker['title'] options = html_options.merge( title: "Issue in #{title}", -- cgit v1.2.1 From f789f29ca63df2050c7c4975957832b0a7cdab7d Mon Sep 17 00:00:00 2001 From: Andrew Kumanyaev Date: Mon, 18 Aug 2014 11:22:11 +0400 Subject: Update markdown.rb Fix mistake by @qqshfox report --- lib/gitlab/markdown.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/gitlab/markdown.rb b/lib/gitlab/markdown.rb index e90de83a9b2..bc718415f60 100644 --- a/lib/gitlab/markdown.rb +++ b/lib/gitlab/markdown.rb @@ -231,7 +231,7 @@ module Gitlab end def reference_external_issue(identifier, issue_tracker, project = @project) - url = url_for_issue(identifier) + url = url_for_issue(identifier, project) title = issue_tracker['title'] options = html_options.merge( -- cgit v1.2.1 From 11b707a62e437a24056eb9525176ce88678fb5c8 Mon Sep 17 00:00:00 2001 From: Andrew Kumanyaev Date: Wed, 20 Aug 2014 00:21:59 +0400 Subject: fix link_to by @bwrsandman Add missing '#' --- lib/gitlab/markdown.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/gitlab/markdown.rb b/lib/gitlab/markdown.rb index bc718415f60..50e6b1efca6 100644 --- a/lib/gitlab/markdown.rb +++ b/lib/gitlab/markdown.rb @@ -238,7 +238,7 @@ module Gitlab title: "Issue in #{title}", class: "gfm gfm-issue #{html_options[:class]}" ) - link_to("#{identifier}", url, options) + link_to("##{identifier}", url, options) end end end -- cgit v1.2.1 From 4cca1b050a0e80e4ce6bb67f530549a2f28af630 Mon Sep 17 00:00:00 2001 From: Charles Bushong Date: Fri, 29 Aug 2014 15:22:45 -0400 Subject: Adding in snippet search functionality http://feedback.gitlab.com/forums/176466-general/suggestions/5529795-search-though-snippets --- lib/gitlab/snippet_search_results.rb | 100 +++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 lib/gitlab/snippet_search_results.rb (limited to 'lib') diff --git a/lib/gitlab/snippet_search_results.rb b/lib/gitlab/snippet_search_results.rb new file mode 100644 index 00000000000..4b406c30f47 --- /dev/null +++ b/lib/gitlab/snippet_search_results.rb @@ -0,0 +1,100 @@ +module Gitlab + class SnippetSearchResults < SearchResults + attr_reader :limit_snippet_ids + + def initialize(limit_snippet_ids, query) + @limit_snippet_ids = limit_snippet_ids + @query = query + end + + def objects(scope, page = nil) + case scope + when 'snippet_titles' + Kaminari.paginate_array(snippet_titles).page(page).per(per_page) + when 'snippet_blobs' + Kaminari.paginate_array(snippet_blobs).page(page).per(per_page) + else + super + end + end + + def total_count + @total_count ||= snippet_titles_count + snippet_blobs_count + end + + def snippet_titles_count + @snippet_titles_count ||= snippet_titles.count + end + + def snippet_blobs_count + @snippet_blobs_count ||= snippet_blobs.count + end + + private + + def snippet_titles + Snippet.where(id: limit_snippet_ids).search(query).order('updated_at DESC') + end + + def snippet_blobs + matching_snippets = Snippet.where(id: limit_snippet_ids).search_code(query).order('updated_at DESC') + matching_snippets = matching_snippets.to_a + snippets = [] + matching_snippets.each { |e| snippets << chunk_snippet(e) } + snippets + end + + def default_scope + 'snippet_blobs' + end + + def bounded_line_numbers(line, min, max, surrounding_lines) + lower = line - surrounding_lines > min ? line - surrounding_lines : min + upper = line + surrounding_lines < max ? line + surrounding_lines : max + (lower..upper).to_a + end + + def chunk_snippet(snippet) + surrounding_lines = 3 + used_lines = [] + lined_content = snippet.content.split("\n") + lined_content.each_with_index { |line, line_number| + used_lines.concat bounded_line_numbers( + line_number, + 0, + lined_content.size, + surrounding_lines + ) if line.include?(query) + } + + used_lines = used_lines.uniq.sort + + snippet_chunk = [] + snippet_chunks = [] + snippet_start_line = 0 + last_line = -1 + used_lines.each { |line_number| + if last_line < 0 + snippet_start_line = line_number + snippet_chunk << lined_content[line_number] + elsif last_line == line_number - 1 + snippet_chunk << lined_content[line_number] + else + snippet_chunks << { + data: snippet_chunk.join("\n"), + start_line: snippet_start_line + 1 + } + snippet_chunk = [lined_content[line_number]] + snippet_start_line = line_number + end + last_line = line_number + } + snippet_chunks << { + data: snippet_chunk.join("\n"), + start_line: snippet_start_line + 1 + } + + { snippet_object: snippet, snippet_chunks: snippet_chunks } + end + end +end -- cgit v1.2.1 From 5e2bce0fef9e213842ee46ff406dd0e177fdec2d Mon Sep 17 00:00:00 2001 From: Ben Bodenmiller Date: Wed, 13 Aug 2014 22:55:41 -0700 Subject: change git to git bin path --- lib/tasks/gitlab/check.rake | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/tasks/gitlab/check.rake b/lib/tasks/gitlab/check.rake index 032ed5ee370..d15944bada3 100644 --- a/lib/tasks/gitlab/check.rake +++ b/lib/tasks/gitlab/check.rake @@ -322,7 +322,7 @@ namespace :gitlab do "core.autocrlf" => "input" } correct_options = options.map do |name, value| - run(%W(git config --global --get #{name})).try(:squish) == value + run(%W(#{Gitlab.config.git.bin_path} config --global --get #{name})).try(:squish) == value end if correct_options.all? @@ -330,9 +330,9 @@ namespace :gitlab do else puts "no".red try_fixing_it( - sudo_gitlab("git config --global user.name \"#{options["user.name"]}\""), - sudo_gitlab("git config --global user.email \"#{options["user.email"]}\""), - sudo_gitlab("git config --global core.autocrlf \"#{options["core.autocrlf"]}\"") + sudo_gitlab("\"#{Gitlab.config.git.bin_path}\" config --global user.name \"#{options["user.name"]}\""), + sudo_gitlab("\"#{Gitlab.config.git.bin_path}\" config --global user.email \"#{options["user.email"]}\""), + sudo_gitlab("\"#{Gitlab.config.git.bin_path}\" config --global core.autocrlf \"#{options["core.autocrlf"]}\"") ) for_more_information( see_installation_guide_section "GitLab" -- cgit v1.2.1 From b1411e90f81ea87ad45dee324b13881095e031ea Mon Sep 17 00:00:00 2001 From: Charles Bushong Date: Tue, 2 Sep 2014 08:33:23 -0400 Subject: Changing some formatting for the Hound, modifying some UI text --- lib/gitlab/snippet_search_results.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/gitlab/snippet_search_results.rb b/lib/gitlab/snippet_search_results.rb index 4b406c30f47..04217aab49f 100644 --- a/lib/gitlab/snippet_search_results.rb +++ b/lib/gitlab/snippet_search_results.rb @@ -37,10 +37,10 @@ module Gitlab end def snippet_blobs - matching_snippets = Snippet.where(id: limit_snippet_ids).search_code(query).order('updated_at DESC') - matching_snippets = matching_snippets.to_a + search = Snippet.where(id: limit_snippet_ids).search_code(query) + search = search.order('updated_at DESC').to_a snippets = [] - matching_snippets.each { |e| snippets << chunk_snippet(e) } + search.each { |e| snippets << chunk_snippet(e) } snippets end @@ -58,14 +58,14 @@ module Gitlab surrounding_lines = 3 used_lines = [] lined_content = snippet.content.split("\n") - lined_content.each_with_index { |line, line_number| + lined_content.each_with_index do |line, line_number| used_lines.concat bounded_line_numbers( line_number, 0, lined_content.size, surrounding_lines ) if line.include?(query) - } + end used_lines = used_lines.uniq.sort @@ -73,7 +73,7 @@ module Gitlab snippet_chunks = [] snippet_start_line = 0 last_line = -1 - used_lines.each { |line_number| + used_lines.each do |line_number| if last_line < 0 snippet_start_line = line_number snippet_chunk << lined_content[line_number] @@ -88,7 +88,7 @@ module Gitlab snippet_start_line = line_number end last_line = line_number - } + end snippet_chunks << { data: snippet_chunk.join("\n"), start_line: snippet_start_line + 1 -- cgit v1.2.1 From 551145bc98e257280b615e305d531a44d7aa4131 Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Sun, 27 Jul 2014 16:40:00 +0200 Subject: Validate branch-names and references in WebUI, API Add specs for GitRefValidator --- lib/api/branches.rb | 16 ++++++++++++---- lib/gitlab/git_ref_validator.rb | 11 +++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 lib/gitlab/git_ref_validator.rb (limited to 'lib') diff --git a/lib/api/branches.rb b/lib/api/branches.rb index b32a4aa7bc2..4db5f61dd28 100644 --- a/lib/api/branches.rb +++ b/lib/api/branches.rb @@ -80,9 +80,17 @@ module API # POST /projects/:id/repository/branches post ":id/repository/branches" do authorize_push_project - @branch = CreateBranchService.new.execute(user_project, params[:branch_name], params[:ref], current_user) - - present @branch, with: Entities::RepoObject, project: user_project + result = CreateBranchService.new.execute(user_project, + params[:branch_name], + params[:ref], + current_user) + if result[:status] == :success + present result[:branch], + with: Entities::RepoObject, + project: user_project + else + render_api_error!(result[:message], 400) + end end # Delete branch @@ -99,7 +107,7 @@ module API if result[:state] == :success true else - render_api_error!(result[:message], 405) + render_api_error!(result[:message], result[:return_code]) end end end diff --git a/lib/gitlab/git_ref_validator.rb b/lib/gitlab/git_ref_validator.rb new file mode 100644 index 00000000000..13cb08948bb --- /dev/null +++ b/lib/gitlab/git_ref_validator.rb @@ -0,0 +1,11 @@ +module Gitlab + module GitRefValidator + extend self + # Validates a given name against the git reference specification + # + # Returns true for a valid reference name, false otherwise + def validate(ref_name) + system *%W(git check-ref-format refs/#{ref_name}) + end + end +end -- cgit v1.2.1 From 392113919adc75ba1537d89a0de8d0641e24d5b8 Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Sun, 27 Jul 2014 19:56:33 +0200 Subject: Validate tag-names and references in WebUI, API --- lib/api/repositories.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/api/repositories.rb b/lib/api/repositories.rb index 42068bb343d..a3773d2c593 100644 --- a/lib/api/repositories.rb +++ b/lib/api/repositories.rb @@ -36,10 +36,15 @@ module API # POST /projects/:id/repository/tags post ':id/repository/tags' do authorize_push_project - @tag = CreateTagService.new.execute(user_project, params[:tag_name], - params[:ref], current_user) - - present @tag, with: Entities::RepoObject, project: user_project + result = CreateTagService.new.execute(user_project, params[:tag_name], + params[:ref], current_user) + if result[:status] == :success + present result[:tag], + with: Entities::RepoObject, + project: user_project + else + render_api_error!(result[:message], 400) + end end # Get a project repository tree -- cgit v1.2.1 From 93f15a49537a47e6a1dead5cec8553b974cd464d Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Wed, 3 Sep 2014 22:57:32 +0300 Subject: Explicit order of issues in API. Fixes specs for mysql db Signed-off-by: Dmitriy Zaporozhets --- lib/api/issues.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/api/issues.rb b/lib/api/issues.rb index 043ce04d321..15a49b452bd 100644 --- a/lib/api/issues.rb +++ b/lib/api/issues.rb @@ -8,7 +8,7 @@ module API case state when 'opened' then issues.opened when 'closed' then issues.closed - else issues + else issues.order('id DESC') end end end -- cgit v1.2.1 From 0ac4a933ffae00adc4b7ab58af9bef15ed8c412b Mon Sep 17 00:00:00 2001 From: jubianchi Date: Thu, 14 Aug 2014 16:17:19 +0200 Subject: Filters issues by labels via API --- lib/api/issues.rb | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/api/issues.rb b/lib/api/issues.rb index 15a49b452bd..e4a66eceadd 100644 --- a/lib/api/issues.rb +++ b/lib/api/issues.rb @@ -11,6 +11,10 @@ module API else issues.order('id DESC') end end + + def filter_issues_labels(issues, labels) + issues.includes(:labels).where("labels.title" => labels.split(',')) + end end resource :issues do @@ -18,13 +22,21 @@ module API # # Parameters: # state (optional) - Return "opened" or "closed" issues - # + # labels (optional) - Comma-separated list of label names + # Example Requests: # GET /issues # GET /issues?state=opened # GET /issues?state=closed + # GET /issues?labels=foo + # GET /issues?labels=foo,bar + # GET /issues?labels=foo,bar&state=opened get do - present paginate(filter_issues_state(current_user.issues, params['state'])), with: Entities::Issue + issues = current_user.issues + issues = filter_issues_state(issues, params[:state]) unless params[:state].nil? + issues = filter_issues_labels(issues, params[:labels]) unless params[:labels].nil? + + present paginate(issues), with: Entities::Issue end end @@ -34,13 +46,22 @@ module API # Parameters: # id (required) - The ID of a project # state (optional) - Return "opened" or "closed" issues + # labels (optional) - Comma-separated list of label names # # Example Requests: # GET /projects/:id/issues # GET /projects/:id/issues?state=opened # GET /projects/:id/issues?state=closed + # GET /projects/:id/issues + # GET /projects/:id/issues?labels=foo + # GET /projects/:id/issues?labels=foo,bar + # GET /projects/:id/issues?labels=foo,bar&state=opened get ":id/issues" do - present paginate(filter_issues_state(user_project.issues, params['state'])), with: Entities::Issue + issues = user_project.issues + issues = filter_issues_state(issues, params[:state]) unless params[:state].nil? + issues = filter_issues_labels(issues, params[:labels]) unless params[:labels].nil? + + present paginate(issues), with: Entities::Issue end # Get a single project issue -- cgit v1.2.1 From 468b2e8e0b46e7a7cee7cc9d9ce9b5c22e79c467 Mon Sep 17 00:00:00 2001 From: Sean Edge Date: Mon, 23 Jun 2014 21:35:36 -0400 Subject: Added annotated tags. Updated tag haml file and call to gitlab-shell. Updated API for annotated tags. Added tests for API. Strip leading/trailing whitespace from message, if present. Update CHANGELOG. --- lib/api/repositories.rb | 5 ++++- lib/gitlab/backend/shell.rb | 9 +++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/api/repositories.rb b/lib/api/repositories.rb index a3773d2c593..ce89177ef65 100644 --- a/lib/api/repositories.rb +++ b/lib/api/repositories.rb @@ -32,12 +32,15 @@ module API # id (required) - The ID of a project # tag_name (required) - The name of the tag # ref (required) - Create tag from commit sha or branch + # message (optional) - Specifying a message creates an annotated tag. # Example Request: # POST /projects/:id/repository/tags post ':id/repository/tags' do authorize_push_project + message = params[:message] || nil result = CreateTagService.new.execute(user_project, params[:tag_name], - params[:ref], current_user) + params[:ref], message, + current_user) if result[:status] == :success present result[:tag], with: Entities::RepoObject, diff --git a/lib/gitlab/backend/shell.rb b/lib/gitlab/backend/shell.rb index 53bff3037e5..907373ab991 100644 --- a/lib/gitlab/backend/shell.rb +++ b/lib/gitlab/backend/shell.rb @@ -107,12 +107,17 @@ module Gitlab # path - project path with namespace # tag_name - new tag name # ref - HEAD for new tag + # message - optional message for tag (annotated tag) # # Ex. # add_tag("gitlab/gitlab-ci", "v4.0", "master") + # add_tag("gitlab/gitlab-ci", "v4.0", "master", "message") # - def add_tag(path, tag_name, ref) - system "#{gitlab_shell_path}/bin/gitlab-projects", "create-tag", "#{path}.git", tag_name, ref + def add_tag(path, tag_name, ref, message = nil) + cmd = %W(#{gitlab_shell_path}/bin/gitlab-projects create-tag #{path}.git + #{tag_name} #{ref}) + cmd << message unless message.nil? || message.empty? + system *cmd end # Remove repository tag -- cgit v1.2.1 From 66516da3c1d7a5fda7876b564a7be00b17d38d25 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 4 Sep 2014 17:15:08 +0300 Subject: Explicit issues order in API. Fixes tests for mysql. Again :) Signed-off-by: Dmitriy Zaporozhets --- lib/api/issues.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/api/issues.rb b/lib/api/issues.rb index e4a66eceadd..5369149cdfc 100644 --- a/lib/api/issues.rb +++ b/lib/api/issues.rb @@ -8,7 +8,7 @@ module API case state when 'opened' then issues.opened when 'closed' then issues.closed - else issues.order('id DESC') + else issues end end @@ -35,6 +35,7 @@ module API issues = current_user.issues issues = filter_issues_state(issues, params[:state]) unless params[:state].nil? issues = filter_issues_labels(issues, params[:labels]) unless params[:labels].nil? + issues = issues.order('issues.id DESC') present paginate(issues), with: Entities::Issue end @@ -60,6 +61,7 @@ module API issues = user_project.issues issues = filter_issues_state(issues, params[:state]) unless params[:state].nil? issues = filter_issues_labels(issues, params[:labels]) unless params[:labels].nil? + issues = issues.order('issues.id DESC') present paginate(issues), with: Entities::Issue end -- cgit v1.2.1 From 3162140dfa30350a15caba662884ea9a24357ae9 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Fri, 5 Sep 2014 09:36:11 +0300 Subject: Fix tag tests Signed-off-by: Dmitriy Zaporozhets --- lib/api/repositories.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') diff --git a/lib/api/repositories.rb b/lib/api/repositories.rb index ce89177ef65..07c29aa7b4c 100644 --- a/lib/api/repositories.rb +++ b/lib/api/repositories.rb @@ -41,6 +41,7 @@ module API result = CreateTagService.new.execute(user_project, params[:tag_name], params[:ref], message, current_user) + if result[:status] == :success present result[:tag], with: Entities::RepoObject, -- cgit v1.2.1 From d93b046c4c7adf5a8fe37122864d7b1fabbd5bf6 Mon Sep 17 00:00:00 2001 From: Ralf Seidler Date: Fri, 5 Sep 2014 12:33:05 +0200 Subject: Added search wiki feature --- lib/gitlab/project_search_results.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/gitlab/project_search_results.rb b/lib/gitlab/project_search_results.rb index 90511662b20..5d959dfe0a5 100644 --- a/lib/gitlab/project_search_results.rb +++ b/lib/gitlab/project_search_results.rb @@ -14,13 +14,15 @@ module Gitlab notes.page(page).per(per_page) when 'blobs' Kaminari.paginate_array(blobs).page(page).per(per_page) + when 'wiki_blobs' + Kaminari.paginate_array(wiki_blobs).page(page).per(per_page) else super end end def total_count - @total_count ||= issues_count + merge_requests_count + blobs_count + notes_count + @total_count ||= issues_count + merge_requests_count + blobs_count + notes_count + wiki_blobs_count end def blobs_count @@ -31,6 +33,10 @@ module Gitlab @notes_count ||= notes.count end + def wiki_blobs_count + @wiki_blobs_count ||= wiki_blobs.count + end + private def blobs @@ -41,6 +47,14 @@ module Gitlab end end + def wiki_blobs + if !project.wiki_enabled? + [] + else + Repository.new(ProjectWiki.new(project).path_with_namespace).search_files(query) + end + end + def notes Note.where(project_id: limit_project_ids).search(query).order('updated_at DESC') end -- cgit v1.2.1 From 858dbd084253d2920d7007babe0471469eb459e7 Mon Sep 17 00:00:00 2001 From: Charles Bushong Date: Fri, 5 Sep 2014 13:30:55 -0400 Subject: Updating to persist a params snippets variable --- lib/gitlab/snippet_search_results.rb | 45 ++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/gitlab/snippet_search_results.rb b/lib/gitlab/snippet_search_results.rb index 04217aab49f..938219efdb2 100644 --- a/lib/gitlab/snippet_search_results.rb +++ b/lib/gitlab/snippet_search_results.rb @@ -48,53 +48,84 @@ module Gitlab 'snippet_blobs' end - def bounded_line_numbers(line, min, max, surrounding_lines) + # Get an array of line numbers surrounding a matching + # line, bounded by min/max. + # + # @returns Array of line numbers + def bounded_line_numbers(line, min, max) lower = line - surrounding_lines > min ? line - surrounding_lines : min upper = line + surrounding_lines < max ? line + surrounding_lines : max (lower..upper).to_a end - def chunk_snippet(snippet) - surrounding_lines = 3 + # Returns a sorted set of lines to be included in a snippet preview. + # This ensures matching adjacent lines do not display duplicated + # surrounding code. + # + # @returns Array, unique and sorted. + def matching_lines(lined_content) used_lines = [] - lined_content = snippet.content.split("\n") lined_content.each_with_index do |line, line_number| used_lines.concat bounded_line_numbers( line_number, 0, - lined_content.size, - surrounding_lines + lined_content.size ) if line.include?(query) end - used_lines = used_lines.uniq.sort + used_lines.uniq.sort + end + + # 'Chunkify' entire snippet. Splits the snippet data into matching lines + + # surrounding_lines() worth of unmatching lines. + # + # @returns a hash with {snippet_object, snippet_chunks:{data,start_line}} + def chunk_snippet(snippet) + lined_content = snippet.content.split("\n") + used_lines = matching_lines(lined_content) snippet_chunk = [] snippet_chunks = [] snippet_start_line = 0 last_line = -1 + + # Go through each used line, and add consecutive lines as a single chunk + # to the snippet chunk array. used_lines.each do |line_number| if last_line < 0 + # Start a new chunk. snippet_start_line = line_number snippet_chunk << lined_content[line_number] elsif last_line == line_number - 1 + # Consecutive line, continue chunk. snippet_chunk << lined_content[line_number] else + # Non-consecutive line, add chunk to chunk array. snippet_chunks << { data: snippet_chunk.join("\n"), start_line: snippet_start_line + 1 } + + # Start a new chunk. snippet_chunk = [lined_content[line_number]] snippet_start_line = line_number end last_line = line_number end + # Add final chunk to chunk array snippet_chunks << { data: snippet_chunk.join("\n"), start_line: snippet_start_line + 1 } + # Return snippet with chunk array { snippet_object: snippet, snippet_chunks: snippet_chunks } end + + # Defines how many unmatching lines should be + # included around the matching lines in a snippet + def surrounding_lines + 3 + end end end -- cgit v1.2.1 From 23241c181c0becdff17365aa49f80c05210f8b16 Mon Sep 17 00:00:00 2001 From: Ralf Seidler Date: Sat, 6 Sep 2014 11:46:14 +0200 Subject: Fixed houndci complaining over too long lines --- lib/gitlab/project_search_results.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/gitlab/project_search_results.rb b/lib/gitlab/project_search_results.rb index 5d959dfe0a5..736c22ecc77 100644 --- a/lib/gitlab/project_search_results.rb +++ b/lib/gitlab/project_search_results.rb @@ -22,7 +22,8 @@ module Gitlab end def total_count - @total_count ||= issues_count + merge_requests_count + blobs_count + notes_count + wiki_blobs_count + @total_count ||= issues_count + merge_requests_count + blobs_count + + notes_count + wiki_blobs_count end def blobs_count @@ -51,7 +52,8 @@ module Gitlab if !project.wiki_enabled? [] else - Repository.new(ProjectWiki.new(project).path_with_namespace).search_files(query) + Repository.new(ProjectWiki.new(project).path_with_namespace). + search_files(query) end end -- cgit v1.2.1 From 9f505954a602aae78032b385b2435cfae59c3a41 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Sat, 6 Sep 2014 13:20:37 +0300 Subject: Fix tests for CI Signed-off-by: Dmitriy Zaporozhets --- lib/gitlab/upgrader.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/gitlab/upgrader.rb b/lib/gitlab/upgrader.rb index 0846359f9b1..74b049b5143 100644 --- a/lib/gitlab/upgrader.rb +++ b/lib/gitlab/upgrader.rb @@ -43,7 +43,7 @@ module Gitlab end def latest_version_raw - remote_tags, _ = Gitlab::Popen.popen(%W(git ls-remote --tags origin)) + remote_tags, _ = Gitlab::Popen.popen(%W(git ls-remote --tags https://gitlab.com/gitlab-org/gitlab-ce.git)) git_tags = remote_tags.split("\n").grep(/tags\/v#{current_version.major}/) git_tags = git_tags.select { |version| version =~ /v\d\.\d\.\d\Z/ } last_tag = git_tags.last.match(/v\d\.\d\.\d/).to_s -- cgit v1.2.1 From 9edf6d4dd08d3bd74df22645a919dbf26d22faf7 Mon Sep 17 00:00:00 2001 From: Ralf Seidler Date: Sat, 6 Sep 2014 20:42:11 +0200 Subject: Fixed trailing white space --- lib/gitlab/project_search_results.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/gitlab/project_search_results.rb b/lib/gitlab/project_search_results.rb index 736c22ecc77..409177cb8bd 100644 --- a/lib/gitlab/project_search_results.rb +++ b/lib/gitlab/project_search_results.rb @@ -22,7 +22,7 @@ module Gitlab end def total_count - @total_count ||= issues_count + merge_requests_count + blobs_count + + @total_count ||= issues_count + merge_requests_count + blobs_count + notes_count + wiki_blobs_count end -- cgit v1.2.1 From c41e5f5018d059a9c57d2c19088e6c274cc60e10 Mon Sep 17 00:00:00 2001 From: Ben Bodenmiller Date: Sun, 7 Sep 2014 14:55:11 -0700 Subject: update ssl_ciphers taken from https://raymii.org/s/tutorials/Strong_SSL_Security_On_nginx.html / https://cipherli.st/ backwards compatible ciphers not needed since gitlab does not support ie8 --- lib/support/nginx/gitlab-ssl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/support/nginx/gitlab-ssl b/lib/support/nginx/gitlab-ssl index 9ab228b46d7..b438bce2184 100644 --- a/lib/support/nginx/gitlab-ssl +++ b/lib/support/nginx/gitlab-ssl @@ -76,7 +76,7 @@ server { ssl_certificate /etc/nginx/ssl/gitlab.crt; ssl_certificate_key /etc/nginx/ssl/gitlab.key; - ssl_ciphers 'ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4'; + ssl_ciphers 'AES256+EECDH:AES256+EDH'; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_session_cache builtin:1000 shared:SSL:10m; -- cgit v1.2.1 From 5d5d4ef91a31d39f15662a6a6bd8a314d860e608 Mon Sep 17 00:00:00 2001 From: Ben Bodenmiller Date: Sun, 7 Sep 2014 15:31:13 -0700 Subject: simplify HTTPS setup details also adds comment about updating nginx files during upgrades --- lib/support/nginx/gitlab-ssl | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'lib') diff --git a/lib/support/nginx/gitlab-ssl b/lib/support/nginx/gitlab-ssl index 9ab228b46d7..9f7e1e220c7 100644 --- a/lib/support/nginx/gitlab-ssl +++ b/lib/support/nginx/gitlab-ssl @@ -26,23 +26,12 @@ ## [1] https://github.com/agentzh/chunkin-nginx-module#status ## [2] https://github.com/agentzh/chunkin-nginx-module ## -################################### -## SSL file editing ## -################################### -## -## Edit `gitlab-shell/config.yml`: -## 1) Set "gitlab_url" param in `gitlab-shell/config.yml` to `https://git.example.com` -## 2) Set "ca_file" to `/etc/nginx/ssl/gitlab.crt` -## 3) Set "self_signed_cert" to `true` -## Edit `gitlab/config/gitlab.yml`: -## 1) Define port for http "port: 443" -## 2) Enable https "https: true" -## 3) Update ssl for gravatar "ssl_url: https://secure.gravatar.com/avatar/%{hash}?s=%{size}&d=mm" ## ################################### ## SSL configuration ## ################################### ## +## See installation.md#using-https for additional HTTPS configuration details. upstream gitlab { server unix:/home/git/gitlab/tmp/sockets/gitlab.socket; -- cgit v1.2.1 From a2b36858f537d0c580a3eb0d9164d6976767f15b Mon Sep 17 00:00:00 2001 From: Ben Bodenmiller Date: Sun, 7 Sep 2014 23:17:37 -0700 Subject: add optional nginx configs to make more secure --- lib/support/nginx/gitlab-ssl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'lib') diff --git a/lib/support/nginx/gitlab-ssl b/lib/support/nginx/gitlab-ssl index 9ab228b46d7..628439a0cf3 100644 --- a/lib/support/nginx/gitlab-ssl +++ b/lib/support/nginx/gitlab-ssl @@ -87,6 +87,23 @@ server { add_header X-Frame-Options SAMEORIGIN; add_header X-Content-Type-Options nosniff; + ## [Optional] If your certficate has OCSP, enable OCSP stapling to reduce the overhead and latency of running SSL. + ## Replace with your ssl_trusted_certificate. For more info see: + ## - https://medium.com/devops-programming/4445f4862461 + ## - https://www.ruby-forum.com/topic/4419319 + ## - https://www.digitalocean.com/community/tutorials/how-to-configure-ocsp-stapling-on-apache-and-nginx + # ssl_stapling on; + # ssl_stapling_verify on; + # ssl_trusted_certificate /etc/nginx/ssl/stapling.trusted.crt; + # resolver 208.67.222.222 208.67.222.220 valid=300s; # Can change to your DNS resolver if desired + # resolver_timeout 10s; + + ## [Optional] Generate a stronger DHE parameter: + ## cd /etc/ssl/certs + ## sudo openssl dhparam -out dhparam.pem 4096 + ## + # ssl_dhparam /etc/ssl/certs/dhparam.pem; + ## Individual nginx logs for this GitLab vhost access_log /var/log/nginx/gitlab_access.log; error_log /var/log/nginx/gitlab_error.log; -- cgit v1.2.1 From 1067b00724c045b4fa46a9f8ff5acd09d65553e0 Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Thu, 4 Sep 2014 10:46:35 +0200 Subject: Duplicate the behaviour and refactor for use with parallel diff. --- lib/gitlab/diff_parser.rb | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'lib') diff --git a/lib/gitlab/diff_parser.rb b/lib/gitlab/diff_parser.rb index b244295027e..baec2e63baa 100644 --- a/lib/gitlab/diff_parser.rb +++ b/lib/gitlab/diff_parser.rb @@ -50,6 +50,51 @@ module Gitlab end end + def each_for_parallel + line_old = 1 + line_new = 1 + type = nil + + lines_arr = ::Gitlab::InlineDiff.processing lines + + lines_arr.each_cons(2) do |line, next_line| + raw_line = line.dup + + next if filename?(line) + + full_line = html_escape(line.gsub(/\n/, '')) + full_line = ::Gitlab::InlineDiff.replace_markers full_line + + next_line = html_escape(next_line.gsub(/\n/, '')) + next_line = ::Gitlab::InlineDiff.replace_markers next_line + + if line.match(/^@@ -/) + type = "match" + + line_old = line.match(/\-[0-9]*/)[0].to_i.abs rescue 0 + line_new = line.match(/\+[0-9]*/)[0].to_i.abs rescue 0 + + next if line_old == 1 && line_new == 1 #top of file + yield(full_line, type, nil, line_new, line_old) + next + else + type = identification_type(line) + line_code = generate_line_code(new_path, line_new, line_old) + yield(full_line, type, line_code, line_new, line_old, next_line) + end + + + if line[0] == "+" + line_new += 1 + elsif line[0] == "-" + line_old += 1 + else + line_new += 1 + line_old += 1 + end + end + end + def empty? @lines.empty? end -- cgit v1.2.1 From f827482c12b3aeec2ed5f60afbf7c676e27435e3 Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Thu, 4 Sep 2014 11:25:14 +0200 Subject: Remove duplication, expand for next_line. --- lib/gitlab/diff_parser.rb | 43 +------------------------------------------ 1 file changed, 1 insertion(+), 42 deletions(-) (limited to 'lib') diff --git a/lib/gitlab/diff_parser.rb b/lib/gitlab/diff_parser.rb index baec2e63baa..f226692a63c 100644 --- a/lib/gitlab/diff_parser.rb +++ b/lib/gitlab/diff_parser.rb @@ -14,47 +14,6 @@ module Gitlab line_new = 1 type = nil - lines_arr = ::Gitlab::InlineDiff.processing lines - lines_arr.each do |line| - raw_line = line.dup - - next if filename?(line) - - full_line = html_escape(line.gsub(/\n/, '')) - full_line = ::Gitlab::InlineDiff.replace_markers full_line - - if line.match(/^@@ -/) - type = "match" - - line_old = line.match(/\-[0-9]*/)[0].to_i.abs rescue 0 - line_new = line.match(/\+[0-9]*/)[0].to_i.abs rescue 0 - - next if line_old == 1 && line_new == 1 #top of file - yield(full_line, type, nil, line_new, line_old) - next - else - type = identification_type(line) - line_code = generate_line_code(new_path, line_new, line_old) - yield(full_line, type, line_code, line_new, line_old, raw_line) - end - - - if line[0] == "+" - line_new += 1 - elsif line[0] == "-" - line_old += 1 - else - line_new += 1 - line_old += 1 - end - end - end - - def each_for_parallel - line_old = 1 - line_new = 1 - type = nil - lines_arr = ::Gitlab::InlineDiff.processing lines lines_arr.each_cons(2) do |line, next_line| @@ -80,7 +39,7 @@ module Gitlab else type = identification_type(line) line_code = generate_line_code(new_path, line_new, line_old) - yield(full_line, type, line_code, line_new, line_old, next_line) + yield(full_line, type, line_code, line_new, line_old, raw_line, next_line) end -- cgit v1.2.1 From 721b75733c49117100a5caf04bf6040fe6004dca Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Thu, 4 Sep 2014 14:13:24 +0200 Subject: Take the next type into consideration --- lib/gitlab/diff_parser.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/gitlab/diff_parser.rb b/lib/gitlab/diff_parser.rb index f226692a63c..3f402c4c238 100644 --- a/lib/gitlab/diff_parser.rb +++ b/lib/gitlab/diff_parser.rb @@ -38,8 +38,9 @@ module Gitlab next else type = identification_type(line) + next_type = identification_type(next_line) line_code = generate_line_code(new_path, line_new, line_old) - yield(full_line, type, line_code, line_new, line_old, raw_line, next_line) + yield(full_line, type, line_code, line_new, line_old, raw_line, next_type, next_line) end -- cgit v1.2.1 From 042465c448e73bb46ce7d159723a7c4805dad062 Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Mon, 8 Sep 2014 10:16:15 +0200 Subject: Use create-hooks instead of rewrite-hooks.sh The rewrite-hooks.sh script is a deprecated wrapper for gitlab-shell's create-hooks script. --- lib/backup/repository.rb | 2 +- lib/tasks/gitlab/check.rake | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/backup/repository.rb b/lib/backup/repository.rb index 6f7c4f7c909..ea05fa2c261 100644 --- a/lib/backup/repository.rb +++ b/lib/backup/repository.rb @@ -69,7 +69,7 @@ module Backup end print 'Put GitLab hooks in repositories dirs'.yellow - if system("#{Gitlab.config.gitlab_shell.path}/support/rewrite-hooks.sh", Gitlab.config.gitlab_shell.repos_path) + if system("#{Gitlab.config.gitlab_shell.path}/bin/create-hooks") puts " [DONE]".green else puts " [FAILED]".red diff --git a/lib/tasks/gitlab/check.rake b/lib/tasks/gitlab/check.rake index d15944bada3..9ea5c55abd6 100644 --- a/lib/tasks/gitlab/check.rake +++ b/lib/tasks/gitlab/check.rake @@ -541,7 +541,7 @@ namespace :gitlab do "sudo -u #{gitlab_shell_ssh_user} ln -sf #{gitlab_shell_hook_file} #{project_hook_file}" ) for_more_information( - "#{gitlab_shell_path}/support/rewrite-hooks.sh" + "#{gitlab_shell_path}/bin/create-hooks" ) fix_and_rerun next @@ -556,7 +556,7 @@ namespace :gitlab do "sudo -u #{gitlab_shell_ssh_user} ln -sf #{gitlab_shell_hook_file} #{project_hook_file}" ) for_more_information( - "lib/support/rewrite-hooks.sh" + "#{gitlab_shell_path}/bin/create-hooks" ) fix_and_rerun end -- cgit v1.2.1 From 4ef809c77d7f4155709a6d3f0188332c206ba0e0 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 8 Sep 2014 16:25:50 +0300 Subject: Gitlab::Diff classes added Signed-off-by: Dmitriy Zaporozhets --- lib/gitlab/diff/file.rb | 42 +++++++++++++++++++++++ lib/gitlab/diff/line.rb | 12 +++++++ lib/gitlab/diff/parser.rb | 86 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 140 insertions(+) create mode 100644 lib/gitlab/diff/file.rb create mode 100644 lib/gitlab/diff/line.rb create mode 100644 lib/gitlab/diff/parser.rb (limited to 'lib') diff --git a/lib/gitlab/diff/file.rb b/lib/gitlab/diff/file.rb new file mode 100644 index 00000000000..adc78616f64 --- /dev/null +++ b/lib/gitlab/diff/file.rb @@ -0,0 +1,42 @@ +module Gitlab + module Diff + class File + attr_reader :diff, :blob + + delegate :new_file, :deleted_file, :renamed_file, + :old_path, :new_path, to: :diff, prefix: false + + def initialize(project, commit, diff) + @diff = diff + @blob = project.repository.blob_for_diff(commit, diff) + end + + # Array of Gitlab::DIff::Line objects + def diff_lines + @lines ||= parser.parse(diff.diff.lines, old_path, new_path) + end + + def blob_exists? + !@blob.nil? + end + + def mode_changed? + diff.a_mode && diff.b_mode && diff.a_mode != diff.b_mode + end + + def parser + Gitlab::Diff::Parser.new + end + + def next_line(index) + diff_lines[index + 1] + end + + def prev_line(index) + if index > 0 + diff_lines[index - 1] + end + end + end + end +end diff --git a/lib/gitlab/diff/line.rb b/lib/gitlab/diff/line.rb new file mode 100644 index 00000000000..e8b9c980a1a --- /dev/null +++ b/lib/gitlab/diff/line.rb @@ -0,0 +1,12 @@ +module Gitlab + module Diff + class Line + attr_reader :type, :text, :index, :code, :old_pos, :new_pos + + def initialize(text, type, index, old_pos, new_pos, code = nil) + @text, @type, @index, @code = text, type, index, code + @old_pos, @new_pos = old_pos, new_pos + end + end + end +end diff --git a/lib/gitlab/diff/parser.rb b/lib/gitlab/diff/parser.rb new file mode 100644 index 00000000000..0fd11c69a59 --- /dev/null +++ b/lib/gitlab/diff/parser.rb @@ -0,0 +1,86 @@ +module Gitlab + module Diff + class Parser + include Enumerable + + def parse(lines, old_path, new_path) + @lines = lines, + lines_obj = [] + line_obj_index = 0 + line_old = 1 + line_new = 1 + type = nil + + lines_arr = ::Gitlab::InlineDiff.processing lines + + lines_arr.each do |line| + raw_line = line.dup + + next if filename?(line) + + full_line = html_escape(line.gsub(/\n/, '')) + full_line = ::Gitlab::InlineDiff.replace_markers full_line + + if line.match(/^@@ -/) + type = "match" + + line_old = line.match(/\-[0-9]*/)[0].to_i.abs rescue 0 + line_new = line.match(/\+[0-9]*/)[0].to_i.abs rescue 0 + + next if line_old == 1 && line_new == 1 #top of file + lines_obj << Gitlab::Diff::Line.new(full_line, type, line_obj_index, line_old, line_new) + line_obj_index += 1 + next + else + type = identification_type(line) + line_code = generate_line_code(new_path, line_new, line_old) + lines_obj << Gitlab::Diff::Line.new(full_line, type, line_obj_index, line_old, line_new, line_code) + line_obj_index += 1 + end + + + if line[0] == "+" + line_new += 1 + elsif line[0] == "-" + line_old += 1 + else + line_new += 1 + line_old += 1 + end + end + + lines_obj + end + + def empty? + @lines.empty? + end + + private + + def filename?(line) + line.start_with?('--- /dev/null', '+++ /dev/null', '--- a', '+++ b', + '--- /tmp/diffy', '+++ /tmp/diffy') + end + + def identification_type(line) + if line[0] == "+" + "new" + elsif line[0] == "-" + "old" + else + nil + end + end + + def generate_line_code(path, line_new, line_old) + "#{Digest::SHA1.hexdigest(path)}_#{line_old}_#{line_new}" + end + + def html_escape str + replacements = { '&' => '&', '>' => '>', '<' => '<', '"' => '"', "'" => ''' } + str.gsub(/[&"'><]/, replacements) + end + end + end +end -- cgit v1.2.1 From 531f16beb0a860a94f732f9e697a447513abe363 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 8 Sep 2014 16:27:12 +0300 Subject: Use new diff parsing logic Signed-off-by: Dmitriy Zaporozhets --- lib/gitlab/diff_parser.rb | 88 ----------------------------------------------- 1 file changed, 88 deletions(-) delete mode 100644 lib/gitlab/diff_parser.rb (limited to 'lib') diff --git a/lib/gitlab/diff_parser.rb b/lib/gitlab/diff_parser.rb deleted file mode 100644 index 3f402c4c238..00000000000 --- a/lib/gitlab/diff_parser.rb +++ /dev/null @@ -1,88 +0,0 @@ -module Gitlab - class DiffParser - include Enumerable - - attr_reader :lines, :new_path - - def initialize(lines, new_path = '') - @lines = lines - @new_path = new_path - end - - def each - line_old = 1 - line_new = 1 - type = nil - - lines_arr = ::Gitlab::InlineDiff.processing lines - - lines_arr.each_cons(2) do |line, next_line| - raw_line = line.dup - - next if filename?(line) - - full_line = html_escape(line.gsub(/\n/, '')) - full_line = ::Gitlab::InlineDiff.replace_markers full_line - - next_line = html_escape(next_line.gsub(/\n/, '')) - next_line = ::Gitlab::InlineDiff.replace_markers next_line - - if line.match(/^@@ -/) - type = "match" - - line_old = line.match(/\-[0-9]*/)[0].to_i.abs rescue 0 - line_new = line.match(/\+[0-9]*/)[0].to_i.abs rescue 0 - - next if line_old == 1 && line_new == 1 #top of file - yield(full_line, type, nil, line_new, line_old) - next - else - type = identification_type(line) - next_type = identification_type(next_line) - line_code = generate_line_code(new_path, line_new, line_old) - yield(full_line, type, line_code, line_new, line_old, raw_line, next_type, next_line) - end - - - if line[0] == "+" - line_new += 1 - elsif line[0] == "-" - line_old += 1 - else - line_new += 1 - line_old += 1 - end - end - end - - def empty? - @lines.empty? - end - - private - - def filename?(line) - line.start_with?('--- /dev/null', '+++ /dev/null', '--- a', '+++ b', - '--- /tmp/diffy', '+++ /tmp/diffy') - end - - def identification_type(line) - if line[0] == "+" - "new" - elsif line[0] == "-" - "old" - else - nil - end - end - - def generate_line_code(path, line_new, line_old) - "#{Digest::SHA1.hexdigest(path)}_#{line_old}_#{line_new}" - end - - def html_escape str - replacements = { '&' => '&', '>' => '>', '<' => '<', '"' => '"', "'" => ''' } - str.gsub(/[&"'><]/, replacements) - end - end -end -- cgit v1.2.1 From bde3f25d262b13d0139276786fe9d9cba29269b8 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 8 Sep 2014 20:42:12 +0300 Subject: Specs for diff parser! Yay! Signed-off-by: Dmitriy Zaporozhets --- lib/gitlab/diff/file.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/gitlab/diff/file.rb b/lib/gitlab/diff/file.rb index adc78616f64..62c0d38884a 100644 --- a/lib/gitlab/diff/file.rb +++ b/lib/gitlab/diff/file.rb @@ -21,7 +21,7 @@ module Gitlab end def mode_changed? - diff.a_mode && diff.b_mode && diff.a_mode != diff.b_mode + !!(diff.a_mode && diff.b_mode && diff.a_mode != diff.b_mode) end def parser -- cgit v1.2.1 From 218219abbdfdc3bc0bc1a9c95cfc0e0ddb5861dd Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 8 Sep 2014 21:54:52 +0300 Subject: Refactoring inside refactoring. We need to go deeper Signed-off-by: Dmitriy Zaporozhets --- lib/gitlab/diff/file.rb | 23 +++++++++++++++-------- lib/gitlab/diff/line.rb | 6 +++--- lib/gitlab/diff/line_code.rb | 9 +++++++++ lib/gitlab/diff/parser.rb | 9 ++------- 4 files changed, 29 insertions(+), 18 deletions(-) create mode 100644 lib/gitlab/diff/line_code.rb (limited to 'lib') diff --git a/lib/gitlab/diff/file.rb b/lib/gitlab/diff/file.rb index 62c0d38884a..19a1198c68c 100644 --- a/lib/gitlab/diff/file.rb +++ b/lib/gitlab/diff/file.rb @@ -1,23 +1,18 @@ module Gitlab module Diff class File - attr_reader :diff, :blob + attr_reader :diff delegate :new_file, :deleted_file, :renamed_file, :old_path, :new_path, to: :diff, prefix: false - def initialize(project, commit, diff) + def initialize(diff) @diff = diff - @blob = project.repository.blob_for_diff(commit, diff) end # Array of Gitlab::DIff::Line objects def diff_lines - @lines ||= parser.parse(diff.diff.lines, old_path, new_path) - end - - def blob_exists? - !@blob.nil? + @lines ||= parser.parse(raw_diff.lines) end def mode_changed? @@ -28,6 +23,10 @@ module Gitlab Gitlab::Diff::Parser.new end + def raw_diff + diff.diff + end + def next_line(index) diff_lines[index + 1] end @@ -37,6 +36,14 @@ module Gitlab diff_lines[index - 1] end end + + def file_path + if diff.new_path.present? + diff.new_path + elsif diff.old_path.present? + diff.old_path + end + end end end end diff --git a/lib/gitlab/diff/line.rb b/lib/gitlab/diff/line.rb index e8b9c980a1a..8ac1b15e88a 100644 --- a/lib/gitlab/diff/line.rb +++ b/lib/gitlab/diff/line.rb @@ -1,10 +1,10 @@ module Gitlab module Diff class Line - attr_reader :type, :text, :index, :code, :old_pos, :new_pos + attr_reader :type, :text, :index, :old_pos, :new_pos - def initialize(text, type, index, old_pos, new_pos, code = nil) - @text, @type, @index, @code = text, type, index, code + def initialize(text, type, index, old_pos, new_pos) + @text, @type, @index = text, type, index @old_pos, @new_pos = old_pos, new_pos end end diff --git a/lib/gitlab/diff/line_code.rb b/lib/gitlab/diff/line_code.rb new file mode 100644 index 00000000000..f3578ab3d35 --- /dev/null +++ b/lib/gitlab/diff/line_code.rb @@ -0,0 +1,9 @@ +module Gitlab + module Diff + class LineCode + def self.generate(file_path, new_line_position, old_line_position) + "#{Digest::SHA1.hexdigest(file_path)}_#{old_line_position}_#{new_line_position}" + end + end + end +end diff --git a/lib/gitlab/diff/parser.rb b/lib/gitlab/diff/parser.rb index 0fd11c69a59..9d6309954a4 100644 --- a/lib/gitlab/diff/parser.rb +++ b/lib/gitlab/diff/parser.rb @@ -3,7 +3,7 @@ module Gitlab class Parser include Enumerable - def parse(lines, old_path, new_path) + def parse(lines) @lines = lines, lines_obj = [] line_obj_index = 0 @@ -33,8 +33,7 @@ module Gitlab next else type = identification_type(line) - line_code = generate_line_code(new_path, line_new, line_old) - lines_obj << Gitlab::Diff::Line.new(full_line, type, line_obj_index, line_old, line_new, line_code) + lines_obj << Gitlab::Diff::Line.new(full_line, type, line_obj_index, line_old, line_new) line_obj_index += 1 end @@ -73,10 +72,6 @@ module Gitlab end end - def generate_line_code(path, line_new, line_old) - "#{Digest::SHA1.hexdigest(path)}_#{line_old}_#{line_new}" - end - def html_escape str replacements = { '&' => '&', '>' => '>', '<' => '<', '"' => '"', "'" => ''' } str.gsub(/[&"'><]/, replacements) -- cgit v1.2.1 From 685757b9d6c1c137c479288fe640c9440a785d71 Mon Sep 17 00:00:00 2001 From: Sytse Sijbrandij Date: Tue, 9 Sep 2014 10:11:07 +0200 Subject: Prevent people from using ci since we plan to host ci on /ci later. --- lib/gitlab/blacklist.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') diff --git a/lib/gitlab/blacklist.rb b/lib/gitlab/blacklist.rb index 65efb6e4407..43145e0ee1b 100644 --- a/lib/gitlab/blacklist.rb +++ b/lib/gitlab/blacklist.rb @@ -27,6 +27,7 @@ module Gitlab notes unsubscribes all + ci ) end end -- cgit v1.2.1 From 6b7e80cb198926a07e3fc94ca850edd4ed4169b8 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 9 Sep 2014 17:56:33 +0300 Subject: Prevent 500 error when search wiki for non-existing repo Signed-off-by: Dmitriy Zaporozhets --- lib/gitlab/project_search_results.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/gitlab/project_search_results.rb b/lib/gitlab/project_search_results.rb index 409177cb8bd..9dc8b34d9c7 100644 --- a/lib/gitlab/project_search_results.rb +++ b/lib/gitlab/project_search_results.rb @@ -49,11 +49,16 @@ module Gitlab end def wiki_blobs - if !project.wiki_enabled? - [] + if project.wiki_enabled? + wiki_repo = Repository.new(ProjectWiki.new(project).path_with_namespace) + + if wiki_repo.exists? + wiki_repo.search_files(query) + else + [] + end else - Repository.new(ProjectWiki.new(project).path_with_namespace). - search_files(query) + [] end end -- cgit v1.2.1