diff --git a/app/models/tpc_software_graduation_report_metric.rb b/app/models/tpc_software_graduation_report_metric.rb index 33c1df9..1ff6e7f 100644 --- a/app/models/tpc_software_graduation_report_metric.rb +++ b/app/models/tpc_software_graduation_report_metric.rb @@ -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') diff --git a/app/models/tpc_software_report_metric.rb b/app/models/tpc_software_report_metric.rb index 637915c..4f58651 100644 --- a/app/models/tpc_software_report_metric.rb +++ b/app/models/tpc_software_report_metric.rb @@ -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*" } })