Skip to content

Commit 51c7f0d

Browse files
committed
Autodetect version tags
Implements #2139 Signed-off-by: Arnout Engelen <[email protected]>
1 parent a848094 commit 51c7f0d

File tree

7 files changed

+501
-8
lines changed

7 files changed

+501
-8
lines changed

app/lib/github_basic_detective.rb

100644100755
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class GithubBasicDetective < Detective
2020
OUTPUTS = %i[
2121
name license discussion_status repo_public_status repo_track_status
2222
repo_distributed_status contribution_status implementation_languages
23+
version_tags_status
2324
].freeze
2425

2526
# These are the 'correct' display case for SPDX for OSI-approved licenses.
@@ -73,6 +74,10 @@ def language_cleanup(raw_language_data)
7374
shorter_list.join(', ')
7475
end
7576

77+
def version_shaped_tag_in(tag_data)
78+
return tag_data.pluck(:name).any? { |tag| tag.match?(/^v?\d+\.\d+\.\d+$/) }
79+
end
80+
7681
# Individual detectives must implement "analyze"
7782
# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
7883
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
@@ -170,6 +175,15 @@ def analyze(_evidence, current)
170175
confidence: 3,
171176
explanation: 'GitHub API implementation language analysis'
172177
}
178+
179+
# Check for version tags
180+
if version_shaped_tag_in(client.tags(fullname))
181+
results[:version_tags_status] = {
182+
value: 'Met',
183+
confidence: 2,
184+
explanation: 'Version tags are present in the code repository'
185+
}
186+
end
173187
end
174188

175189
results

test/unit/lib/github_basic_detective_test.rb

100644100755
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ class GithubBasicDetectiveTest < ActiveSupport::TestCase
3737
# stub test project by ciitest?
3838
assert_equal 'Python', results[:implementation_languages][:value]
3939

40+
# Can we correctly detect version-shaped tags?
41+
assert_equal 'Met', results[:version_tags_status][:value]
42+
43+
assert_not detective.version_shaped_tag_in([])
44+
assert_not detective.version_shaped_tag_in([{ name: 'foobar' }])
45+
assert detective.version_shaped_tag_in([{ name: '1.2.3' }])
46+
assert detective.version_shaped_tag_in([{ name: '1.2.3' }, { name: 'foobar' }])
47+
4048
# Do several unit tests of language_cleanup, it's more complex.
4149
# This does not invoke network calls, we are directly providing
4250
# test values to more thoroughly test the method language_cleanup.

test/vcr_cassettes/assimilation-official.yml

Lines changed: 81 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/vcr_cassettes/github.yml

Lines changed: 155 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/vcr_cassettes/github_project.yml

Lines changed: 81 additions & 1 deletion
Large diffs are not rendered by default.

test/vcr_cassettes/unit_test_github_basic_detective.yml

Lines changed: 81 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/vcr_cassettes/users_manipulate_test.yml

Lines changed: 81 additions & 2 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)