diff options
author | Douwe Maan <douwe@gitlab.com> | 2016-11-23 10:13:29 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2016-11-23 10:13:29 +0000 |
commit | db02af3e2496203890c9ab1aa5a17eb891071682 (patch) | |
tree | 4116bb60b828d4ec543332e09f5f1225a5c98e50 | |
parent | 9f7fc6a0434399170ce1b089a6b00e11d0880f16 (diff) | |
parent | b938aa5cc83ffb51b516c7abfaaf6fe5e37031a6 (diff) | |
download | gitlab-ce-db02af3e2496203890c9ab1aa5a17eb891071682.tar.gz |
Merge branch 'fix/cycle-analytics-plan-issue' into 'master'
Fix cycle analytics plan stage when commits are missing
Takes into account when commits are `nil` so the app doesn't throw an exception and also removes them.
Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/24836
- [x] [Changelog entry](https://docs.gitlab.com/ce/development/changelog.html) added
- Tests
- [x] Added for this feature/bug
- [x] All builds are passing
- [x] Conform by the [merge request performance guides](http://docs.gitlab.com/ce/development/merge_request_performance_guidelines.html)
- [x] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides)
- [x] Branch has no merge conflicts with `master` (if it does - rebase it please)
- [ ] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits)
See merge request !7694
-rw-r--r-- | changelogs/unreleased/fix-cycle-analytics-plan-issue.yml | 4 | ||||
-rw-r--r-- | lib/gitlab/cycle_analytics/base_event.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/cycle_analytics/plan_event.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/cycle_analytics/plan_event_spec.rb | 8 |
4 files changed, 15 insertions, 1 deletions
diff --git a/changelogs/unreleased/fix-cycle-analytics-plan-issue.yml b/changelogs/unreleased/fix-cycle-analytics-plan-issue.yml new file mode 100644 index 00000000000..6ed16c6d722 --- /dev/null +++ b/changelogs/unreleased/fix-cycle-analytics-plan-issue.yml @@ -0,0 +1,4 @@ +--- +title: Fix cycle analytics plan stage when commits are missing +merge_request: +author: diff --git a/lib/gitlab/cycle_analytics/base_event.rb b/lib/gitlab/cycle_analytics/base_event.rb index 486139b1687..53a148ad703 100644 --- a/lib/gitlab/cycle_analytics/base_event.rb +++ b/lib/gitlab/cycle_analytics/base_event.rb @@ -16,7 +16,7 @@ module Gitlab event_result.map do |event| serialize(event) if has_permission?(event['id']) - end + end.compact end def custom_query(_base_query); end diff --git a/lib/gitlab/cycle_analytics/plan_event.rb b/lib/gitlab/cycle_analytics/plan_event.rb index b1ae215f348..7c3f0e9989f 100644 --- a/lib/gitlab/cycle_analytics/plan_event.rb +++ b/lib/gitlab/cycle_analytics/plan_event.rb @@ -27,6 +27,8 @@ module Gitlab end def first_time_reference_commit(commits, event) + return nil if commits.blank? + YAML.load(commits).find do |commit| next unless commit[:committed_date] && event['first_mentioned_in_commit_at'] diff --git a/spec/lib/gitlab/cycle_analytics/plan_event_spec.rb b/spec/lib/gitlab/cycle_analytics/plan_event_spec.rb index d76a255acf5..4a5604115ec 100644 --- a/spec/lib/gitlab/cycle_analytics/plan_event_spec.rb +++ b/spec/lib/gitlab/cycle_analytics/plan_event_spec.rb @@ -6,5 +6,13 @@ describe Gitlab::CycleAnalytics::PlanEvent do it 'has the default order' do expect(event.order).to eq(event.start_time_attrs) end + + context 'no commits' do + it 'does not blow up if there are no commits' do + allow_any_instance_of(Gitlab::CycleAnalytics::EventsQuery).to receive(:execute).and_return([{}]) + + expect { event.fetch }.not_to raise_error + end + end end end |