Skip to content

Commit

Permalink
Merge pull request #182 from xiaobokuai/main
Browse files Browse the repository at this point in the history
Update get_compliance_dco
  • Loading branch information
lishengbao authored Dec 18, 2024
2 parents dad28e2 + 3b86218 commit 3da8511
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 45 deletions.
50 changes: 25 additions & 25 deletions app/models/tpc_software_graduation_report_metric.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,38 +185,38 @@ def self.get_compliance_license_compatibility(scancode_result)
def self.get_compliance_dco(project_url,oh_commit_sha)
indexer, repo_urls =
select_idx_repos_by_lablel_and_level(project_url, "repo", GiteeGitEnrich, GithubGitEnrich)
if oh_commit_sha.present?

# commit_time_query = indexer.must(terms: { tag: repo_urls.map { |element| element + ".git" } })
# .must(term: { "hash.keyword": oh_commit_sha })
# .aggregate({ commit_time: { min: { field: "metadata__updated_on" } } })
# .per(0)
commit_time_query = indexer.must(terms: { tag: repo_urls.map { |element| element + ".git" } })
.must(match_phrase: { "hash": oh_commit_sha })
result = commit_time_query.execute
commit_time_query = indexer.must(terms: { tag: repo_urls.map { |element| element + ".git" } })
.must(match_phrase: { "hash": oh_commit_sha })
result = commit_time_query.execute

if result.results.nil?
return { compliance_dco: 6, compliance_dco_detail: { commit_count: 0, commit_dco_count: 0 }.to_json }
end
if result.results.nil?
return { compliance_dco: 6, compliance_dco_detail: { commit_count: 0, commit_dco_count: 0 }.to_json }
end

if result.results.first.nil?
return { compliance_dco: 6, compliance_dco_detail: { commit_count: 0, commit_dco_count: 0 }.to_json }
end
if result.results.first.nil?
return { compliance_dco: 6, compliance_dco_detail: { commit_count: 0, commit_dco_count: 0 }.to_json }
end

commit_time = result.results.first['commit_date']
commit_time = result.results.first['commit_date']

if commit_time.nil?
return { compliance_dco: 6, compliance_dco_detail: { commit_count: 0, commit_dco_count: 0 }.to_json }
if commit_time.nil?
return { compliance_dco: 6, compliance_dco_detail: { commit_count: 0, commit_dco_count: 0 }.to_json }
end
base = indexer.must(terms: { tag: repo_urls.map { |element| element + ".git" } })
.must(terms: { branches: ["'master'", "'main'"] })
.must(range: { commit_date: { gt: commit_time } })
.must_not(wildcard: { message: { value: "*Merge*" } })
.aggregate({ count: { cardinality: { field: "uuid" } } })
.per(0)
else
base = indexer.must(terms: { tag: repo_urls.map { |element| element + ".git" } })
.must_not(wildcard: { message: { value: "*Merge*" } })
.aggregate({ count: { cardinality: { field: "uuid" } } })
.per(0)
end

base = indexer.must(terms: { tag: repo_urls.map { |element| element + ".git" } })
.must(terms: { branches: ["'master'", "'main'"] })
.must(range: { commit_date: { gt: commit_time } })
.must_not(wildcard: { message: { value: "*Merge pull request*" } })
.must_not(wildcard: { message: { value: "*Merge branch*" } })
.must_not(wildcard: { message: { value: "*Merge remote*" } })
.aggregate({ count: { cardinality: { field: "uuid" } }})
.per(0)

commit_count = base.execute.aggregations.dig('count', 'value')
commit_dco_count = base.must(wildcard: { message: { value: "*Signed-off-by*" } })
.execute.aggregations.dig('count', 'value')
Expand Down
45 changes: 25 additions & 20 deletions app/models/tpc_software_report_metric.rb
Original file line number Diff line number Diff line change
Expand Up @@ -421,35 +421,40 @@ def self.get_ecology_software_quality(sonar_scanner_result)

def self.get_compliance_dco(project_url,oh_commit_sha)
indexer, repo_urls = select_idx_repos_by_lablel_and_level(project_url, "repo", GiteeGitEnrich, GithubGitEnrich)
if oh_commit_sha.present?
commit_time_query = indexer.must(terms: { tag: repo_urls.map { |element| element + ".git" } })
.must(match_phrase: { "hash": oh_commit_sha })
result = commit_time_query.execute

if result.results.nil?
return { compliance_dco: 6, compliance_dco_detail: { commit_count: 0, commit_dco_count: 0 }.to_json }
end

commit_time_query = indexer.must(terms: { tag: repo_urls.map { |element| element + ".git" } })
.must(match_phrase: { "hash": oh_commit_sha })
result = commit_time_query.execute
if result.results.first.nil?
return { compliance_dco: 6, compliance_dco_detail: { commit_count: 0, commit_dco_count: 0 }.to_json }
end

if result.results.nil?
return { compliance_dco: 6, compliance_dco_detail: { commit_count: 0, commit_dco_count: 0 }.to_json }
end
commit_time = result.results.first['commit_date']

if result.results.first.nil?
return { compliance_dco: 6, compliance_dco_detail: { commit_count: 0, commit_dco_count: 0 }.to_json }
end

commit_time = result.results.first['commit_date']
if commit_time.nil?
return { compliance_dco: 6, compliance_dco_detail: { commit_count: 0, commit_dco_count: 0 }.to_json }
end

base = indexer.must(terms: { tag: repo_urls.map { |element| element + ".git" } })
.must(terms: { branches: ["'master'", "'main'"] })
.must(range: { commit_date: { gt: commit_time } })
.must_not(wildcard: { message: { value: "*Merge*" } })
.aggregate({ count: { cardinality: { field: "uuid" } } })
.per(0)
else
base = indexer.must(terms: { tag: repo_urls.map { |element| element + ".git" } })
.must_not(wildcard: { message: { value: "*Merge*" } })
.aggregate({ count: { cardinality: { field: "uuid" } } })
.per(0)

if commit_time.nil?
return { compliance_dco: 6, compliance_dco_detail: { commit_count: 0, commit_dco_count: 0 }.to_json }
end

base = indexer.must(terms: { tag: repo_urls.map { |element| element + ".git" } })
.must(terms: { branches: ["'master'", "'main'"] })
.must(range: { commit_date: { gt: commit_time } })
.must_not(wildcard: { message: { value: "*Merge pull request*" } })
.must_not(wildcard: { message: { value: "*Merge branch*" } })
.must_not(wildcard: { message: { value: "*Merge remote*" } })
.aggregate({ count: { cardinality: { field: "uuid" } }})
.per(0)

commit_count = base.execute.aggregations.dig('count', 'value')
commit_dco_count = base.must(wildcard: { message: { value: "*Signed-off-by*" } })
Expand Down

0 comments on commit 3da8511

Please sign in to comment.