Class: CypressViewportUpdater::GithubService
- Inherits:
-
Object
- Object
- CypressViewportUpdater::GithubService
- Includes:
- SentryLogging
- Defined in:
- app/sidekiq/cypress_viewport_updater/github_service.rb
Constant Summary collapse
- REPO =
'department-of-veterans-affairs/vets-website'
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#feature_branch_name ⇒ Object
readonly
Returns the value of attribute feature_branch_name.
Instance Method Summary collapse
- #create_branch ⇒ Object
- #get_content(file:) ⇒ Object
-
#initialize ⇒ GithubService
constructor
A new instance of GithubService.
- #submit_pr ⇒ Object
- #update_content(file:) ⇒ Object
Methods included from SentryLogging
#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger
Constructor Details
#initialize ⇒ GithubService
Returns a new instance of GithubService.
11 12 13 14 15 16 17 18 19 |
# File 'app/sidekiq/cypress_viewport_updater/github_service.rb', line 11 def initialize @private_key = OpenSSL::PKey::RSA.new(Settings.github_cvu.private_pem&.gsub('\n', "\n")) @installation_id = Settings.github_cvu.installation_id @integration_id = Settings.github_cvu.integration_id @client = Octokit::Client.new(bearer_token: new_jwt_token) response = @client.create_installation_access_token(@installation_id, accept: 'application/vnd.github.v3+json') @client.bearer_token = response.to_h[:token] end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
9 10 11 |
# File 'app/sidekiq/cypress_viewport_updater/github_service.rb', line 9 def client @client end |
#feature_branch_name ⇒ Object
Returns the value of attribute feature_branch_name.
9 10 11 |
# File 'app/sidekiq/cypress_viewport_updater/github_service.rb', line 9 def feature_branch_name @feature_branch_name end |
Instance Method Details
#create_branch ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/sidekiq/cypress_viewport_updater/github_service.rb', line 34 def create_branch set_feature_branch_name ref = "heads/#{feature_branch_name}" begin sha = @client.ref(REPO, 'heads/main').object.sha @client.create_ref(REPO, ref, sha) rescue Octokit::ClientError, Octokit::UnprocessableEntity => e # :nocov: log_exception_to_sentry(e) # :nocov: end end |
#get_content(file:) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/sidekiq/cypress_viewport_updater/github_service.rb', line 21 def get_content(file:) begin file.sha = @client.content(REPO, path: file.github_path).sha file.raw_content = @client.content(REPO, path: file.github_path, accept: 'application/vnd.github.V3.raw') rescue Octokit::ClientError, Octokit::UnprocessableEntity => e # :nocov: log_exception_to_sentry(e) # :nocov: end self end |
#submit_pr ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/sidekiq/cypress_viewport_updater/github_service.rb', line 61 def submit_pr @client.create_pull_request(REPO, 'main', feature_branch_name, pr_title, pr_body) rescue Octokit::ClientError, Octokit::UnprocessableEntity => e # :nocov: log_exception_to_sentry(e) # :nocov: end |
#update_content(file:) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/sidekiq/cypress_viewport_updater/github_service.rb', line 48 def update_content(file:) @client.update_content(REPO, file.github_path, "update #{file.name}", file.sha, file.updated_content, branch: feature_branch_name) rescue Octokit::ClientError, Octokit::UnprocessableEntity => e # :nocov: log_exception_to_sentry(e) # :nocov: end |