Skip to content

Commit

Permalink
Autodetect version tags
Browse files Browse the repository at this point in the history
Implements coreinfrastructure#2139

Signed-off-by: Arnout Engelen <[email protected]>
  • Loading branch information
raboof committed Jun 20, 2024
1 parent a848094 commit a3e344e
Show file tree
Hide file tree
Showing 7 changed files with 501 additions and 8 deletions.
14 changes: 14 additions & 0 deletions app/lib/github_basic_detective.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class GithubBasicDetective < Detective
OUTPUTS = %i[
name license discussion_status repo_public_status repo_track_status
repo_distributed_status contribution_status implementation_languages
version_tags
].freeze

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

def version_shaped_tag_in(tag_data)
return tag_data.pluck(:name).any? { |tag| tag.match?(/^v?\d+\.\d+\.\d+$/) }
end

# Individual detectives must implement "analyze"
# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
Expand Down Expand Up @@ -170,6 +175,15 @@ def analyze(_evidence, current)
confidence: 3,
explanation: 'GitHub API implementation language analysis'
}

# Check for version tags
if version_shaped_tag_in(client.tags(fullname))
results[:version_tags] = {
value: 'Met',
confidence: 2,
explanation: 'GitHub tags'
}
end
end

results
Expand Down
8 changes: 8 additions & 0 deletions test/unit/lib/github_basic_detective_test.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ class GithubBasicDetectiveTest < ActiveSupport::TestCase
# stub test project by ciitest?
assert_equal 'Python', results[:implementation_languages][:value]

# Can we correctly detect version-shaped tags?
assert_equal 'Met', results[:version_tags][:value]

assert_not detective.version_shaped_tag_in([])
assert_not detective.version_shaped_tag_in([{ name: 'foobar' }])
assert detective.version_shaped_tag_in([{ name: '1.2.3' }])
assert detective.version_shaped_tag_in([{ name: '1.2.3' }, { name: 'foobar' }])

# Do several unit tests of language_cleanup, it's more complex.
# This does not invoke network calls, we are directly providing
# test values to more thoroughly test the method language_cleanup.
Expand Down
83 changes: 81 additions & 2 deletions test/vcr_cassettes/assimilation-official.yml

Large diffs are not rendered by default.

156 changes: 155 additions & 1 deletion test/vcr_cassettes/github.yml

Large diffs are not rendered by default.

82 changes: 81 additions & 1 deletion test/vcr_cassettes/github_project.yml

Large diffs are not rendered by default.

83 changes: 81 additions & 2 deletions test/vcr_cassettes/unit_test_github_basic_detective.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

83 changes: 81 additions & 2 deletions test/vcr_cassettes/users_manipulate_test.yml

Large diffs are not rendered by default.

0 comments on commit a3e344e

Please sign in to comment.