Class: CiToolkit::GithubPr
Overview
Can be used to retrieve information about a PR on Github via the Github API
Instance Method Summary collapse
- #big? ⇒ Boolean
- #build_types ⇒ Object
- #comment(text) ⇒ Object
- #comments ⇒ Object
- #create_status(state, context, target_url, description) ⇒ Object
- #delete_comment(comment_id) ⇒ Object
- #delete_comments_including_text(text) ⇒ Object
- #files ⇒ Object
- #find_comments_including_text(text) ⇒ Object
- #get_status(context) ⇒ Object
- #get_status_description(context) ⇒ Object
- #infrastructure_work? ⇒ Boolean
-
#initialize(env = CiToolkit::BitriseEnv.new, build_types = ENV["BUILD_TYPES"]&.split(/,/) || ["BluetoothDemo", "Acceptance PreProd", "Acceptance Prod", "Latest Prod", "Latest PreProd", "Mock", "Design System"], client = Octokit::Client.new) ⇒ GithubPr
constructor
A new instance of GithubPr.
- #labels ⇒ Object
- #lines_of_code_changed ⇒ Object
- #number ⇒ Object
- #realm_module_modified? ⇒ Boolean
- #title ⇒ Object
- #work_in_progress? ⇒ Boolean
Methods included from AbstractInterface
Constructor Details
#initialize(env = CiToolkit::BitriseEnv.new, build_types = ENV["BUILD_TYPES"]&.split(/,/) || ["BluetoothDemo", "Acceptance PreProd", "Acceptance Prod", "Latest Prod", "Latest PreProd", "Mock", "Design System"], client = Octokit::Client.new) ⇒ GithubPr
Returns a new instance of GithubPr.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/ci_toolkit/github_pr.rb', line 8 def initialize( env = CiToolkit::BitriseEnv.new, build_types = ENV["BUILD_TYPES"]&.split(/,/) || ["BluetoothDemo", "Acceptance PreProd", "Acceptance Prod", "Latest Prod", "Latest PreProd", "Mock", "Design System"], client = Octokit::Client.new ) super() @pr_number = env.pull_request_number @repo_slug = env.repository_path @commit_sha = env.git_commit @_client = client @build_types = build_types @bot = CiToolkit::GithubBot.new end |
Instance Method Details
#big? ⇒ Boolean
104 105 106 |
# File 'lib/ci_toolkit/github_pr.rb', line 104 def big? lines_of_code_changed > 500 end |
#build_types ⇒ Object
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/ci_toolkit/github_pr.rb', line 85 def build_types types = [] @build_types.each do |type| if comments.include?("#{type} build") || labels.include?("#{type} build") || comments.include?(type) || labels.include?(type) types.push(type) end end types end |
#comment(text) ⇒ Object
40 41 42 |
# File 'lib/ci_toolkit/github_pr.rb', line 40 def comment(text) client.add_comment(@repo_slug, @pr_number, text[0...65_500]) # github comment character limit is 65536 end |
#comments ⇒ Object
36 37 38 |
# File 'lib/ci_toolkit/github_pr.rb', line 36 def comments client.issue_comments(@repo_slug, @pr_number).map { |item| item[:body] } end |
#create_status(state, context, target_url, description) ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/ci_toolkit/github_pr.rb', line 69 def create_status(state, context, target_url, description) client.create_status( @repo_slug, @commit_sha, state, { context:, target_url:, description: } ) end |
#delete_comment(comment_id) ⇒ Object
49 50 51 |
# File 'lib/ci_toolkit/github_pr.rb', line 49 def delete_comment(comment_id) client.delete_comment(@repo_slug, comment_id) end |
#delete_comments_including_text(text) ⇒ Object
44 45 46 47 |
# File 'lib/ci_toolkit/github_pr.rb', line 44 def delete_comments_including_text(text) comments = find_comments_including_text(text) comments.each { |comment| delete_comment(comment[:id]) } end |
#files ⇒ Object
65 66 67 |
# File 'lib/ci_toolkit/github_pr.rb', line 65 def files client.pull_request_files(@repo_slug, @pr_number) end |
#find_comments_including_text(text) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/ci_toolkit/github_pr.rb', line 53 def find_comments_including_text(text) comments = [] client.issue_comments(@repo_slug, @pr_number).map do |item| comments << item if item[:body]&.include? text end comments end |
#get_status(context) ⇒ Object
78 79 80 81 82 83 |
# File 'lib/ci_toolkit/github_pr.rb', line 78 def get_status(context) client.statuses(@repo_slug, @commit_sha).each do |status| return status if status[:context] == context end nil end |
#get_status_description(context) ⇒ Object
113 114 115 116 117 118 |
# File 'lib/ci_toolkit/github_pr.rb', line 113 def get_status_description(context) status = get_status(context) return if status.nil? status[:description] end |
#infrastructure_work? ⇒ Boolean
96 97 98 |
# File 'lib/ci_toolkit/github_pr.rb', line 96 def infrastructure_work? !(title =~ /\[infra\]/i).nil? || labels.include?("Infra") end |
#labels ⇒ Object
61 62 63 |
# File 'lib/ci_toolkit/github_pr.rb', line 61 def labels client.labels_for_issue(@repo_slug, @pr_number).map { |item| item[:name] } end |
#lines_of_code_changed ⇒ Object
31 32 33 34 |
# File 'lib/ci_toolkit/github_pr.rb', line 31 def lines_of_code_changed pr = client.pull_request(@repo_slug, @pr_number) pr[:additions] + pr[:deletions] end |
#number ⇒ Object
27 28 29 |
# File 'lib/ci_toolkit/github_pr.rb', line 27 def number @pr_number end |
#realm_module_modified? ⇒ Boolean
108 109 110 111 |
# File 'lib/ci_toolkit/github_pr.rb', line 108 def realm_module_modified? modified_files = files.select { |file| file[:filename]&.start_with? "cache/" } modified_files.length.positive? end |
#title ⇒ Object
23 24 25 |
# File 'lib/ci_toolkit/github_pr.rb', line 23 def title client.pull_request(@repo_slug, @pr_number).[](:title) || "" end |
#work_in_progress? ⇒ Boolean
100 101 102 |
# File 'lib/ci_toolkit/github_pr.rb', line 100 def work_in_progress? title.include?("[WIP]") || labels.include?("WIP") end |