From 64891c6c40c6b670c2b50aab8ba56e3d47e30076 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Sat, 21 Mar 2015 23:48:08 -0700 Subject: [PATCH 01/10] Replace commits calendar with contributions calendar * count opening of issues and merge requests * dont trigger git repository - use events from database * much-much faster since does not affected by repository size --- app/assets/javascripts/calendar.js.coffee | 2 +- app/controllers/users_controller.rb | 29 +++++---- app/models/project_contributions.rb | 32 --------- app/models/repository.rb | 35 ---------- app/views/users/calendar.html.haml | 2 +- app/views/users/calendar_activities.html.haml | 53 +++++++-------- lib/gitlab/commits_calendar.rb | 41 ------------ lib/gitlab/contributions_calendar.rb | 65 +++++++++++++++++++ 8 files changed, 104 insertions(+), 155 deletions(-) delete mode 100644 app/models/project_contributions.rb delete mode 100644 lib/gitlab/commits_calendar.rb create mode 100644 lib/gitlab/contributions_calendar.rb diff --git a/app/assets/javascripts/calendar.js.coffee b/app/assets/javascripts/calendar.js.coffee index 2891a48e249..99e7d3a029f 100644 --- a/app/assets/javascripts/calendar.js.coffee +++ b/app/assets/javascripts/calendar.js.coffee @@ -7,7 +7,7 @@ class @calendar constructor: (timestamps, starting_year, starting_month, calendar_activities_path) -> cal = new CalHeatMap() cal.init - itemName: ["commit"] + itemName: ["contribution"] data: timestamps start: new Date(starting_year, starting_month) domainLabelFormat: "%b" diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 68130eb128c..f39c820626f 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -31,9 +31,7 @@ class UsersController < ApplicationController end def calendar - projects = Project.where(id: authorized_projects_ids & @user.contributed_projects_ids) - - calendar = Gitlab::CommitsCalendar.new(projects, @user) + calendar = contributions_calendar @timestamps = calendar.timestamps @starting_year = calendar.starting_year @starting_month = calendar.starting_month @@ -42,20 +40,13 @@ class UsersController < ApplicationController end def calendar_activities - projects = Project.where(id: authorized_projects_ids & @user.contributed_projects_ids) + @calendar_date = Date.parse(params[:date]) rescue nil + @events = [] - date = Date.parse(params[:date]) rescue nil - if date - @calendar_activities = Gitlab::CommitsCalendar.get_commits_for_date(projects, @user, date) - else - @calendar_activities = {} + if @calendar_date + @events = contributions_calendar.events_by_date(@calendar_date) end - # get the total number of unique commits - @commit_count = @calendar_activities.values.flatten.map(&:id).uniq.count - - @calendar_date = date - render 'calendar_activities', layout: false end @@ -82,4 +73,14 @@ class UsersController < ApplicationController @authorized_projects_ids ||= ProjectsFinder.new.execute(current_user).pluck(:id) end + + def contributed_projects + @contributed_projects = Project. + where(id: authorized_projects_ids & @user.contributed_projects_ids).reject(&:forked?) + end + + def contributions_calendar + @contributions_calendar ||= Gitlab::ContributionsCalendar. + new(contributed_projects, @user) + end end diff --git a/app/models/project_contributions.rb b/app/models/project_contributions.rb deleted file mode 100644 index bfe9928b158..00000000000 --- a/app/models/project_contributions.rb +++ /dev/null @@ -1,32 +0,0 @@ -class ProjectContributions - attr_reader :project, :user - - def initialize(project, user) - @project, @user = project, user - end - - def commits_log - repository = project.repository - - if !repository.exists? || repository.empty? - return {} - end - - Rails.cache.fetch(cache_key) do - repository.commits_per_day_for_user(user) - end - end - - def user_commits_on_date(date) - repository = @project.repository - - if !repository.exists? || repository.empty? - return [] - end - commits = repository.commits_by_user_on_date_log(@user, date) - end - - def cache_key - "#{Date.today.to_s}-commits-log-#{project.id}-#{user.email}" - end -end diff --git a/app/models/repository.rb b/app/models/repository.rb index 082ad7a0c6a..77765cae1a0 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -149,41 +149,6 @@ class Repository end end - def timestamps_by_user_log(user) - author_emails = '(' + user.all_emails.map{ |e| Regexp.escape(e) }.join('|') + ')' - args = %W(git log -E --author=#{author_emails} --since=#{(Date.today - 1.year).to_s} --branches --pretty=format:%cd --date=short) - dates = Gitlab::Popen.popen(args, path_to_repo).first.split("\n") - - if dates.present? - dates - else - [] - end - end - - def commits_by_user_on_date_log(user, date) - # format the date string for git - start_date = date.strftime("%Y-%m-%d 00:00:00") - end_date = date.strftime("%Y-%m-%d 23:59:59") - - author_emails = '(' + user.all_emails.map{ |e| Regexp.escape(e) }.join('|') + ')' - args = %W(git log -E --author=#{author_emails} --after=#{start_date.to_s} --until=#{end_date.to_s} --branches --pretty=format:%h) - commits = Gitlab::Popen.popen(args, path_to_repo).first.split("\n") - - commits.map! do |commit_id| - commit(commit_id) - end - end - - def commits_per_day_for_user(user) - timestamps_by_user_log(user). - group_by { |commit_date| commit_date }. - inject({}) do |hash, (timestamp_date, commits)| - hash[timestamp_date] = commits.count - hash - end - end - def lookup_cache @lookup_cache ||= {} end diff --git a/app/views/users/calendar.html.haml b/app/views/users/calendar.html.haml index d113ceeb753..12446a209f8 100644 --- a/app/views/users/calendar.html.haml +++ b/app/views/users/calendar.html.haml @@ -1,4 +1,4 @@ -%h4 Commits calendar +%h4 Contributions calendar #cal-heatmap.calendar :javascript new calendar( diff --git a/app/views/users/calendar_activities.html.haml b/app/views/users/calendar_activities.html.haml index 7c0cecfadb5..4200233dc4b 100644 --- a/app/views/users/calendar_activities.html.haml +++ b/app/views/users/calendar_activities.html.haml @@ -1,33 +1,24 @@ .calendar_commit_activity - %hr - %h4 - Commit Activity - %strong - - if @commit_count == 0 - no - - else - = @commit_count - %span.calendar_commit_date - unique - = 'commit'.pluralize(@commit_count) - on - = @calendar_date.strftime("%b %d, %Y") rescue '' - -unless @commit_count == 0 - %hr - - @calendar_activities.each do |project, commits| - - next if commits.empty? - %div.js-toggle-container +%h4.prepend-top-20 + %span.light Contributions for + %strong #{@calendar_date.to_s(:short)} + +%ul.bordered-list + - @events.sort_by(&:created_at).each do |event| + %li + %span.light + %i.fa.fa-clock-o + = event.created_at.to_s(:time) + - if event.push? && event.commits_count > 0 + pushed #{event.commits_count} commits to + - else + = event_action_name(event) + - if event.target + %strong= link_to "##{event.target_iid}", [event.project.namespace.becomes(Namespace), event.project, event.target] + at + %strong - = pluralize(commits.count, 'commit') - in project - = link_to project.name_with_namespace, project_path(project) - %a.text-expander.js-toggle-button … - %hr - %div.js-toggle-content - - commits.each do |commit| - %span.monospace - = commit.committed_date.strftime("%H:%M") - = link_to commit.short_id, namespace_project_commit_path(project.namespace, project, commit), class: "commit_short_id" - = link_to commit.message, namespace_project_commit_path(project.namespace, project, commit), class: "commit-row-message str-truncated" - %br - %hr + - if event.project + = link_to_project event.project + - else + = event.project_name diff --git a/lib/gitlab/commits_calendar.rb b/lib/gitlab/commits_calendar.rb deleted file mode 100644 index 8963d346b6f..00000000000 --- a/lib/gitlab/commits_calendar.rb +++ /dev/null @@ -1,41 +0,0 @@ -module Gitlab - class CommitsCalendar - attr_reader :timestamps - - def initialize(projects, user) - @timestamps = {} - date_timestamps = [] - - projects.reject(&:forked?).each do |project| - date_timestamps << ProjectContributions.new(project, user).commits_log - end - - # Sumarrize commits from all projects per days - date_timestamps = date_timestamps.inject do |collection, date| - collection.merge(date) { |k, old_v, new_v| old_v + new_v } - end - - date_timestamps ||= [] - date_timestamps.each do |date, commits| - timestamp = Date.parse(date).to_time.to_i.to_s rescue nil - @timestamps[timestamp] = commits if timestamp - end - end - - def self.get_commits_for_date(projects, user, date) - user_commits = {} - projects.reject(&:forked?).each do |project| - user_commits[project] = ProjectContributions.new(project, user).user_commits_on_date(date) - end - user_commits - end - - def starting_year - (Time.now - 1.year).strftime("%Y") - end - - def starting_month - Date.today.strftime("%m").to_i - end - end -end diff --git a/lib/gitlab/contributions_calendar.rb b/lib/gitlab/contributions_calendar.rb new file mode 100644 index 00000000000..8ca5115d43a --- /dev/null +++ b/lib/gitlab/contributions_calendar.rb @@ -0,0 +1,65 @@ +module Gitlab + class ContributionsCalendar + attr_reader :timestamps, :projects, :user + + def initialize(projects, user) + @projects = projects + @user = user + end + + def timestamps + return @timestamps if @timestamps.present? + + @timestamps = {} + date_from = 1.year.ago + date_to = Date.today + + events = Event.where(author_id: user.id).where(action: event_type). + where("created_at > ?", date_from).where(project_id: projects) + + grouped_events = events.to_a.group_by { |event| event.created_at.to_date.to_s } + dates = (1.year.ago.to_date..(Date.today + 1.day)).to_a + + dates.each do |date| + date_id = date.to_time.to_i.to_s + @timestamps[date_id] = 0 + + if grouped_events.has_key?(date.to_s) + grouped_events[date.to_s].each do |event| + if event.created_at.to_date == date + if event.issue? || event.merge_request? + @timestamps[date_id] += 1 + elsif event.push? + @timestamps[date_id] += event.commits_count + end + end + end + end + end + + @timestamps + end + + def events_by_date(date) + events = Event.where(author_id: user.id).where(action: event_type). + where("created_at > ? AND created_at < ?", date.beginning_of_day, date.end_of_day). + where(project_id: projects) + + events.select do |event| + event.push? || event.issue? || event.merge_request? + end + end + + def starting_year + (Time.now - 1.year).strftime("%Y") + end + + def starting_month + Date.today.strftime("%m").to_i + end + + def event_type + [Event::PUSHED, Event::CREATED, Event::CLOSED, Event::MERGED] + end + end +end From 9c6086bc956a3fa57cb71eab744847b0206109e2 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Sun, 22 Mar 2015 11:01:45 -0700 Subject: [PATCH 02/10] Refactor repository specs --- spec/models/repository_spec.rb | 45 ++++++---------------------------- 1 file changed, 7 insertions(+), 38 deletions(-) diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index 0e3e0b167d7..f41e5a97ca3 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -13,47 +13,16 @@ describe Repository do it { is_expected.not_to include('fix') } end + describe :tag_names_contains do + subject { repository.tag_names_contains(sample_commit.id) } + + it { is_expected.to include('v1.1.0') } + it { is_expected.not_to include('v1.0.0') } + end + describe :last_commit_for_path do subject { repository.last_commit_for_path(sample_commit.id, '.gitignore').id } it { is_expected.to eq('c1acaa58bbcbc3eafe538cb8274ba387047b69f8') } end - - context :timestamps_by_user_log do - before do - Date.stub(:today).and_return(Date.new(2015, 03, 01)) - end - - describe 'single e-mail for user' do - let(:user) { create(:user, email: sample_commit.author_email) } - - subject { repository.timestamps_by_user_log(user) } - - it { is_expected.to eq(['2014-08-06', '2014-07-31', '2014-07-31']) } - end - - describe 'multiple emails for user' do - let(:email_alias) { create(:email, email: another_sample_commit.author_email) } - let(:user) { create(:user, email: sample_commit.author_email, emails: [email_alias]) } - - subject { repository.timestamps_by_user_log(user) } - - it { is_expected.to eq(['2015-01-10', '2014-08-06', '2014-07-31', '2014-07-31']) } - end - end - - context :commits_by_user_on_date_log do - - describe 'single e-mail for user' do - let(:user) { create(:user, email: sample_commit.author_email) } - let(:commit1) { '0ed8c6c6752e8c6ea63e7b92a517bf5ac1209c80' } - let(:commit2) { '7d3b0f7cff5f37573aea97cebfd5692ea1689924' } - - subject { repository.commits_by_user_on_date_log(user,Date.new(2014, 07, 31)) } - - it 'contains the exepected commits' do - expect(subject.flatten.map(&:id)).to eq([commit1, commit2]) - end - end - end end From 20a12438ab470afe1a5736fc46091a6ef4c30073 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Sun, 22 Mar 2015 11:14:42 -0700 Subject: [PATCH 03/10] Fix user controller specs --- spec/controllers/users_controller_spec.rb | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index 7962bcdde71..d47a37914df 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -25,34 +25,21 @@ describe UsersController do end describe 'GET #calendar_activities' do - include RepoHelpers - let(:project) { create(:project) } - let(:calendar_user) { create(:user, email: sample_commit.author_email) } - let(:commit1) { '0ed8c6c6752e8c6ea63e7b92a517bf5ac1209c80' } - let(:commit2) { '7d3b0f7cff5f37573aea97cebfd5692ea1689924' } + let!(:project) { create(:project) } + let!(:user) { create(:user) } before do allow_any_instance_of(User).to receive(:contributed_projects_ids).and_return([project.id]) project.team << [user, :developer] end - it 'assigns @commit_count' do - get :calendar_activities, username: calendar_user.username, date: '2014-07-31' - expect(assigns(:commit_count)).to eq(2) - end - it 'assigns @calendar_date' do - get :calendar_activities, username: calendar_user.username, date: '2014-07-31' + get :calendar_activities, username: user.username, date: '2014-07-31' expect(assigns(:calendar_date)).to eq(Date.parse('2014-07-31')) end - it 'assigns @calendar_activities' do - get :calendar_activities, username: calendar_user.username, date: '2014-07-31' - expect(assigns(:calendar_activities).values.flatten.map(&:id)).to eq([commit1, commit2]) - end - it 'renders calendar_activities' do - get :calendar_activities, username: calendar_user.username + get :calendar_activities, username: user.username expect(response).to render_template('calendar_activities') end end From 43afe46bbd19b1edf60abf3f104fb2b0d29af564 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Sun, 22 Mar 2015 13:55:00 -0700 Subject: [PATCH 04/10] Refactor contributions events and write tests for calendar --- app/controllers/users_controller.rb | 10 ++++---- app/models/event.rb | 6 +++++ app/models/user.rb | 7 ++---- app/views/users/_projects.html.haml | 2 +- features/steps/user.rb | 35 ++++++++++++++++++++++++++++ features/user.feature | 9 +++++++ lib/gitlab/contributions_calendar.rb | 8 ++----- 7 files changed, 59 insertions(+), 18 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index f39c820626f..f9b568b8af9 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -4,10 +4,7 @@ class UsersController < ApplicationController layout :determine_layout def show - @contributed_projects = Project. - where(id: authorized_projects_ids & @user.contributed_projects_ids). - in_group_namespace. - includes(:namespace). + @contributed_projects = contributed_projects.joined(@user). reject(&:forked?) @projects = @user.personal_projects. @@ -76,11 +73,12 @@ class UsersController < ApplicationController def contributed_projects @contributed_projects = Project. - where(id: authorized_projects_ids & @user.contributed_projects_ids).reject(&:forked?) + where(id: authorized_projects_ids & @user.contributed_projects_ids). + includes(:namespace) end def contributions_calendar @contributions_calendar ||= Gitlab::ContributionsCalendar. - new(contributed_projects, @user) + new(contributed_projects.reject(&:forked?), @user) end end diff --git a/app/models/event.rb b/app/models/event.rb index 2103a48a71b..57f6d5cd4e0 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -55,6 +55,12 @@ class Event < ActiveRecord::Base order('id DESC').limit(100). update_all(updated_at: Time.now) end + + def contributions + where("action = ? OR (target_type in (?) AND action in (?))", + Event::PUSHED, ["MergeRequest", "Issue"], + [Event::CREATED, Event::CLOSED, Event::MERGED]) + end end def proper? diff --git a/app/models/user.rb b/app/models/user.rb index ba325132df8..50f664a09a3 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -603,13 +603,10 @@ class User < ActiveRecord::Base end def contributed_projects_ids - Event.where(author_id: self). + Event.contributions.where(author_id: self). where("created_at > ?", Time.now - 1.year). - where("action = :pushed OR (target_type = 'MergeRequest' AND action = :created)", - pushed: Event::PUSHED, created: Event::CREATED). reorder(project_id: :desc). select(:project_id). - uniq - .map(&:project_id) + uniq.map(&:project_id) end end diff --git a/app/views/users/_projects.html.haml b/app/views/users/_projects.html.haml index 6c7779be30e..b7383d5594e 100644 --- a/app/views/users/_projects.html.haml +++ b/app/views/users/_projects.html.haml @@ -1,5 +1,5 @@ - if @contributed_projects.present? - .panel.panel-default + .panel.panel-default.contributed-projects .panel-heading Projects contributed to = render 'shared/projects_list', projects: @contributed_projects.sort_by(&:star_count).reverse, diff --git a/features/steps/user.rb b/features/steps/user.rb index d6f05ecb2c7..e6086bfc1c9 100644 --- a/features/steps/user.rb +++ b/features/steps/user.rb @@ -7,4 +7,39 @@ class Spinach::Features::User < Spinach::FeatureSteps step 'I should see user "John Doe" page' do expect(title).to match(/^\s*John Doe/) end + + step '"John Doe" has contributions' do + user = User.find_by(name: 'John Doe') + project = contributed_project + + # Issue controbution + issue_params = { title: 'Bug in old browser' } + Issues::CreateService.new(project, user, issue_params).execute + + # Push code contribution + push_params = { + project: project, + action: Event::PUSHED, + author_id: user.id, + data: { commit_count: 3 } + } + + Event.create(push_params) + end + + step 'I should see contributed projects' do + within '.contributed-projects' do + page.should have_content(@contributed_project.name) + end + end + + step 'I should see contributions calendar' do + within '.calendar' do + page.should have_css('.graph-rect.r2.q2') + end + end + + def contributed_project + @contributed_project ||= create(:project, :public) + end end diff --git a/features/user.feature b/features/user.feature index a2167935fd2..69618e929c4 100644 --- a/features/user.feature +++ b/features/user.feature @@ -67,3 +67,12 @@ Feature: User And I should see project "Enterprise" And I should not see project "Internal" And I should not see project "Community" + + @javascript + Scenario: "John Doe" contribution profile + Given I sign in as a user + And "John Doe" has contributions + When I visit user "John Doe" page + Then I should see user "John Doe" page + And I should see contributed projects + And I should see contributions calendar diff --git a/lib/gitlab/contributions_calendar.rb b/lib/gitlab/contributions_calendar.rb index 8ca5115d43a..ea41644811f 100644 --- a/lib/gitlab/contributions_calendar.rb +++ b/lib/gitlab/contributions_calendar.rb @@ -14,7 +14,7 @@ module Gitlab date_from = 1.year.ago date_to = Date.today - events = Event.where(author_id: user.id).where(action: event_type). + events = Event.contributions.where(author_id: user.id). where("created_at > ?", date_from).where(project_id: projects) grouped_events = events.to_a.group_by { |event| event.created_at.to_date.to_s } @@ -41,7 +41,7 @@ module Gitlab end def events_by_date(date) - events = Event.where(author_id: user.id).where(action: event_type). + events = Event.contributions.where(author_id: user.id). where("created_at > ? AND created_at < ?", date.beginning_of_day, date.end_of_day). where(project_id: projects) @@ -57,9 +57,5 @@ module Gitlab def starting_month Date.today.strftime("%m").to_i end - - def event_type - [Event::PUSHED, Event::CREATED, Event::CLOSED, Event::MERGED] - end end end From 54aca18cf856a18bdd121a3db25d2a64b9e0844d Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Sun, 22 Mar 2015 14:35:27 -0700 Subject: [PATCH 05/10] Contribution calendar will use events instead of commits to count contributions --- app/views/users/calendar.html.haml | 5 ++++- features/steps/user.rb | 2 +- lib/gitlab/contributions_calendar.rb | 19 +++++++------------ 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/app/views/users/calendar.html.haml b/app/views/users/calendar.html.haml index 12446a209f8..488f49267c7 100644 --- a/app/views/users/calendar.html.haml +++ b/app/views/users/calendar.html.haml @@ -1,4 +1,7 @@ -%h4 Contributions calendar +%h4 + Contributions calendar + .pull-right + %small Issues, merge requests and push events #cal-heatmap.calendar :javascript new calendar( diff --git a/features/steps/user.rb b/features/steps/user.rb index e6086bfc1c9..5939c28a000 100644 --- a/features/steps/user.rb +++ b/features/steps/user.rb @@ -35,7 +35,7 @@ class Spinach::Features::User < Spinach::FeatureSteps step 'I should see contributions calendar' do within '.calendar' do - page.should have_css('.graph-rect.r2.q2') + page.should have_css('.graph-rect.r3.q3') end end diff --git a/lib/gitlab/contributions_calendar.rb b/lib/gitlab/contributions_calendar.rb index ea41644811f..79e0a514f9e 100644 --- a/lib/gitlab/contributions_calendar.rb +++ b/lib/gitlab/contributions_calendar.rb @@ -15,25 +15,20 @@ module Gitlab date_to = Date.today events = Event.contributions.where(author_id: user.id). - where("created_at > ?", date_from).where(project_id: projects) + where("created_at > ?", date_from).where(project_id: projects). + group('date(created_at)'). + select('date(created_at), count(id) as total_amount'). + reorder(nil).map(&:attributes) - grouped_events = events.to_a.group_by { |event| event.created_at.to_date.to_s } dates = (1.year.ago.to_date..(Date.today + 1.day)).to_a dates.each do |date| date_id = date.to_time.to_i.to_s @timestamps[date_id] = 0 + day_events = events.find { |day_events| day_events["date"] == date } - if grouped_events.has_key?(date.to_s) - grouped_events[date.to_s].each do |event| - if event.created_at.to_date == date - if event.issue? || event.merge_request? - @timestamps[date_id] += 1 - elsif event.push? - @timestamps[date_id] += event.commits_count - end - end - end + if day_events + @timestamps[date_id] = day_events["total_amount"] end end From 7d84252e052de03431edf39d1f3eeebad34758be Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Sun, 22 Mar 2015 14:37:14 -0700 Subject: [PATCH 06/10] Update CHANGELOG with contribution calendar --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index cf00780d332..ff2ac6a095f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -23,6 +23,7 @@ v 7.10.0 (unreleased) - Restrict permissions on backup files - Improve oauth accounts UI in profile page - Add ability to unlink connected accounts + - Replace commits calendar with faster contribution calendar that includes issues and merge requests v 7.9.0 (unreleased) - Add HipChat integration documentation (Stan Hu) From 8494170550063c2d0308963cbd14cb46a292c401 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Sun, 22 Mar 2015 14:52:44 -0700 Subject: [PATCH 07/10] Improve contribution calendar per day info --- app/assets/javascripts/calendar.js.coffee | 3 --- app/assets/stylesheets/generic/calendar.scss | 21 ------------------- app/views/users/calendar_activities.html.haml | 7 +++---- lib/gitlab/contributions_calendar.rb | 4 ++-- 4 files changed, 5 insertions(+), 30 deletions(-) diff --git a/app/assets/javascripts/calendar.js.coffee b/app/assets/javascripts/calendar.js.coffee index 99e7d3a029f..d08ef9361a6 100644 --- a/app/assets/javascripts/calendar.js.coffee +++ b/app/assets/javascripts/calendar.js.coffee @@ -27,7 +27,6 @@ class @calendar legendCellPadding: 3 onClick: (date, count) -> formated_date = date.getFullYear() + "-" + (date.getMonth()+1) + "-" + date.getDate() - $(".calendar_commit_activity").fadeOut 400 $.ajax url: calendar_activities_path data: @@ -36,6 +35,4 @@ class @calendar dataType: "html" success: (data) -> $(".user-calendar-activities").html data - $(".calendar_commit_activity").find(".js-toggle-content").hide() - $(".calendar_commit_activity").fadeIn 400 diff --git a/app/assets/stylesheets/generic/calendar.scss b/app/assets/stylesheets/generic/calendar.scss index e2ab7fc51a5..a36fefe22c5 100644 --- a/app/assets/stylesheets/generic/calendar.scss +++ b/app/assets/stylesheets/generic/calendar.scss @@ -1,21 +1,8 @@ .user-calendar-activities { - - .calendar_commit_activity { - padding: 5px 0 0; - } - .calendar_onclick_hr { padding: 0; margin: 10px 0; } - - .calendar_commit_date { - color: #999; - } - - .calendar_activity_summary { - font-size: 14px; - } .str-truncated { max-width: 70%; @@ -31,14 +18,6 @@ background-color: #ddd; } } - - .commit-row-message { - color: #333; - &:hover { - color: #444; - text-decoration: underline; - } - } } /** * This overwrites the default values of the cal-heatmap gem diff --git a/app/views/users/calendar_activities.html.haml b/app/views/users/calendar_activities.html.haml index 4200233dc4b..027a93a75fc 100644 --- a/app/views/users/calendar_activities.html.haml +++ b/app/views/users/calendar_activities.html.haml @@ -1,4 +1,3 @@ -.calendar_commit_activity %h4.prepend-top-20 %span.light Contributions for %strong #{@calendar_date.to_s(:short)} @@ -9,14 +8,14 @@ %span.light %i.fa.fa-clock-o = event.created_at.to_s(:time) - - if event.push? && event.commits_count > 0 - pushed #{event.commits_count} commits to + - if event.push? + #{event.action_name} #{event.ref_type} #{event.ref_name} - else = event_action_name(event) - if event.target %strong= link_to "##{event.target_iid}", [event.project.namespace.becomes(Namespace), event.project, event.target] - at + at %strong - if event.project = link_to_project event.project diff --git a/lib/gitlab/contributions_calendar.rb b/lib/gitlab/contributions_calendar.rb index 79e0a514f9e..3fd0823df06 100644 --- a/lib/gitlab/contributions_calendar.rb +++ b/lib/gitlab/contributions_calendar.rb @@ -14,11 +14,11 @@ module Gitlab date_from = 1.year.ago date_to = Date.today - events = Event.contributions.where(author_id: user.id). + events = Event.reorder(nil).contributions.where(author_id: user.id). where("created_at > ?", date_from).where(project_id: projects). group('date(created_at)'). select('date(created_at), count(id) as total_amount'). - reorder(nil).map(&:attributes) + map(&:attributes) dates = (1.year.ago.to_date..(Date.today + 1.day)).to_a From b449bc5b77aa658db67ebcb25f709fe51c29b129 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Sun, 22 Mar 2015 19:47:23 -0700 Subject: [PATCH 08/10] Improve user calendar test --- features/steps/user.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/features/steps/user.rb b/features/steps/user.rb index 5939c28a000..10cae692a88 100644 --- a/features/steps/user.rb +++ b/features/steps/user.rb @@ -34,9 +34,7 @@ class Spinach::Features::User < Spinach::FeatureSteps end step 'I should see contributions calendar' do - within '.calendar' do - page.should have_css('.graph-rect.r3.q3') - end + page.should have_css('.cal-heatmap-container') end def contributed_project From a2e161cb35eb8b755ebdff92ab95f0fe4ca5d87d Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Mon, 23 Mar 2015 12:11:38 +0000 Subject: [PATCH 09/10] Bump Docker build to GitLab v7.9.0 --- docker/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 4eb280f9554..f34cbc38a54 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -11,7 +11,7 @@ RUN apt-get update -q \ # If the Omnibus package version below is outdated please contribute a merge request to update it. # If you run GitLab Enterprise Edition point it to a location where you have downloaded it. RUN TMP_FILE=$(mktemp); \ - wget -q -O $TMP_FILE https://downloads-packages.s3.amazonaws.com/ubuntu-14.04/gitlab_7.8.3-omnibus-1_amd64.deb \ + wget -q -O $TMP_FILE https://downloads-packages.s3.amazonaws.com/ubuntu-14.04/gitlab_7.9.0-omnibus.2-1_amd64.deb \ && dpkg -i $TMP_FILE \ && rm -f $TMP_FILE From a3daead1b00c28a16684cf11970ebd6da27511e2 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Mon, 23 Mar 2015 05:51:38 -0700 Subject: [PATCH 10/10] Include missing events and fix save functionality in admin service template settings form Closes #1275 --- CHANGELOG | 1 + app/controllers/admin/services_controller.rb | 4 ++- app/views/admin/services/_form.html.haml | 13 +++++++++ features/admin/settings.feature | 7 +++++ features/steps/admin/settings.rb | 29 ++++++++++++++++++++ 5 files changed, 53 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index f5a53747881..84f4446d017 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ Please view this file on the master branch, on stable branches it's out of date. v 7.10.0 (unreleased) + - Include missing events and fix save functionality in admin service template settings form (Stan Hu) - Fix "Import projects from" button to show the correct instructions (Stan Hu) - Fix dots in Wiki slugs causing errors (Stan Hu) - Update poltergeist to version 1.6.0 to support PhantomJS 2.0 (Zeger-Jan van de Weg) diff --git a/app/controllers/admin/services_controller.rb b/app/controllers/admin/services_controller.rb index 44a3f1379d8..76a938c5fe4 100644 --- a/app/controllers/admin/services_controller.rb +++ b/app/controllers/admin/services_controller.rb @@ -46,7 +46,9 @@ class Admin::ServicesController < Admin::ApplicationController :user_key, :device, :priority, :sound, :bamboo_url, :username, :password, :build_key, :server, :teamcity_url, :build_type, :description, :issues_url, :new_issue_url, :restrict_to_branch, - :send_from_committer_email, :disable_diffs + :send_from_committer_email, :disable_diffs, + :push_events, :tag_push_events, :note_events, :issues_events, + :merge_requests_events ]) end end diff --git a/app/views/admin/services/_form.html.haml b/app/views/admin/services/_form.html.haml index a953833b37c..18b7e8ba270 100644 --- a/app/views/admin/services/_form.html.haml +++ b/app/views/admin/services/_form.html.haml @@ -14,6 +14,11 @@ = preserve do = markdown @service.help + .form-group + = f.label :active, "Active", class: "control-label" + .col-sm-10 + = f.check_box :active + - if @service.supported_events.length > 1 .form-group = f.label :url, "Trigger", class: 'control-label' @@ -34,6 +39,14 @@ %strong Tag push events %p.light This url will be triggered when a new tag is pushed to the repository + - if @service.supported_events.include?("note") + %div + = f.check_box :note_events, class: 'pull-left' + .prepend-left-20 + = f.label :note_events, class: 'list-label' do + %strong Comments + %p.light + This url will be triggered when someone adds a comment - if @service.supported_events.include?("issue") %div = f.check_box :issues_events, class: 'pull-left' diff --git a/features/admin/settings.feature b/features/admin/settings.feature index 8fdf0575c2c..52e47307b23 100644 --- a/features/admin/settings.feature +++ b/features/admin/settings.feature @@ -7,3 +7,10 @@ Feature: Admin Settings Scenario: Change application settings When I modify settings and save form Then I should see application settings saved + + Scenario: Change Slack Service Template settings + When I click on "Service Templates" + And I click on "Slack" service + Then I check all events and submit form + And I should see service template settings saved + And I should see all checkboxes checked diff --git a/features/steps/admin/settings.rb b/features/steps/admin/settings.rb index c2d0d2a3fa3..87d4e969ff5 100644 --- a/features/steps/admin/settings.rb +++ b/features/steps/admin/settings.rb @@ -15,4 +15,33 @@ class Spinach::Features::AdminSettings < Spinach::FeatureSteps current_application_settings.home_page_url.should == 'https://about.gitlab.com/' page.should have_content 'Application settings saved successfully' end + + step 'I click on "Service Templates"' do + click_link 'Service Templates' + end + + step 'I click on "Slack" service' do + click_link 'Slack' + end + + step 'I check all events and submit form' do + page.check('Active') + page.check('Push events') + page.check('Tag push events') + page.check('Comments') + page.check('Issues events') + page.check('Merge Request events') + fill_in 'Webhook', with: "http://localhost" + click_on 'Save' + end + + step 'I should see service template settings saved' do + page.should have_content 'Application settings saved successfully' + end + + step 'I should see all checkboxes checked' do + all('input[type=checkbox]').each do |checkbox| + checkbox.should be_checked + end + end end