Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autodetect version tags #2147

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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_status
].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_status] = {
value: 'Met',
confidence: 2,
explanation: 'Version tags are present in the code repository'
}
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_status][: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.