Class: SashimiTanpopo::Provider::GitHub
- Defined in:
- lib/sashimi_tanpopo/provider/github.rb
Overview
Apply recipe files and create Pull Request
Constant Summary collapse
- DEFAULT_API_ENDPOINT =
"https://api.github.com/"- DEFAULT_GITHUB_HOST =
"github.com"
Class Method Summary collapse
- .generate_summary(changed_files:, dry_run:) ⇒ String
-
.github_host(api_endpoint) ⇒ String
Get GitHub host from api_endpoint.
Instance Method Summary collapse
-
#initialize(recipe_paths:, target_dir:, params:, dry_run:, is_colored:, git_username:, git_email:, commit_message:, repository:, access_token:, api_endpoint: DEFAULT_API_ENDPOINT, pr_title:, pr_body:, pr_source_branch:, pr_target_branch:, pr_assignees: [], pr_reviewers: [], pr_labels: [], is_draft_pr:, summary_path:) ⇒ GitHub
constructor
A new instance of GitHub.
-
#perform ⇒ String?
Apply recipe files.
Methods inherited from Base
Constructor Details
#initialize(recipe_paths:, target_dir:, params:, dry_run:, is_colored:, git_username:, git_email:, commit_message:, repository:, access_token:, api_endpoint: DEFAULT_API_ENDPOINT, pr_title:, pr_body:, pr_source_branch:, pr_target_branch:, pr_assignees: [], pr_reviewers: [], pr_labels: [], is_draft_pr:, summary_path:) ⇒ GitHub
Returns a new instance of GitHub.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/sashimi_tanpopo/provider/github.rb', line 31 def initialize(recipe_paths:, target_dir:, params:, dry_run:, is_colored:, git_username:, git_email:, commit_message:, repository:, access_token:, api_endpoint: DEFAULT_API_ENDPOINT, pr_title:, pr_body:, pr_source_branch:, pr_target_branch:, pr_assignees: [], pr_reviewers: [], pr_labels: [], is_draft_pr:, summary_path:) super( recipe_paths: recipe_paths, target_dir: target_dir, params: params, dry_run: dry_run, is_colored: is_colored, is_update_local: false, ) @commit_message = @repository = repository @pr_title = pr_title @pr_body = pr_body @pr_source_branch = pr_source_branch @pr_target_branch = pr_target_branch @pr_assignees = pr_assignees @pr_reviewers = pr_reviewers @pr_labels = pr_labels @is_draft_pr = is_draft_pr @git_username = git_username @git_email = git_email @api_endpoint = api_endpoint @summary_path = summary_path || "" @client = Octokit::Client.new(api_endpoint: api_endpoint, access_token: access_token) end |
Class Method Details
.generate_summary(changed_files:, dry_run:) ⇒ String
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/sashimi_tanpopo/provider/github.rb', line 109 def self.generate_summary(changed_files:, dry_run:) header = +"## :page_facing_up: sashimi_tanpopo report" header << " (dry run)" if dry_run lines = [header] if changed_files.empty? lines.push( "no changes", "", ) else changed_files.each do |path, data| lines.push( "### :memo: #{path}", "```diff", SashimiTanpopo::DiffHelper.generate_diff(data[:before_content], data[:after_content], is_colored: false).rstrip, "```", "", ) end end lines.join("\n") end |
.github_host(api_endpoint) ⇒ String
Get GitHub host from api_endpoint
96 97 98 99 100 101 102 103 |
# File 'lib/sashimi_tanpopo/provider/github.rb', line 96 def self.github_host(api_endpoint) return DEFAULT_GITHUB_HOST if api_endpoint == DEFAULT_API_ENDPOINT matched = %r{^https?://(.+)/api}.match(api_endpoint) return matched[1] if matched # steep:ignore DEFAULT_GITHUB_HOST end |
Instance Method Details
#perform ⇒ String?
Apply recipe files
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/sashimi_tanpopo/provider/github.rb', line 68 def perform changed_files = apply_recipe_files write_summary_file(changed_files) return nil if changed_files.empty? || @dry_run if exists_branch?(@pr_source_branch) SashimiTanpopo.logger.info "Skipped because branch #{@pr_source_branch} already exists on #{@repository}" return nil end create_branch_and_push_changes(changed_files) pr = create_pull_request add_pr_labels(pr[:number]) add_pr_assignees(pr[:number]) add_pr_reviewers(pr[:number]) pr[:html_url] end |