Skip to content

Commit

Permalink
Add REST/JSON interface to access an issue's release note
Browse files Browse the repository at this point in the history
  • Loading branch information
eivindt committed Nov 16, 2021
1 parent 357b586 commit 12d4b7f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
11 changes: 11 additions & 0 deletions app/controllers/release_notes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ def update
render_404
end

def view
@issue = Issue.find(params[:issue_id])
@release_note = @issue.release_note
@format = release_notes_format_from_params
@content = ReleaseNotesGenerator.new(nil, @format).generate_single(@release_note)

respond_to do |format|
format.api {}
end
end

def destroy
release_note = ReleaseNote.find(params[:id])
@issue = release_note.issue
Expand Down
8 changes: 8 additions & 0 deletions app/models/release_notes_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ def generate
generate_header << "\n" << generate_release_notes
end

def generate_single(release_note)
str = format.start
str << "\n"
str << make_substitutions(format.each_issue, values_for_issue(release_note.issue))
str << "\n"
str << format.end
end

private
def generate_header
make_substitutions(format.header, values_for_header(version))
Expand Down
7 changes: 7 additions & 0 deletions app/views/release_notes/view.api.rsb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
api.release_note do
api.id @release_note.id
api.issue_id @release_note.issue_id
api.status @issue.release_notes_custom_value.value
api.text @release_note.text
api.formatted @content
end
6 changes: 6 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
:to => "release_notes#generate",
:as => :generate_release_notes

get "/issues/:issue_id/release_notes",
:to => 'release_notes#view',
:as => :release_note_view,
defaults: { format: 'json' }


patch 'release_notes_formats/preview',
:to => 'release_notes_formats#preview',
:as => :preview_release_notes_format
Expand Down

0 comments on commit 12d4b7f

Please sign in to comment.