Class: Gitjira::InformationFetching
- Inherits:
-
Object
- Object
- Gitjira::InformationFetching
- Defined in:
- lib/gitjira/information_fetching.rb
Class Method Summary collapse
- .branches ⇒ Object
- .current_branch ⇒ Object
- .date_formatter(date) ⇒ Object
- .describe(issue = nil) ⇒ Object
- .extract_issue(branch_name = nil) ⇒ Object
- .extract_person(person_object) ⇒ Object
- .extract_versions(version_array) ⇒ Object
- .host ⇒ Object
- .project_key ⇒ Object
- .username ⇒ Object
Class Method Details
.branches ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/gitjira/information_fetching.rb', line 3 def self.branches project_key = self.project_key branches = `git branch -a`.split("\n") issues = Array.new issues_printed = Array.new branches.each do |current_branch| branch = current_branch[/#{project_key}-\d+/] if branch and not issues_printed.include?(branch) issues_printed << branch fetch = true end if fetch json = self.fetch_issue_json(branch) if json['fields']['progress']['percent'] puts sprintf "%-12s %3.0f%s\t%-14s - %s", json['fields']['status']['name'], json['fields']['progress']['percent'], "% done", branch, json['fields']['summary'] else puts sprintf "%-12s\t\t%-14s - %s", json['fields']['status']['name'], branch, json['fields']['summary'] end fetch = false end end if issues_printed.size == 0 STDERR.puts "[Warning] No branch found that is related to an issue. You can try `git-jira describe -i ###`" return 1 else return 0 end end |
.current_branch ⇒ Object
117 118 119 |
# File 'lib/gitjira/information_fetching.rb', line 117 def self.current_branch `git branch --no-color | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'` end |
.date_formatter(date) ⇒ Object
86 87 88 |
# File 'lib/gitjira/information_fetching.rb', line 86 def self.date_formatter(date) DateTime.parse(date).strftime("%Y-%m-%d %H:%M:%S %z") end |
.describe(issue = nil) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/gitjira/information_fetching.rb', line 41 def self.describe(issue = nil) issue = "#{self.project_key}-#{issue}" if issue and not issue.to_s.start_with?(self.project_key) issue = self.extract_issue unless issue if issue issue_info = self.fetch_issue_json(issue) if issue_info fields = issue_info['fields'] puts "=> #{fields['summary']} <=" puts "" puts "Issue Key...........: #{issue_info['key']}" puts "Type................: #{fields['issuetype']['name']}" puts "Status..............: #{fields['status'] ? fields['status']['name'] : 'None'}" if fields['progress'] and fields['progress']['percent'] puts "Progress............: #{fields['progress']['percent'].round(2)} %" end if fields['timetracking'] and fields['timetracking']['originalEstimate'] and fields['timetracking']['remainingEstimate'] puts "Estimated Work......: #{fields['timetracking']['originalEstimate']}" puts "Remaining Work......: #{fields['timetracking']['remainingEstimate']}" end puts "Resolution..........: #{fields['resolution'] ? fields['resolution']['name'] : 'None'}" puts "Priority............: #{fields['priority']['name']}" puts "Assignee............: #{self.extract_person(fields['assignee'])}" puts "Reporter............: #{self.extract_person(fields['reporter'])}" puts "Created At..........: #{self.date_formatter(fields['created'])}" puts "Updated At..........: #{self.date_formatter(fields['updated'])}" puts "Fix Version.........: #{self.extract_versions(fields['fixVersions'])}" if fields['description'] puts "" puts "#{fields['description']}" end return 0 else puts "[Error] Not able to extract issue information of '#{issue}'" return 2 end else puts "[Warning] You are currently in no issue related branch. You can try `git-jira describe -i ###`" return 1 end end |
.extract_issue(branch_name = nil) ⇒ Object
111 112 113 114 115 |
# File 'lib/gitjira/information_fetching.rb', line 111 def self.extract_issue(branch_name = nil) branch_name = self.current_branch if branch_name.nil? project_key = self.project_key branch_name[/#{project_key}-\d+/] end |
.extract_person(person_object) ⇒ Object
90 91 92 93 94 95 96 97 |
# File 'lib/gitjira/information_fetching.rb', line 90 def self.extract_person(person_object) me_email = `git config --get user.email`.chomp if me_email and person_object and me_email.eql?(person_object['emailAddress']) "Me" else "#{person_object['displayName']} <#{person_object['emailAddress']}>" end end |
.extract_versions(version_array) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/gitjira/information_fetching.rb', line 99 def self.extract_versions(version_array) if version_array and version_array.kind_of?(Array) versions = "" version_array.each do |version| versions = "#{version['name']} (#{version['releaseDate']}), #{versions}" end versions else "" end end |
.host ⇒ Object
125 126 127 |
# File 'lib/gitjira/information_fetching.rb', line 125 def self.host `git config --local --get gitjira.host`.chomp end |
.project_key ⇒ Object
121 122 123 |
# File 'lib/gitjira/information_fetching.rb', line 121 def self.project_key `git config --local --get gitjira.projectkey`.chomp end |
.username ⇒ Object
129 130 131 132 133 134 135 |
# File 'lib/gitjira/information_fetching.rb', line 129 def self.username encoded = self.credentials credentials = Base64.strict_decode64(encoded) username = credentials.split(":").first encoded = credentials = nil username end |