Class: ChangelogUtils

Inherits:
Object
  • Object
show all
Defined in:
lib/pr_changelog_utils.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#branch_nameObject

Returns the value of attribute branch_name.



5
6
7
# File 'lib/pr_changelog_utils.rb', line 5

def branch_name
  @branch_name
end

#state_changedObject

Returns the value of attribute state_changed.



6
7
8
# File 'lib/pr_changelog_utils.rb', line 6

def state_changed
  @state_changed
end

Class Method Details

.currentBranchNameObject



66
67
68
69
# File 'lib/pr_changelog_utils.rb', line 66

def self.currentBranchName
  branch = `git branch --no-color 2> /dev/null`.strip.scan(/\*\s(.*)/)
  return branch[0][0] if branch.size()>0 and branch[0].size()>0
end

.getLastMessageFromGitObject



54
55
56
# File 'lib/pr_changelog_utils.rb', line 54

def self.getLastMessageFromGit
  `git log -1 --format="%b"`
end

.getProjectNameObject



8
9
10
11
12
13
14
15
# File 'lib/pr_changelog_utils.rb', line 8

def self.getProjectName
  projectFiles = Dir["*.xcodeproj"]
  if (projectFiles.size()>0)
    return projectFiles[0].scan(/[^.]*/)[0]
  else 
    return nil
  end
end

.getPullRequestHashObject



62
63
64
# File 'lib/pr_changelog_utils.rb', line 62

def self.getPullRequestHash
  `git log -1 --format="%s" | cut -f 4 -d ' '`
end

.goBackObject



45
46
47
48
# File 'lib/pr_changelog_utils.rb', line 45

def self.goBack
  @branch_name = self.currentBranchName if !@branch_name
  `git checkout HEAD^ >/dev/null 2>/dev/null`
end

.goForwardObject



50
51
52
# File 'lib/pr_changelog_utils.rb', line 50

def self.goForward
  `git checkout #{@branch_name} >/dev/null 2>/dev/null`
end

.isPullRequestMergeObject



58
59
60
# File 'lib/pr_changelog_utils.rb', line 58

def self.isPullRequestMerge
  `git log -1 --format="%s" | cut -c -18`.strip == "Merge pull request"
end

.isXcodeDirectoryObject



71
72
73
74
75
76
77
# File 'lib/pr_changelog_utils.rb', line 71

def self.isXcodeDirectory  
  projectName = ChangelogUtils.getProjectName
  if projectName == nil
    puts "changelog should be used in a xcode directory" 
    exit
  end
end

.plistFileObject



18
19
20
21
22
23
24
25
26
# File 'lib/pr_changelog_utils.rb', line 18

def self.plistFile
  projectName = ChangelogUtils.getProjectName
   plistFile = Dir["#{Dir.pwd}/*/#{projectName}-Info.plist"]
    if (plistFile.size() > 0)
       return plistFile[0]
    else 
       return nil
    end
end

.printCurrentChange(options) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/pr_changelog_utils.rb', line 32

def self.printCurrentChange (options)
  if (options.char)
    if (options.char != ChangelogUtils.getLastMessageFromGit.strip[0])
      return 
    end
  end
  if (!options.nobullet)
    " * #{ChangelogUtils.getLastMessageFromGit.strip} (#{ChangelogUtils.getPullRequestHash.strip})"
  else
    "#{ChangelogUtils.getLastMessageFromGit.strip} (#{ChangelogUtils.getPullRequestHash.strip})"
  end
end

.restoreStateObject



104
105
106
107
108
# File 'lib/pr_changelog_utils.rb', line 104

def self.restoreState
  if @state_changed
    `git stash pop` 
  end
end

.saveStateObject



98
99
100
101
102
# File 'lib/pr_changelog_utils.rb', line 98

def self.saveState 
  if @state_changed
    `git stash` 
  end
end

.showVersionObject



28
29
30
# File 'lib/pr_changelog_utils.rb', line 28

def self.showVersion
  `/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" #{ChangelogUtils.plistFile}`.strip
end

.validateCurrentDirectoryObject



92
93
94
95
96
# File 'lib/pr_changelog_utils.rb', line 92

def self.validateCurrentDirectory
  ChangelogUtils.validateGitExists
  ChangelogUtils.validateNoChangeInCurrentWorkspace
  ChangelogUtils.isXcodeDirectory
end

.validateGitExistsObject



85
86
87
88
89
90
# File 'lib/pr_changelog_utils.rb', line 85

def self.validateGitExists
  if Dir[".git"].first == nil
    puts "no git project found. changelog should be used in a git project."
    exit
  end
end

.validateNoChangeInCurrentWorkspaceObject



79
80
81
82
83
# File 'lib/pr_changelog_utils.rb', line 79

def self.validateNoChangeInCurrentWorkspace
  if `git status -s`.strip != ""
    @state_changed = true
  end
end