Class: Neetob::CLI::MonthlyAudit::Security::Github::DependabotPrsMerged

Inherits:
Base
  • Object
show all
Defined in:
lib/neetob/cli/monthly_audit/security/github/dependabot_prs_merged.rb

Constant Summary

Constants inherited from Base

Base::NEETO_APPS_LIST_LINK

Instance Attribute Summary

Attributes inherited from Base

#ui

Instance Method Summary collapse

Methods included from Utils

#camel_case_to_slug, #is_upper?, #symbolize_keys

Constructor Details

#initializeDependabotPrsMerged

Returns a new instance of DependabotPrsMerged.



12
13
14
# File 'lib/neetob/cli/monthly_audit/security/github/dependabot_prs_merged.rb', line 12

def initialize
  super()
end

Instance Method Details

#runObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/neetob/cli/monthly_audit/security/github/dependabot_prs_merged.rb', line 16

def run
  ui.success("### 1.2.2. Checking whether all dependabot PRs created before 2 days have been merged")
  ui.info "\n"

  repo_data = [[
    "Repository",
    "All dependabot PRs older than 2 days have been merged",
    "Comments",
    "Audit Passed"
    ]
  ]
  NeetoCompliance::NeetoRepos.products.keys.each do |repo|
    ui.info "Checking #{repo}...", print_to_audit_log: false
    pull_requests = Neetob::CLI::Github::Repositories::PullRequests.new([repo]).run[0]
    dependabot_prs = pull_requests.select { |pr| pr[:user][:login] == "dependabot[bot]" }
    dependabot_prs_older_than_2_days = dependabot_prs.select { |pr| pr[:created_at] < 2.days.ago }
    dependabot_prs_older_than_2_days_merged = "No"
    audit_passed = "No"
    comments = nil
    if dependabot_prs_older_than_2_days.empty?
      audit_passed = dependabot_prs_older_than_2_days_merged = "Yes"
    else
      comments = "PRs older than 2 days: #{dependabot_prs_older_than_2_days.map { |pr| pr[:number] }.join(', ')}"
      issue_url = GithubIssueCreation.new.create_issue(
        repo:, title: "Merge Dependabot PRs older than 2 days",
        description: comments)
      audit_passed += " #{issue_url}"
    end
    repo_data << [repo, dependabot_prs_older_than_2_days_merged, comments, audit_passed]
  end
  ui.print_table(repo_data)
end