Class: ChangelogUtils
- Inherits:
-
Object
- Object
- ChangelogUtils
- Defined in:
- lib/pr_changelog_utils.rb
Instance Attribute Summary collapse
-
#branch_name ⇒ Object
Returns the value of attribute branch_name.
-
#state_changed ⇒ Object
Returns the value of attribute state_changed.
Class Method Summary collapse
- .currentBranchName ⇒ Object
- .getLastMessageFromGit ⇒ Object
- .getProjectName ⇒ Object
- .getPullRequestHash ⇒ Object
- .goBack ⇒ Object
- .goForward ⇒ Object
- .isPullRequestMerge ⇒ Object
- .isXcodeDirectory ⇒ Object
- .plistFile ⇒ Object
- .printCurrentChange(options) ⇒ Object
- .restoreState ⇒ Object
- .saveState ⇒ Object
- .showVersion ⇒ Object
- .validateCurrentDirectory ⇒ Object
- .validateGitExists ⇒ Object
- .validateNoChangeInCurrentWorkspace ⇒ Object
Instance Attribute Details
#branch_name ⇒ Object
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_changed ⇒ Object
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
.currentBranchName ⇒ Object
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 |
.getLastMessageFromGit ⇒ Object
54 55 56 |
# File 'lib/pr_changelog_utils.rb', line 54 def self.getLastMessageFromGit `git log -1 --format="%b"` end |
.getProjectName ⇒ Object
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 |
.getPullRequestHash ⇒ Object
62 63 64 |
# File 'lib/pr_changelog_utils.rb', line 62 def self.getPullRequestHash `git log -1 --format="%s" | cut -f 4 -d ' '` end |
.goBack ⇒ Object
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 |
.goForward ⇒ Object
50 51 52 |
# File 'lib/pr_changelog_utils.rb', line 50 def self.goForward `git checkout #{@branch_name} >/dev/null 2>/dev/null` end |
.isPullRequestMerge ⇒ Object
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 |
.isXcodeDirectory ⇒ Object
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 |
.plistFile ⇒ Object
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 () if (.char) if (.char != ChangelogUtils.getLastMessageFromGit.strip[0]) return end end if (!.nobullet) " * #{ChangelogUtils.getLastMessageFromGit.strip} (#{ChangelogUtils.getPullRequestHash.strip})" else "#{ChangelogUtils.getLastMessageFromGit.strip} (#{ChangelogUtils.getPullRequestHash.strip})" end end |
.restoreState ⇒ Object
104 105 106 107 108 |
# File 'lib/pr_changelog_utils.rb', line 104 def self.restoreState if @state_changed `git stash pop` end end |
.saveState ⇒ Object
98 99 100 101 102 |
# File 'lib/pr_changelog_utils.rb', line 98 def self.saveState if @state_changed `git stash` end end |
.showVersion ⇒ Object
28 29 30 |
# File 'lib/pr_changelog_utils.rb', line 28 def self.showVersion `/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" #{ChangelogUtils.plistFile}`.strip end |
.validateCurrentDirectory ⇒ Object
92 93 94 95 96 |
# File 'lib/pr_changelog_utils.rb', line 92 def self.validateCurrentDirectory ChangelogUtils.validateGitExists ChangelogUtils.validateNoChangeInCurrentWorkspace ChangelogUtils.isXcodeDirectory end |
.validateGitExists ⇒ Object
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 |
.validateNoChangeInCurrentWorkspace ⇒ Object
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 |