Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add service for fetching Github PR data #10

Merged
merged 9 commits into from
Aug 26, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add pull request model
Vadser committed Aug 22, 2024
commit 4abaa2785e58fef652d926d0407369238ab11669
2 changes: 2 additions & 0 deletions app/models/pull_request.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class PullRequest < ApplicationRecord
end
6 changes: 3 additions & 3 deletions app/services/fetch_github_pull_request_data_service.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class FetchGithubPullRequestDataService
attr_reader :pull_request_url, :client
GITHUB_BASE_URL = 'https://api.github.com'

Check failure on line 3 in app/services/fetch_github_pull_request_data_service.rb

GitHub Actions / lint

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

def initialize(pull_request_url)
@pull_request_url = pull_request_url
@@ -17,7 +17,7 @@
commits_data = fetch_commits_data(pr_data[:commits_url])
comments_data = fetch_comments_data(pr_data[:review_comments_url])

assemble_pull_request_data(pr_data, diff_data, commits_data, comments_data)
PullRequest.create(assemble_pull_request_data(pr_data, diff_data, commits_data, comments_data))
end

private
@@ -26,7 +26,7 @@
pattern = %r{\Ahttps://github\.com/(?<owner>[^/]+)/(?<repo>[^/]+)/pull/(?<pr_number>\d+)\z}

match_data = pull_request_url.match(pattern)
raise ArgumentError, 'Invalid GitHub pull request URL' unless match_data

Check failure on line 29 in app/services/fetch_github_pull_request_data_service.rb

GitHub Actions / lint

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

{
owner: match_data[:owner],
@@ -44,7 +44,7 @@

def fetch_diff_data(diff_url)
response = client.send_get_request(diff_url)
response.code == 200 ? response.body : ''

Check failure on line 47 in app/services/fetch_github_pull_request_data_service.rb

GitHub Actions / lint

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
end

def fetch_commits_data(commits_url)
@@ -53,7 +53,7 @@

JSON.parse(response.body).map do |commit|
{
sha: commit['sha'],

Check failure on line 56 in app/services/fetch_github_pull_request_data_service.rb

GitHub Actions / lint

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
author: commit['commit']['author'].slice('name', 'email'),
message: commit['commit']['message'],
date: commit['commit']['author']['date']
@@ -90,8 +90,8 @@
comments: comments_data,
commits: commits_data,
diff: diff_data,
created_at: pr_data[:created_at],
updated_at: pr_data[:updated_at]
pr_created_at: pr_data[:created_at],
pr_updated_at: pr_data[:updated_at]
}
end
end
2 changes: 1 addition & 1 deletion config/credentials.yml.enc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/DHwqsNHUbO+v/Gw7Nhq+j3ufU3ffcc6zHsxIy0rO6qROENCFQG/mEU/GUNNhx44KbZEdNBpVKXeirbv6Tg8pYT5pO6zpYhQYhWbG+hl30a4cF0UDzZU8v0dLOnerhQxAXX4pPa04avG1VSyzsoboC66h/y+6DSbt7zrGbCaH38/Zse6MunjFpEKC39tXRBGcCiFYSPM/3xEoZau+iPefsybq4yPR+Kq6HkerfuweJwYFAULShGGNNnr8ZVqJbb2D8IvmVAvQS2OmdSVATfsei5FCPEt/YAioqsh2ybcqIK8E/5z7SvoeUQCwAPhyUg0BBFj7VQGSxAwkt+8wKLQ0uOQNFYC54hOS9DBp0EZL3d0jY+Oz138PqvYoleNVgEdWdoTP7jDEYhr0Z7gogfbYIMgA4w+qxxqkZTtFaVN/cjJCD4hsICxAp1GcIqD2hE6jh6hD/OEtnSINdIWNt3YVqu3c6Rdh4kQj3n9Pp+LE5Q4vRJMGnZIFkVU/2tBzYZN/RPpDXVdX6rP4+w4bkBtPoD5njyTQptRvPwHrKiS06d6mmAXxd1a--aqV86+5maj3bza49--KX5CzjSSYPMrf5beOY9I7w==
zdXnhs4q2NxhuciKxZn6KEpUK2v+kwlphY5XyUWqQas7aycFLA+e4B4WDqWprW9NA1ZiYPURuglIplIVAQjHUFh7+xHbsUcWTVr5DEp+guj04hIHzNNmnuaWE1ha7qVcqAz3oejhwXR/COyAWqUDyh/XCkINuOQTdp5oV6htZ5n7fjrq8ctFy8iJ6L9AXDq5Ka+ZasVTmll5/l899vGly7ecoXaE3Ra0l+R20F2kEaom6XwRxehgtDN+WUMzqYazsCUhwyEefTKtzzVJSfmbwnSWgMk+mfgcyGZQ1LHKrOeYafa9W3JSYO4bmQR/O0z06J2OSm21OAdw7hkByS3T+jDb8wVotSFRtSq2HDBTSbr3y21tV569K9deg3pp253aPbS/Nk27o9w0E9d0X6vCNXl6e7jofvVln7XWKwrK1xUnG0TWxleHR1Fogni9V+PI2HrDr0q1QtuvSeqpI/VTwx5dmH/BAHqq6See8zVLP4/14O5d7qfQzlS19C420By8vXtNcplzzloTGMiKbCzbsn3dzQsgnijUWWoNdd9L0ksrgEMn0EK5--4CPKoh4crqcTEyUh--ajYgrnaCjCB8rTT6qGBXTw==
19 changes: 19 additions & 0 deletions db/migrate/20240822102014_create_pull_requests.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class CreatePullRequests < ActiveRecord::Migration[7.2]
def change
create_table :pull_requests do |t|
t.string :url
t.string :title
t.text :body
t.string :repo_owner
t.string :repo
t.string :creator
t.json :comments
t.json :commits
t.text :diff
t.datetime :pr_created_at
t.datetime :pr_updated_at

t.timestamps
end
end
end
29 changes: 29 additions & 0 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.


Unchanged files with check annotations Beta

class Github::Client
BASE_URL = 'https://api.github.com'

Check failure on line 2 in app/lib/github/client.rb

GitHub Actions / lint

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
def send_get_request(url)
RestClient.get(url, headers)
def headers
@_headers ||= {
'X-GitHub-Api-Version' => '2022-11-28',

Check failure on line 28 in app/lib/github/client.rb

GitHub Actions / lint

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

Check failure on line 28 in app/lib/github/client.rb

GitHub Actions / lint

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
'Authorization' => "Bearer #{Rails.application.credentials.github.api_token}",

Check failure on line 29 in app/lib/github/client.rb

GitHub Actions / lint

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
'Accept' => 'application/vnd.github+json'

Check failure on line 30 in app/lib/github/client.rb

GitHub Actions / lint

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

Check failure on line 30 in app/lib/github/client.rb

GitHub Actions / lint

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
}
end
end