From 891fc6020868ee39eb0f98c144fba3eef82d3f97 Mon Sep 17 00:00:00 2001 From: Andrejs Date: Thu, 8 Apr 2021 16:53:57 +0300 Subject: [PATCH] add changelog endpoint (#607) --- lib/gitlab/client/repositories.rb | 21 +++++++++++++++++++++ spec/fixtures/changelog.json | 1 + spec/gitlab/client/repositories_spec.rb | 17 +++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 spec/fixtures/changelog.json diff --git a/lib/gitlab/client/repositories.rb b/lib/gitlab/client/repositories.rb index 47881bb32..b4bef1224 100644 --- a/lib/gitlab/client/repositories.rb +++ b/lib/gitlab/client/repositories.rb @@ -88,5 +88,26 @@ def contributors(project, options = {}) get("/projects/#{url_encode project}/repository/contributors", query: options) end alias repo_contributors contributors + + # Generate changelog data + # + # @example + # Gitlab.generate_changelog(42, 'v1.0.0') + # Gitlab.generate_changelog(42, 'v1.0.0', branch: 'main') + # + # @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] :branch The branch to commit the changelog changes to + # @option options [String] :trailer The Git trailer to use for including commits + # @option options [String] :file The file to commit the changes to + # @option options [String] :message The commit message to produce when committing the changes + # @return [bool] + def generate_changelog(project, version, options = {}) + post("/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 new file mode 100644 index 000000000..08839f6bb --- /dev/null +++ b/spec/fixtures/changelog.json @@ -0,0 +1 @@ +200 diff --git a/spec/gitlab/client/repositories_spec.rb b/spec/gitlab/client/repositories_spec.rb index 089069cf6..43a0abccb 100644 --- a/spec/gitlab/client/repositories_spec.rb +++ b/spec/gitlab/client/repositories_spec.rb @@ -129,4 +129,21 @@ expect(@contributors.first.commits).to eq(117) end end + + describe '.generate_changelog' do + before do + stub_post('/projects/3/repository/changelog', 'changelog') + .with(body: { version: 'v1.0.0', branch: 'main' }) + @changelog = Gitlab.generate_changelog(3, 'v1.0.0', branch: 'main') + end + + it 'gets the correct resource' do + expect(a_post('/projects/3/repository/changelog') + .with(body: { version: 'v1.0.0', branch: 'main' })).to have_been_made + end + + it 'returns successful result' do + expect(@changelog).to be_truthy + end + end end