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.



21
22
23
24
25
26
# File 'lib/ios_version_change/plugin.rb', line 21

def initialize(dangerfile)
  super(dangerfile)
  raise unless dangerfile.env.scm.class == Danger::GitRepo

  @git = dangerfile.env.scm
end

Class Method Details

.instance_nameString

The instance name used in the Dangerfile

Returns:

  • (String)


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

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.



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

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

  git_diff_string = @git.diff[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.



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ios_version_change/plugin.rb', line 30

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