Class: Danger::ManifestPRChecker

Inherits:
Plugin
  • Object
show all
Defined in:
lib/dangermattic/plugins/manifest_pr_checker.rb

Overview

Plugin to check if the a lock file (Gemfile.lock, Podfile.lock, Package.resolved) was updated when changing a manifest file (Gemfile, Podfile, Package.swift) in a PR.

Examples:

Running manifest / lock checks


# Check all manifest files (Gemfile, Podfile, Package.swift) have a corresponding lock change
checker.check_all_manifest_lock_updated

Gemfile check


# Check if the Gemfile and the Gemfile.lock are both updated
checker.check_gemfile_lock_updated

Podfile check


# Check if the Podfile and the Podfile.lock are both updated
checker.check_podfile_lock_updated

Package.swift check


# Check if the Package.swift and the Package.resolved are both updated
checker.check_swift_package_resolved_updated

See Also:

  • Automattic/dangermattic

Constant Summary collapse

MESSAGE =
'`%s` was changed without updating its corresponding `%s`. %s.'
SWIFT_INSTRUCTION =

The two new lines at the start are intentional. This will be interpolated in MESSAGE into the final %s. The first new line moves it to a new line, the second adds visual padding.

<<~INSTRUCTION


  If the change includes adding, removing, or editing a dependency please resolve the Swift packages as appropriate to your project setup (e.g. in Xcode or by running `swift package resolve`).

  If the change to the `Package.swift` did not modify dependencies, ignoring this warning should be safe, but we recommend double checking and running the package resolution just in case.
INSTRUCTION

Instance Method Summary collapse

Instance Method Details

#check_all_manifest_lock_updated(report_type: :warning) ⇒ void

This method returns an undefined value.

Performs all the checks, asserting that changes on Gemfile, Podfile and Package.swift must have corresponding lock file changes.

Parameters:

  • report_type (Symbol) (defaults to: :warning)

    (optional) The type of report for the message. Types: :error, :warning (default), :message.



50
51
52
53
54
# File 'lib/dangermattic/plugins/manifest_pr_checker.rb', line 50

def check_all_manifest_lock_updated(report_type: :warning)
  check_gemfile_lock_updated(report_type: report_type)
  check_podfile_lock_updated(report_type: report_type)
  check_swift_package_resolved_updated(report_type: report_type)
end

#check_gemfile_lock_updated(report_type: :warning) ⇒ void

This method returns an undefined value.

Check if the Gemfile file was modified without a corresponding Gemfile.lock update

Parameters:

  • report_type (Symbol) (defaults to: :warning)

    (optional) The type of report for the message. Types: :error, :warning (default), :message.



61
62
63
64
65
66
67
68
# File 'lib/dangermattic/plugins/manifest_pr_checker.rb', line 61

def check_gemfile_lock_updated(report_type: :warning)
  check_manifest_lock_updated(
    file_name: 'Gemfile',
    lock_file_name: 'Gemfile.lock',
    instruction: 'Please run `bundle install` or `bundle update <updated_gem>`',
    report_type: report_type
  )
end

#check_podfile_lock_updated(report_type: :warning) ⇒ void

This method returns an undefined value.

Check if the Podfile file was modified without a corresponding Podfile.lock update

Parameters:

  • report_type (Symbol) (defaults to: :warning)

    (optional) The type of report for the message. Types: :error, :warning (default), :message.



75
76
77
78
79
80
81
82
# File 'lib/dangermattic/plugins/manifest_pr_checker.rb', line 75

def check_podfile_lock_updated(report_type: :warning)
  check_manifest_lock_updated(
    file_name: 'Podfile',
    lock_file_name: 'Podfile.lock',
    instruction: 'Please run `bundle exec pod install`',
    report_type: report_type
  )
end

#check_swift_package_resolved_updated(report_type: :warning) ⇒ void

This method returns an undefined value.

Check if the Package.swift file was modified without a corresponding Package.resolved update

Parameters:

  • report_type (Symbol) (defaults to: :warning)

    (optional) The type of report for the message. Types: :error, :warning (default), :message.



89
90
91
92
93
94
95
96
# File 'lib/dangermattic/plugins/manifest_pr_checker.rb', line 89

def check_swift_package_resolved_updated(report_type: :warning)
  check_manifest_lock_updated(
    file_name: 'Package.swift',
    lock_file_name: 'Package.resolved',
    instruction: SWIFT_INSTRUCTION,
    report_type: report_type
  )
end

#check_swift_package_resolved_updated_strict(manifest_path:, manifest_lock_path:, report_type: :warning) ⇒ void

This method returns an undefined value.

Check if the Package.swift file was modified without a corresponding Package.resolved update, checking for exact path matches

Parameters:

  • manifest_path (String)

    The path to the Package.swift file.

  • manifest_lock_path (String)

    The path to the Package.resolved file.

  • report_type (Symbol) (defaults to: :warning)

    (optional) The type of report for the message. Types: :error, :warning (default), :message.



106
107
108
109
110
111
112
113
# File 'lib/dangermattic/plugins/manifest_pr_checker.rb', line 106

def check_swift_package_resolved_updated_strict(manifest_path:, manifest_lock_path:, report_type: :warning)
  check_manifest_lock_updated_strict(
    manifest_path: manifest_path,
    manifest_lock_path: manifest_lock_path,
    instruction: SWIFT_INSTRUCTION,
    report_type: report_type
  )
end