Class: GithubGateway
- Inherits:
-
Object
- Object
- GithubGateway
- Defined in:
- lib/jirametrics/github_gateway.rb
Instance Attribute Summary collapse
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
Instance Method Summary collapse
- #build_pr_data(raw_pr) ⇒ Object
- #extract_issue_keys(raw_pr) ⇒ Object
- #extract_reviews(raw_reviews) ⇒ Object
- #fetch_pull_requests(since: nil) ⇒ Object
-
#initialize(repo:, project_keys:, file_system:) ⇒ GithubGateway
constructor
A new instance of GithubGateway.
Constructor Details
#initialize(repo:, project_keys:, file_system:) ⇒ GithubGateway
Returns a new instance of GithubGateway.
9 10 11 12 13 14 |
# File 'lib/jirametrics/github_gateway.rb', line 9 def initialize repo:, project_keys:, file_system: @repo = repo @project_keys = project_keys @file_system = file_system @issue_key_pattern = build_issue_key_pattern end |
Instance Attribute Details
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
7 8 9 |
# File 'lib/jirametrics/github_gateway.rb', line 7 def repo @repo end |
Instance Method Details
#build_pr_data(raw_pr) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/jirametrics/github_gateway.rb', line 30 def build_pr_data raw_pr issue_keys = extract_issue_keys(raw_pr) return nil if issue_keys.empty? { 'number' => raw_pr['number'], 'repo' => @repo, 'url' => raw_pr['url'], 'title' => raw_pr['title'], 'branch' => raw_pr['headRefName'], 'opened_at' => raw_pr['createdAt'], 'closed_at' => raw_pr['closedAt'], 'merged_at' => raw_pr['mergedAt'], 'state' => raw_pr['state'], 'issue_keys' => issue_keys, 'reviews' => extract_reviews(raw_pr['reviews'] || []) } end |
#extract_issue_keys(raw_pr) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/jirametrics/github_gateway.rb', line 49 def extract_issue_keys raw_pr return [] if @issue_key_pattern.nil? sources = [ raw_pr['headRefName'], raw_pr['title'], raw_pr['body'] ] sources.compact .flat_map { |s| s.scan(@issue_key_pattern) } .uniq end |
#extract_reviews(raw_reviews) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/jirametrics/github_gateway.rb', line 63 def extract_reviews raw_reviews raw_reviews .select { |r| %w[APPROVED CHANGES_REQUESTED].include?(r['state']) } .map do |r| { 'author' => r.dig('author', 'login'), 'submitted_at' => r['submittedAt'], 'state' => r['state'] } end end |
#fetch_pull_requests(since: nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/jirametrics/github_gateway.rb', line 16 def fetch_pull_requests since: nil # Note: 'commits' is intentionally excluded — including it triggers GitHub's GraphQL node # limit (authors sub-connection × PRs × commits exceeds 500,000 nodes). Branch name, # title, and body are sufficient for issue key extraction in the vast majority of cases. args = %w[pr list --state all --limit 5000 --json number,title,body,headRefName,createdAt,closedAt,mergedAt,url,state,reviews] args += ['--repo', @repo] args += ['--search', "updated:>=#{since}"] if since @file_system.log " Downloading pull requests from #{@repo}", also_write_to_stderr: true raw_prs = run_command(args) raw_prs.filter_map { |pr| build_pr_data(pr) } end |