class ChangelogUtils

Attributes

branch_name[RW]
state_changed[RW]

Public Class Methods

currentBranchName() click to toggle source
# 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
getLastMessageFromGit() click to toggle source
# File lib/pr_changelog_utils.rb, line 54
def self.getLastMessageFromGit
        `git log -1 --format="%b"`
end
getProjectName() click to toggle source
# 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
getPullRequestHash() click to toggle source
# File lib/pr_changelog_utils.rb, line 62
def self.getPullRequestHash
        `git log -1 --format="%s" | cut -f 4 -d ' '`
end
goBack() click to toggle source
# 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
goForward() click to toggle source
# File lib/pr_changelog_utils.rb, line 50
def self.goForward
        `git checkout #{@branch_name} >/dev/null 2>/dev/null`
end
isPullRequestMerge() click to toggle source
# File lib/pr_changelog_utils.rb, line 58
def self.isPullRequestMerge
        `git log -1 --format="%s" | cut -c -18`.strip == "Merge pull request"
end
isXcodeDirectory() click to toggle source
# 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
plistFile() click to toggle source
# 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) click to toggle source
# 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
restoreState() click to toggle source
# File lib/pr_changelog_utils.rb, line 104
def self.restoreState
        if @state_changed
                `git stash pop` 
        end
end
saveState() click to toggle source
# File lib/pr_changelog_utils.rb, line 98
def self.saveState 
        if @state_changed
                `git stash` 
        end
end
showVersion() click to toggle source
# File lib/pr_changelog_utils.rb, line 28
def self.showVersion
        `/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" #{ChangelogUtils.plistFile}`.strip
end
validateCurrentDirectory() click to toggle source
# File lib/pr_changelog_utils.rb, line 92
def self.validateCurrentDirectory
        ChangelogUtils.validateGitExists
        ChangelogUtils.validateNoChangeInCurrentWorkspace
        ChangelogUtils.isXcodeDirectory
end
validateGitExists() click to toggle source
# 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
validateNoChangeInCurrentWorkspace() click to toggle source
# File lib/pr_changelog_utils.rb, line 79
def self.validateNoChangeInCurrentWorkspace
        if `git status -s`.strip != ""
                @state_changed = true
        end
end