Skip to content

Commit cc2793a

Browse files
committed
Add Rubygems.org version function
Added function to get latest version for a gem from rubygems.org Related: #24
1 parent bde2b42 commit cc2793a

File tree

8 files changed

+100
-5
lines changed

8 files changed

+100
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Added
9+
- Retrieve latest version for gem from rubygems.org
810

911
## [2.0.1] - 2020-02-19
1012
### Added

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,15 @@ files within it's directory.
194194
</ol>
195195
</td>
196196
</tr>
197+
<tr>
198+
<td><a href="test-utils/ruby">Ruby</a></td>
199+
<td>Helpers related to ruby infrastructure</td>
200+
<td>
201+
<ol>
202+
<li><b>bl_gem_latest_version</b>: Return the latest version of a gem from rubygems.org</li>
203+
</ol>
204+
</td>
205+
</tr>
197206
<tr>
198207
<td><a href="test-utils/lib">test-utils</a></td>
199208
<td>Helpers for executing tests</td>

init

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ BASH_LIB_DIR="${BASH_LIB_DIR_RELATIVE}"
2626

2727
# Load the filehandling module for the abspath
2828
# function
29-
for lib in helpers logging filehandling git github k8s test-utils; do
29+
for lib in helpers logging filehandling git github k8s test-utils ruby; do
3030
. "${BASH_LIB_DIR_RELATIVE}/${lib}/lib"
3131
done
3232

logging/lib

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,3 @@ function bl_error(){
6868
function bl_fatal(){
6969
bl_log fatal "${*}"
7070
}
71-

ruby/lib

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
: "${BASH_LIB_DIR:?BASH_LIB_DIR must be set. Please source bash-lib/init before other scripts from bash-lib.}"
2+
3+
function bl_gem_latest_version(){
4+
gem="${1:-}"
5+
if [[ -z "${gem}" ]]; then
6+
bl_fail "usage: bl_gem_version <gem name>"
7+
fi
8+
curl https://rubygems.org/api/v1/gems/${gem}.json \
9+
|jq -r '.version'
10+
}

run-tests

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,19 @@
55
# shellcheck disable=SC2086
66
. "$(dirname ${BASH_SOURCE[0]})/init"
77

8-
# Run BATS Tests
8+
bl_info "Checking the changelog complies with keepachangelog.com format"
9+
docker run \
10+
--rm \
11+
-v "${PWD}/CHANGELOG.md:/CHANGELOG.md" \
12+
cyberark/parse-a-changelog
13+
14+
bl_info "Running BATS Tests"
915
"${BASH_LIB_DIR}/tests-for-this-repo/run-bats-tests"
1016

11-
# Run Python Lint
17+
bl_info "Running Python Lint"
1218
"${BASH_LIB_DIR}/tests-for-this-repo/run-python-lint"
1319

14-
# Run gitleaks
20+
bl_info "Running gitleaks"
1521
"${BASH_LIB_DIR}/tests-for-this-repo/run-gitleaks"
22+
23+
bl_info "Sucess! All tests passed."
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"name": "parse_a_changelog",
3+
"downloads": 6660,
4+
"version": "1.0.1",
5+
"version_downloads": 168,
6+
"platform": "ruby",
7+
"authors": "John Tuttle",
8+
"info": "Uses a grammar describing the keep-a-changelog format to attempt to parse a given file.",
9+
"licenses": [
10+
"Apache-2.0"
11+
],
12+
"metadata": {},
13+
"yanked": false,
14+
"sha": "c081ae854570083ba56097d84a1fc66d47dd31f1a015edcb1ba2cbf9e2a4fe4a",
15+
"project_uri": "https://rubygems.org/gems/parse_a_changelog",
16+
"gem_uri": "https://rubygems.org/gems/parse_a_changelog-1.0.1.gem",
17+
"homepage_uri": "http://github.com/cyberark/parse-a-changelog",
18+
"wiki_uri": null,
19+
"documentation_uri": "http://www.rubydoc.info/gems/parse_a_changelog/1.0.1",
20+
"mailing_list_uri": null,
21+
"source_code_uri": null,
22+
"bug_tracker_uri": null,
23+
"changelog_uri": null,
24+
"dependencies": {
25+
"development": [
26+
{
27+
"name": "rspec",
28+
"requirements": "~> 3.8"
29+
},
30+
{
31+
"name": "rspec_junit_formatter",
32+
"requirements": "~> 0.4.1"
33+
}
34+
],
35+
"runtime": [
36+
{
37+
"name": "treetop",
38+
"requirements": "~> 1.6"
39+
}
40+
]
41+
}
42+
}

tests-for-this-repo/ruby.bats

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
. "${BASH_LIB_DIR}/test-utils/bats-support/load.bash"
2+
. "${BASH_LIB_DIR}/test-utils/bats-assert-1/load.bash"
3+
4+
. "${BASH_LIB_DIR}/init"
5+
6+
teardown(){
7+
unset curl
8+
}
9+
10+
@test "bl_gem_latest_version fails when no gem name is supplied" {
11+
run bl_gem_latest_version
12+
assert_failure
13+
assert_output --partial "usage"
14+
}
15+
16+
@test "bl_gem_latest_version returns only the version number" {
17+
curl(){
18+
fixtures_dir="${BASH_LIB_DIR}/tests-for-this-repo/fixtures/ruby"
19+
cat ${fixtures_dir}/ruby_gems_api_response.json
20+
}
21+
22+
run bl_gem_latest_version parse_a_changelog
23+
assert_success
24+
assert_output "1.0.1"
25+
}

0 commit comments

Comments
 (0)