Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/gitlab/client/repositories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.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
# @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
4 changes: 3 additions & 1 deletion spec/fixtures/changelog.json
Original file line number Diff line number Diff line change
@@ -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"
}
1 change: 1 addition & 0 deletions spec/fixtures/generate_changelog.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
200
20 changes: 19 additions & 1 deletion spec/gitlab/client/repositories_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was this changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For stub response filenames to better correspond to method names in which test they are used.

BTW, I was the one who also added original generate_changelog method.

.with(body: { version: 'v1.0.0', branch: 'main' })
@changelog = Gitlab.generate_changelog(3, 'v1.0.0', branch: 'main')
end
Expand All @@ -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