Class: Danger::DangerIosVersionChange

Inherits:
Plugin
  • Object
show all
Defined in:
lib/ios_version_change/plugin.rb

Overview

Asserts the version string has been changed in your iOS XCode project. This is done by checking the git diff of your project’s Info.plist file. The plugin will either call Danger’s fail method or do nothing if the version string was changed.

ios_version_change.assert_version_changed("ProjectName/Info.plist")

Examples:

Assert the version string changed for your iOS project

# Calls Danger `fail` if the version string not updated or nothing if it has changed.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dangerfile) ⇒ DangerIosVersionChange

Returns a new instance of DangerIosVersionChange.



20
21
22
# File 'lib/ios_version_change/plugin.rb', line 20

def initialize(dangerfile)
  super(dangerfile)
end

Class Method Details

.instance_nameString

The instance name used in the Dangerfile

Returns:

  • (String)


16
17
18
# File 'lib/ios_version_change/plugin.rb', line 16

def self.instance_name
  "ios_version_change"
end

Instance Method Details

#assert_version_changed(info_plist_file_path) ⇒ void

This method returns an undefined value.

Asserts the version string has been changed in your iOS XCode project.

ios_version_change.assert_version_changed("ProjectName/Info.plist")

Examples:

Assert the version string changed for your iOS project

# Calls Danger `fail` if the version string not updated or nothing if it has changed.

Parameters:

  • info_plist_file_path (String)

    Path to Info.plist file for XCode project.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/ios_version_change/plugin.rb', line 48

def assert_version_changed(info_plist_file_path)
  unless File.file?(info_plist_file_path)
    fail "Info.plist at path " + info_plist_file_path + " does not exist."
    return # rubocop:disable UnreachableCode
  end

  unless git.diff_for_file(info_plist_file_path) # No diff found for Info.plist file.
    fail "You did not edit your Info.plist file at all. Therefore, you did not change the iOS version."
    return # rubocop:disable UnreachableCode
  end

  git_diff_string = git.diff_for_file(info_plist_file_path).patch
  assert_version_changed_diff(git_diff_string)
end

#assert_version_changed_diff(git_diff_string) ⇒ void

This method returns an undefined value.

Ignore. Pass the git diff string here to see if the version string has been updated. Use ‘ios_version_change.assert_version_changed(“ProjectName/Info.plist”)` instead as it’s more convenient sending the path to the Info.plist file.



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ios_version_change/plugin.rb', line 26

def assert_version_changed_diff(git_diff_string)
  git_diff_lines = git_diff_string.lines
  git_diff_string.each_line.each_with_index do |line, index|
    next unless line.include? "<key>CFBundleShortVersionString</key>"
    # we need to check the next 2 lines of the string to determine if it's a git diff change.
    if git_diff_lines.length >= (index + 3) && git_diff_lines[index + 1][0] == "-" && git_diff_lines[index + 2][0] == "+"
      return # rubocop:disable NonLocalExitFromIterator
    end
  end

  fail "You did not change the iOS version."
end