Class: Danger::PodfileChecker

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

Overview

Plugin for checking that the Podfile.lock doesn't contain direct commit references.

Examples:

Checking a Podfile for commit references:

podfile_checker.check_podfile_does_not_have_commit_references(podfile_lock_path: './aLib/Podfile.lock')

Checking Git diffs for Podfile.lock commit references:

podfile_checker.check_podfile_diff_does_not_have_commit_references

See Also:

  • Automattic/dangermattic

Constant Summary collapse

PODFILE_LOCK =
'Podfile.lock'
PODFILE_LOCK_DEPENDENCIES_ENTRY =
'DEPENDENCIES'
DEFAULT_PODFILE_LOCK_PATH =
'./Podfile.lock'

Instance Method Summary collapse

Instance Method Details

#check_podfile_diff_does_not_have_branch_references(report_type: :warning) ⇒ void

This method returns an undefined value.

Check for Podfile references to branches in the Podfile.lock in a pull request.

Parameters:

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

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



81
82
83
84
# File 'lib/dangermattic/plugins/podfile_checker.rb', line 81

def check_podfile_diff_does_not_have_branch_references(report_type: :warning)
  warning_message = 'This PR adds a Podfile reference to a branch:'
  check_podfile_diff_entries_do_not_match(regexp: BRANCH_REFERENCE_REGEXP, match_found_message: warning_message, report_type: report_type)
end

#check_podfile_diff_does_not_have_commit_references(report_type: :warning) ⇒ void

This method returns an undefined value.

Check for Podfile references to commit hashes in the Podfile.lock in a pull request.

Parameters:

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

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



49
50
51
52
# File 'lib/dangermattic/plugins/podfile_checker.rb', line 49

def check_podfile_diff_does_not_have_commit_references(report_type: :warning)
  warning_message = 'This PR adds a Podfile reference to a commit hash:'
  check_podfile_diff_entries_do_not_match(regexp: COMMIT_REFERENCE_REGEXP, match_found_message: warning_message, report_type: report_type)
end

#check_podfile_does_not_have_branch_references(podfile_lock_path: DEFAULT_PODFILE_LOCK_PATH, report_type: :error) ⇒ void

This method returns an undefined value.

Check if the Podfile.lock contains any references to branches and raise a failure if it does.

Examples:

Checking the default Podfile.lock:

check_podfile_does_not_have_branch_references

Checking a custom Podfile.lock at a specific path:

check_podfile_does_not_have_branch_references(podfile_lock_path: '/path/to/Podfile.lock')

Parameters:

  • podfile_lock_path (String) (defaults to: DEFAULT_PODFILE_LOCK_PATH)

    (optional) The path to the Podfile.lock file. Defaults to the DEFAULT_PODFILE_LOCK_PATH constant if not provided.

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

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



67
68
69
70
71
72
73
74
# File 'lib/dangermattic/plugins/podfile_checker.rb', line 67

def check_podfile_does_not_have_branch_references(podfile_lock_path: DEFAULT_PODFILE_LOCK_PATH, report_type: :error)
  check_podfile_does_not_match(
    regexp: BRANCH_REFERENCE_REGEXP,
    podfile_lock_path: podfile_lock_path,
    match_found_message_generator: ->(matches) { "Podfile reference(s) to a branch:\n```#{matches.join("\n")}```" },
    report_type: report_type
  )
end

#check_podfile_does_not_have_commit_references(podfile_lock_path: DEFAULT_PODFILE_LOCK_PATH, report_type: :error) ⇒ void

This method returns an undefined value.

Check if the Podfile.lock contains any references to commit hashes and raise a failure if it does.

Examples:

Checking the default Podfile.lock:

check_podfile_does_not_have_commit_references

Checking a custom Podfile.lock at a specific path:

check_podfile_does_not_have_commit_references(podfile_lock_path: '/path/to/Podfile.lock')

Parameters:

  • podfile_lock_path (String) (defaults to: DEFAULT_PODFILE_LOCK_PATH)

    (optional) The path to the Podfile.lock file. Defaults to the DEFAULT_PODFILE_LOCK_PATH constant if not provided.

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

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



35
36
37
38
39
40
41
42
# File 'lib/dangermattic/plugins/podfile_checker.rb', line 35

def check_podfile_does_not_have_commit_references(podfile_lock_path: DEFAULT_PODFILE_LOCK_PATH, report_type: :error)
  check_podfile_does_not_match(
    regexp: COMMIT_REFERENCE_REGEXP,
    podfile_lock_path: podfile_lock_path,
    match_found_message_generator: ->(matches) { "Podfile reference(s) to a commit hash:\n```#{matches.join("\n")}```" },
    report_type: report_type
  )
end