From e0b80edc65e359903e9f5135bd2b53158a5d6a20 Mon Sep 17 00:00:00 2001 From: Andrejs Cunskis Date: Sat, 18 Jun 2022 18:47:43 +0300 Subject: [PATCH 1/2] feat: Add get changelog data endpoint --- lib/gitlab/client/repositories.rb | 17 +++++++++++++++++ spec/fixtures/changelog.json | 4 +++- spec/fixtures/generate_changelog.json | 1 + spec/gitlab/client/repositories_spec.rb | 20 +++++++++++++++++++- 4 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 spec/fixtures/generate_changelog.json diff --git a/lib/gitlab/client/repositories.rb b/lib/gitlab/client/repositories.rb index b4bef1224..d351f130f 100644 --- a/lib/gitlab/client/repositories.rb +++ b/lib/gitlab/client/repositories.rb @@ -109,5 +109,22 @@ def contributors(project, options = {}) def generate_changelog(project, version, options = {}) post("/projects/#{url_encode project}/repository/changelog", body: options.merge(version: version)) end + + # Get changelog data + # + # @example + # Gitlab.generate_changelog(42, 'v1.0.0') + # + # @param [Integer, String] project The ID or name of a project + # @param [String] version The version to generate the changelog for + # @param [Hash] options A customizable set of options + # @option options [String] :from The start of the range of commits (SHA) + # @option options [String] :to The end of the range of commits (as a SHA) to use for the changelog + # @option options [String] :date The date and time of the release, defaults to the current time + # @option options [String] :trailer The Git trailer to use for including commits + # @return [Gitlab::ObjectifiedHash] + def get_changelog(project, version, options = {}) + get("/projects/#{url_encode project}/repository/changelog", body: options.merge(version: version)) + end end end diff --git a/spec/fixtures/changelog.json b/spec/fixtures/changelog.json index 08839f6bb..473e64a68 100644 --- a/spec/fixtures/changelog.json +++ b/spec/fixtures/changelog.json @@ -1 +1,3 @@ -200 +{ + "notes": "## 1.0.0 (2022-06-18)\n\n### Features (1 change)\n\n- [Test entry](gitlab@12a98e2bd52a2f17f78b87c3e489a216f9e52ea0) by @test. See merge request gitlab!1" +} diff --git a/spec/fixtures/generate_changelog.json b/spec/fixtures/generate_changelog.json new file mode 100644 index 000000000..08839f6bb --- /dev/null +++ b/spec/fixtures/generate_changelog.json @@ -0,0 +1 @@ +200 diff --git a/spec/gitlab/client/repositories_spec.rb b/spec/gitlab/client/repositories_spec.rb index 43a0abccb..c176703f2 100644 --- a/spec/gitlab/client/repositories_spec.rb +++ b/spec/gitlab/client/repositories_spec.rb @@ -132,7 +132,7 @@ describe '.generate_changelog' do before do - stub_post('/projects/3/repository/changelog', 'changelog') + stub_post('/projects/3/repository/changelog', 'generate_changelog') .with(body: { version: 'v1.0.0', branch: 'main' }) @changelog = Gitlab.generate_changelog(3, 'v1.0.0', branch: 'main') end @@ -146,4 +146,22 @@ expect(@changelog).to be_truthy end end + + describe '.get_changelog' do + before do + stub_get('/projects/3/repository/changelog', 'changelog') + .with(body: { version: 'v1.0.0' }) + @changelog = Gitlab.get_changelog(3, 'v1.0.0') + end + + it 'gets the correct resource' do + expect(a_get('/projects/3/repository/changelog') + .with(body: { version: 'v1.0.0' })).to have_been_made + end + + it 'returns changelog notes' do + expect(@changelog).to be_kind_of Gitlab::ObjectifiedHash + expect(@changelog.notes).to be_a String + end + end end From f59ccbdc46a1632c7395f2425cca3d09d3074114 Mon Sep 17 00:00:00 2001 From: Andrejs Date: Sat, 25 Jun 2022 21:47:37 +0300 Subject: [PATCH 2/2] Update lib/gitlab/client/repositories.rb Co-authored-by: Nihad Abbasov --- lib/gitlab/client/repositories.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/gitlab/client/repositories.rb b/lib/gitlab/client/repositories.rb index d351f130f..a28539764 100644 --- a/lib/gitlab/client/repositories.rb +++ b/lib/gitlab/client/repositories.rb @@ -113,7 +113,7 @@ def generate_changelog(project, version, options = {}) # Get changelog data # # @example - # Gitlab.generate_changelog(42, 'v1.0.0') + # Gitlab.get_changelog(42, 'v1.0.0') # # @param [Integer, String] project The ID or name of a project # @param [String] version The version to generate the changelog for