From 68cf8eaf4e563650187b4853ebb46ac14b2bc247 Mon Sep 17 00:00:00 2001 From: Matheus Roberto Date: Sat, 11 Nov 2017 17:35:11 -0200 Subject: [PATCH 01/11] Creating Burndown method in Sprints Signed-off-by: MateusO97 Signed-off-by: matheussbernardo --- app/controllers/sprints_controller.rb | 34 ++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/app/controllers/sprints_controller.rb b/app/controllers/sprints_controller.rb index fd0dcef..078cdbb 100644 --- a/app/controllers/sprints_controller.rb +++ b/app/controllers/sprints_controller.rb @@ -1,7 +1,7 @@ class SprintsController < ApplicationController include ValidationsHelper - before_action :set_sprint, only: [:show, :update, :destroy] + before_action :set_sprint, only: [:show, :update, :destroy, :burndown] before_action only: [:index, :create] do validate_release(0, :release_id) @@ -53,6 +53,38 @@ def destroy update_amount_of_sprints end + def burndown + total_points = 0 + burned_stories = {} + coordenates = [] + + for story in @sprint.stories + total_points += story.story_points + if(story.pipeline == "Done") + if(burned_stories[story.final_date] == nil) + burned_stories[story.final_date] = story.story_points + else + burned_stories[story.final_date] += story.story_points + end + end + end + + + range = (@sprint.initial_date .. @sprint.final_date) + + range.each do |date| + if burned_stories[date] == nil + burned_stories[date] = total_points + else + total_points -= burned_stories[date] + burned_stories[date] = total_points + end + coordanate = {x: date, y: burned_stories[date]} + coordenates.push(coordanate) + end + burned_stories = burned_stories.sort_by {|key, value| key} + render json: coordenates + end private # Use callbacks to share common setup or constraints between actions. def set_sprint From eb5f678d37304f6d67e8516f70f34a7df1eca1c9 Mon Sep 17 00:00:00 2001 From: MateusO97 Date: Sat, 11 Nov 2017 17:39:31 -0200 Subject: [PATCH 02/11] Changing Story controller and adding burndown routes Signed-off-by: matheussbernardo Signed-off-by: Matheus Roberto --- app/controllers/stories_controller.rb | 5 ++++- config/routes.rb | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index 2476587..458cbfa 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -39,6 +39,9 @@ def create def update if @story.update(story_params) + if @story.pipeline == "Done" + @story.final_date = Date.today + end render json: @story else render json: @story.errors, status: :unprocessable_entity @@ -55,6 +58,6 @@ def set_story end def story_params - params.require(:story).permit(:name, :description, :assign, :pipeline, :initial_date, :story_points) + params.require(:story).permit(:name, :description, :assign, :pipeline, :initial_date, :story_points, :final_date) end end diff --git a/config/routes.rb b/config/routes.rb index c45e246..7047a7b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,6 +3,8 @@ post "authenticate", to: "authentication#authenticate" post "request_github_token", to: "users#request_github_token" + get "sprints/:id/burndown", to: "sprints#burndown" + get "repos", to: "projects#github_projects_list" get "projects/:id/contributors", to: "projects#get_contributors" post "projects/:id/issues/assignees", to: "issues#update_assignees" From 9c78201c9f263e6258aeb4fe8aeb5165af2a3e60 Mon Sep 17 00:00:00 2001 From: MateusO97 Date: Sat, 11 Nov 2017 17:40:49 -0200 Subject: [PATCH 03/11] Adding Story points on Seed Signed-off-by: Matheus Roberto Signed-off-by: matheussbernardo --- db/schema.rb | 6 +++--- db/seeds.rb | 30 +++++++++++++++++++++++------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index df336de..26bbda1 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171107172605) do +ActiveRecord::Schema.define(version: 20171108135629) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -32,9 +32,9 @@ t.datetime "created_at", null: false t.datetime "updated_at", null: false t.bigint "user_id" - t.boolean "check_project" - t.boolean "is_project_from_github" t.string "github_slug" + t.boolean "is_project_from_github" + t.boolean "is_scoring" t.index ["user_id"], name: "index_projects_on_user_id" end diff --git a/db/seeds.rb b/db/seeds.rb index 8d14f47..11a253e 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -32,13 +32,15 @@ name: "Owla", description: "This project helps improving classes", user_id: "1", - is_project_from_github: true + is_project_from_github: true, + is_scoring: true ), Project.find_or_create_by( name: "Falko", description: "Agile Projects Manager", user_id: "2", - is_project_from_github: true + is_project_from_github: true, + is_scoring: true ) ] @@ -87,8 +89,8 @@ Sprint.find_or_create_by( name: "Sprint 2 - P1", description: "Second Sprint", - initial_date: "01-10-2016", - final_date: "01-12-2016", + initial_date: "01-01-2017", + final_date: "07-01-2017", release_id: "1" ), Sprint.find_or_create_by( @@ -116,6 +118,7 @@ pipeline: "Backlog", initial_date: "01/01/2017", final_date: "02/01/2017", + story_points: "10", sprint_id: "1" ), Story.find_or_create_by( @@ -125,22 +128,28 @@ pipeline: "Done", initial_date: "01/01/2017", final_date: "08/01/2017", + story_points: "10", sprint_id: "1" ), Story.find_or_create_by( name: "Story 1", description: "Story 1 us14", assign: "Matheus B", - pipeline: "In Progress", - initial_date: "03/01/2017", + pipeline: "Done", + initial_date: "01/01/2017", + final_date: "04/01/2017", + story_points: "10", sprint_id: "2" ), Story.find_or_create_by( name: "Story 2", description: "Story 2 us14", assign: "Matheus R", - pipeline: "Backlog", + pipeline: "Done", initial_date: "01/01/2017", + final_date: "04/01/2017", + sprint_id: "2", + story_points: "10", sprint_id: "2" ), Story.find_or_create_by( @@ -149,6 +158,8 @@ assign: "Matheus Roberto", pipeline: "In Progress", initial_date: "01/01/2017", + final_date: "04/01/2017", + story_points: "10", sprint_id: "3" ), Story.find_or_create_by( @@ -158,6 +169,7 @@ pipeline: "Done", initial_date: "07/01/2017", final_date: "15/01/2017", + story_points: "10", sprint_id: "3" ), Story.find_or_create_by( @@ -166,6 +178,8 @@ assign: "Vinícius", pipeline: "In Progress", initial_date: "01/01/2017", + final_date: "04/01/2017", + story_points: "10", sprint_id: "4" ), Story.find_or_create_by( @@ -174,6 +188,8 @@ assign: "Adrianne", pipeline: "In Progress", initial_date: "01/01/2017", + final_date: "04/01/2017", + story_points: "10", sprint_id: "4" ) ] From ae172d6cc012de17adb3a6270287d9cb49c6dc36 Mon Sep 17 00:00:00 2001 From: Matheus456 Date: Thu, 16 Nov 2017 23:13:50 -0200 Subject: [PATCH 04/11] Adding Burndown tests Signed-off-by: MateusO97 Signed-off-by: matheussbernardo --- test/controllers/sprints_controller_test.rb | 49 +++++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/test/controllers/sprints_controller_test.rb b/test/controllers/sprints_controller_test.rb index af5f5dd..48806bf 100644 --- a/test/controllers/sprints_controller_test.rb +++ b/test/controllers/sprints_controller_test.rb @@ -15,7 +15,7 @@ def setup description: "Some project description.", user_id: @user.id, is_project_from_github: true, - is_scoring: false + is_scoring: true ) @release = Release.create( @@ -30,11 +30,45 @@ def setup @sprint = Sprint.create( name: "Sprint 1", description: "Sprint 1 us10", - initial_date: "06/10/2017", - final_date: "13/10/2017", + initial_date: "01/01/2017", + final_date: "08/01/2017", release_id: @release.id ) + @story = Story.create( + name: "Story 1", + description: "Story 1 us14", + assign: "Lucas", + pipeline: "In progress", + initial_date: "01/01/2017", + story_points: "10", + sprint_id: @sprint.id + ) + + @story = Story.create( + name: "Story 2", + description: "Story 1 us14", + assign: "Lucas", + pipeline: "Done", + initial_date: "01/01/2017", + final_date: "07/01/2017", + story_points: "10", + sprint_id: @sprint.id + ) + + + @story = Story.create( + name: "Story 3", + description: "Story 1 us14", + assign: "Lucas", + pipeline: "Done", + initial_date: "01/01/2017", + final_date: "07/01/2017", + story_points: "10", + sprint_id: @sprint.id + ) + + @token = AuthenticateUser.call(@user.email, @user.password) @another_user = User.create( @@ -253,4 +287,13 @@ def setup assert_response :success end + + test "Should get Burndown data if project is scored" do + get "/sprints/#{@sprint.id}/burndown", headers: { Authorization: @token.result } + + assert_response :success + end + + + end From 8f043ee45244fd94d865cf2b21d9fa3fb1d80f05 Mon Sep 17 00:00:00 2001 From: Matheus Roberto Date: Fri, 17 Nov 2017 17:10:48 -0200 Subject: [PATCH 05/11] Fixing issue codeclimate Signed-off-by: Matheus Roberto --- app/controllers/sprints_controller.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/sprints_controller.rb b/app/controllers/sprints_controller.rb index 078cdbb..e9d526e 100644 --- a/app/controllers/sprints_controller.rb +++ b/app/controllers/sprints_controller.rb @@ -60,8 +60,8 @@ def burndown for story in @sprint.stories total_points += story.story_points - if(story.pipeline == "Done") - if(burned_stories[story.final_date] == nil) + if story.pipeline == "Done" + if burned_stories[story.final_date] == nil burned_stories[story.final_date] = story.story_points else burned_stories[story.final_date] += story.story_points @@ -79,10 +79,10 @@ def burndown total_points -= burned_stories[date] burned_stories[date] = total_points end - coordanate = {x: date, y: burned_stories[date]} + coordanate = { x: date, y: burned_stories[date] } coordenates.push(coordanate) end - burned_stories = burned_stories.sort_by {|key, value| key} + burned_stories = burned_stories.sort_by { |key, value| key } render json: coordenates end private From b1243f51e489bc834c93c90be5f65971c989c374 Mon Sep 17 00:00:00 2001 From: Matheus Roberto Date: Sat, 18 Nov 2017 14:31:43 -0200 Subject: [PATCH 06/11] Fixing seeds Signed-off-by: Matheus Roberto --- db/seeds.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/db/seeds.rb b/db/seeds.rb index 11a253e..605a52c 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -158,7 +158,6 @@ assign: "Matheus Roberto", pipeline: "In Progress", initial_date: "01/01/2017", - final_date: "04/01/2017", story_points: "10", sprint_id: "3" ), From 9ffd5d89596c695f9b5741d6c8f360e3f2bc90ba Mon Sep 17 00:00:00 2001 From: Matheus Roberto Date: Tue, 21 Nov 2017 08:26:12 -0200 Subject: [PATCH 07/11] Fixing tests of Sprints Signed-off-by: Matheus Roberto --- app/controllers/sprints_controller.rb | 4 ++-- config/routes.rb | 2 +- test/controllers/sprints_controller_test.rb | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/sprints_controller.rb b/app/controllers/sprints_controller.rb index abc43ba..4777d65 100644 --- a/app/controllers/sprints_controller.rb +++ b/app/controllers/sprints_controller.rb @@ -1,7 +1,7 @@ class SprintsController < ApplicationController include ValidationsHelper - before_action :set_sprint, only: [:show, :update, :destroy, :burndown] + before_action :set_sprint, only: [:show, :update, :destroy, :get_burndown] before_action only: [:index, :create] do validate_release(0, :release_id) @@ -61,7 +61,7 @@ def destroy update_amount_of_sprints end - def burndown + def get_burndown total_points = 0 burned_stories = {} coordenates = [] diff --git a/config/routes.rb b/config/routes.rb index 4d0d207..4a788c1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,7 +4,7 @@ post "request_github_token", to: "users#request_github_token" post "remove_github_token", to: "users#remove_github_token" - get "sprints/:id/burndown", to: "sprints#burndown" + get "sprints/:id/burndown", to: "sprints#get_burndown" get "repos", to: "projects#github_projects_list" get "projects/:id/contributors", to: "projects#get_contributors" diff --git a/test/controllers/sprints_controller_test.rb b/test/controllers/sprints_controller_test.rb index b933e59..2619c01 100644 --- a/test/controllers/sprints_controller_test.rb +++ b/test/controllers/sprints_controller_test.rb @@ -21,8 +21,8 @@ def setup @release = Release.create( name: "R1", description: "Description", - initial_date: "01/01/2018", - final_date: "01/01/2019", + initial_date: "01/01/2017", + final_date: "01/01/2020", amount_of_sprints: "20", project_id: @project.id ) @@ -178,7 +178,7 @@ def setup "name": "Sprint 02", "description": "Description of sprint", "initial_date": "13/10/2018", - "final_date": "25/12/2018" + "final_date": "17/10/2018" } }, headers: { Authorization: @token.result } From f11de16db93b1625b59ff4012cec1b338d17c4d9 Mon Sep 17 00:00:00 2001 From: MateusO97 Date: Tue, 21 Nov 2017 08:35:01 -0200 Subject: [PATCH 08/11] Fixing Seeds Signed-off-by: Matheus Roberto --- db/seeds.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/db/seeds.rb b/db/seeds.rb index d07d99a..34e6b87 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -183,7 +183,6 @@ assign: "Vinícius", pipeline: "In Progress", initial_date: "01/01/2017", - final_date: "04/01/2017", story_points: "10", sprint_id: "4" issue_number: "7", @@ -194,7 +193,6 @@ assign: "Adrianne", pipeline: "In Progress", initial_date: "01/01/2017", - final_date: "04/01/2017", story_points: "10", issue_number: "8", ) From f1d847c922e22f0ea6053e6af4a91bff91cceded Mon Sep 17 00:00:00 2001 From: Matheus Roberto Date: Tue, 21 Nov 2017 21:17:43 -0200 Subject: [PATCH 09/11] Adding validator to burndown Signed-off-by: Matheus Roberto --- app/controllers/sprints_controller.rb | 58 +++++++++++++-------------- 1 file changed, 27 insertions(+), 31 deletions(-) diff --git a/app/controllers/sprints_controller.rb b/app/controllers/sprints_controller.rb index 4777d65..aec2589 100644 --- a/app/controllers/sprints_controller.rb +++ b/app/controllers/sprints_controller.rb @@ -11,19 +11,15 @@ class SprintsController < ApplicationController validate_sprint(:id, 0) end - # GET /sprints def index - # @release used from validate_previous_release(:release_id) @sprints = @release.sprints.reverse render json: @sprints end - # GET /sprints/1 def show render json: @sprint end - # POST /sprints def create @sprint = Sprint.new(sprint_params) if validate_sprints_date("sprint", sprint_params) @@ -31,7 +27,6 @@ def create update_amount_of_sprints if @sprint.save render json: @sprint, status: :created - # @release used from validate_release @sprint.release = @release update_amount_of_sprints else @@ -42,7 +37,6 @@ def create end end - # PATCH/PUT /sprints/1 def update if validate_sprints_date("sprint", sprint_params) if @sprint.update(sprint_params) @@ -55,51 +49,53 @@ def update end end - # DELETE /sprints/1 def destroy @sprint.destroy update_amount_of_sprints end def get_burndown - total_points = 0 - burned_stories = {} - coordenates = [] + project = @sprint.release.project + if project.is_scoring != false + total_points = 0 + burned_stories = {} + coordenates = [] - for story in @sprint.stories - total_points += story.story_points - if story.pipeline == "Done" - if burned_stories[story.final_date] == nil - burned_stories[story.final_date] = story.story_points - else - burned_stories[story.final_date] += story.story_points + for story in @sprint.stories + total_points += story.story_points + if story.pipeline == "Done" + if burned_stories[story.final_date] == nil + burned_stories[story.final_date] = story.story_points + else + burned_stories[story.final_date] += story.story_points + end end end - end - range = (@sprint.initial_date .. @sprint.final_date) + range = (@sprint.initial_date .. @sprint.final_date) - range.each do |date| - if burned_stories[date] == nil - burned_stories[date] = total_points - else - total_points -= burned_stories[date] - burned_stories[date] = total_points + range.each do |date| + if burned_stories[date] == nil + burned_stories[date] = total_points + else + total_points -= burned_stories[date] + burned_stories[date] = total_points + end + coordanate = { x: date, y: burned_stories[date] } + coordenates.push(coordanate) end - coordanate = { x: date, y: burned_stories[date] } - coordenates.push(coordanate) + burned_stories = burned_stories.sort_by { |key, value| key } + render json: coordenates + else + render json: { error: "The Burndown Chart is only available in projects that use Story Points" }, status: :unprocessable_entity end - burned_stories = burned_stories.sort_by { |key, value| key } - render json: coordenates end private - # Use callbacks to share common setup or constraints between actions. def set_sprint @sprint = Sprint.find(params[:id]) end - # Only allow a trusted parameter "white list" through. def sprint_params params.require(:sprint).permit(:name, :description, :initial_date, :final_date, :release_id) end From fdf53b362795dfb1aa4e611108d177f9f3e65a4f Mon Sep 17 00:00:00 2001 From: Matheus Roberto Date: Tue, 21 Nov 2017 21:19:09 -0200 Subject: [PATCH 10/11] Fixing date of a Release on Seeds Signed-off-by: Matheus Roberto --- db/seeds.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/db/seeds.rb b/db/seeds.rb index 34e6b87..59cdc0b 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -71,7 +71,7 @@ Release.find_or_create_by( name: "R - 02", description: "Second Release", - initial_date: "01-10-2016", + initial_date: "01-01-2016", final_date: "01-12-2016", project_id: "2" ) @@ -119,8 +119,8 @@ initial_date: "01/01/2017", final_date: "02/01/2017", story_points: "10", - sprint_id: "1" issue_number: "1", + sprint_id: "1" ), Story.find_or_create_by( name: "Story 2", @@ -130,8 +130,8 @@ initial_date: "01/01/2017", final_date: "08/01/2017", story_points: "10", - sprint_id: "1" issue_number: "2", + sprint_id: "1" ), Story.find_or_create_by( name: "Story 1", @@ -141,8 +141,8 @@ initial_date: "01/01/2017", final_date: "04/01/2017", story_points: "10", - sprint_id: "2" issue_number: "3", + sprint_id: "2" ), Story.find_or_create_by( name: "Story 2", @@ -153,8 +153,8 @@ final_date: "04/01/2017", sprint_id: "2", story_points: "10", - sprint_id: "2" issue_number: "4", + sprint_id: "2" ), Story.find_or_create_by( name: "Story 1", @@ -163,8 +163,8 @@ pipeline: "In Progress", initial_date: "01/01/2017", story_points: "10", - sprint_id: "3" issue_number: "5", + sprint_id: "3" ), Story.find_or_create_by( name: "Story 2", @@ -174,8 +174,8 @@ initial_date: "07/01/2017", final_date: "15/01/2017", story_points: "10", - sprint_id: "3" issue_number: "6", + sprint_id: "3" ), Story.find_or_create_by( name: "Story 1", @@ -184,8 +184,8 @@ pipeline: "In Progress", initial_date: "01/01/2017", story_points: "10", - sprint_id: "4" issue_number: "7", + sprint_id: "4" ), Story.find_or_create_by( name: "Story 2", From 4af052593bf5351ad3cd96d9a5e69c4c25cc485a Mon Sep 17 00:00:00 2001 From: Matheus Roberto Date: Tue, 21 Nov 2017 21:19:37 -0200 Subject: [PATCH 11/11] Adding test to Sprint controller Signed-off-by: Matheus Roberto --- test/controllers/sprints_controller_test.rb | 40 +++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/test/controllers/sprints_controller_test.rb b/test/controllers/sprints_controller_test.rb index 2619c01..7d50057 100644 --- a/test/controllers/sprints_controller_test.rb +++ b/test/controllers/sprints_controller_test.rb @@ -103,6 +103,40 @@ def setup release_id: @another_release.id ) + @project_without_score = Project.create( + name: "Falko", + description: "Some project description.", + user_id: @user.id, + is_project_from_github: true, + is_scoring: false + ) + + @release_without_score = Release.create( + name: "R1", + description: "Description", + initial_date: "01/01/2017", + final_date: "01/01/2020", + amount_of_sprints: "20", + project_id: @project_without_score.id + ) + + @sprint_without_score = Sprint.create( + name: "Sprint 1", + description: "Sprint 1 us10", + initial_date: "01/01/2017", + final_date: "08/01/2017", + release_id: @release_without_score.id + ) + + @story_without_score = Story.create( + name: "Story 1", + description: "Story 1 us14", + assign: "Lucas", + pipeline: "In progress", + initial_date: "01/01/2017", + sprint_id: @sprint_without_score.id + ) + @another_token = AuthenticateUser.call(@another_user.email, @another_user.password) end @@ -294,6 +328,12 @@ def setup assert_response :success end + test "Should not get Burndown data if project is not scored" do + get "/sprints/#{@sprint_without_score.id}/burndown", headers: { Authorization: @token.result } + + assert_response :unprocessable_entity + end + test "should not create a sprint with a final date outside the release interval" do post "/releases/#{@release.id}/sprints", params: { "sprint": {