Skip to content

Commit 5437e77

Browse files
committed
Expose sprint goal in API representer
Adds a nullable `goal` property to `SprintRepresenter` that resolves the per-project goal text when a `goal_project:` context is provided. Returns `nil` otherwise. Updates the OpenAPI schema to match.
1 parent 3d9d109 commit 5437e77

3 files changed

Lines changed: 45 additions & 0 deletions

File tree

docs/api/apiv3/components/schemas/sprint_model.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ properties:
2323
description: Sprint name
2424
description:
2525
$ref: "./formattable.yml"
26+
goal:
27+
type:
28+
- "string"
29+
- "null"
30+
description: |-
31+
The sprint goal for the contextual project. Returns null when no
32+
project context is available.
2633
startDate:
2734
type:
2835
- "string"

modules/backlogs/lib/api/v3/sprints/sprint_representer.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,23 @@ class SprintRepresenter < ::API::Decorators::Single
6060

6161
date_property :finish_date
6262

63+
property :goal,
64+
render_nil: true,
65+
exec_context: :decorator,
66+
getter: ->(*) { goal_text }
67+
6368
date_time_property :created_at
6469
date_time_property :updated_at
6570

71+
def initialize(model, current_user:, embed_links: false, goal_project: nil)
72+
super(model, current_user:, embed_links:)
73+
@goal_project = goal_project
74+
end
75+
76+
def goal_text
77+
@goal_project ? represented.goal_for(@goal_project)&.goal : nil
78+
end
79+
6680
def _type
6781
"Sprint"
6882
end

modules/backlogs/spec/lib/api/v3/sprints/sprint_representer_rendering_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,30 @@
137137
end
138138
end
139139

140+
describe "goal" do
141+
context "without project context" do
142+
it_behaves_like "property", :goal do
143+
let(:value) { nil }
144+
end
145+
end
146+
147+
context "with project context and a goal set" do
148+
let(:sprint) { create(:sprint, project: workspace) }
149+
let(:workspace) { create(:project) }
150+
let(:representer) do
151+
described_class.new(sprint, current_user:, embed_links:, goal_project: workspace)
152+
end
153+
154+
before do
155+
create(:sprint_goal, sprint:, project: workspace, goal: "Deliver MVP")
156+
end
157+
158+
it "renders the goal text" do
159+
expect(generated).to be_json_eql("Deliver MVP".to_json).at_path("goal")
160+
end
161+
end
162+
end
163+
140164
describe "createdAt" do
141165
it_behaves_like "has UTC ISO 8601 date and time" do
142166
let(:date) { sprint.created_at }

0 commit comments

Comments
 (0)