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
- #certificate_pinning_logic_modified? ⇒ Boolean
- #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 22 23 |
# 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 @changes_detector = GithubSpecificFilesChangesDetector.new @build_types_getter = CiToolkit::BuildTypes.new end |
Instance Method Details
#big? ⇒ Boolean
99 100 101 |
# File 'lib/ci_toolkit/github_pr.rb', line 99 def big? lines_of_code_changed > 500 end |
#build_types ⇒ Object
87 88 89 |
# File 'lib/ci_toolkit/github_pr.rb', line 87 def build_types @build_types_getter.get_build_types(@build_types, comments, labels) end |
#certificate_pinning_logic_modified? ⇒ Boolean
107 108 109 |
# File 'lib/ci_toolkit/github_pr.rb', line 107 def certificate_pinning_logic_modified? @changes_detector.certificate_pinning_logic_modified(files) end |
#comment(text) ⇒ Object
42 43 44 |
# File 'lib/ci_toolkit/github_pr.rb', line 42 def comment(text) client.add_comment(@repo_slug, @pr_number, text[0...65_500]) # github comment character limit is 65536 end |
#comments ⇒ Object
38 39 40 |
# File 'lib/ci_toolkit/github_pr.rb', line 38 def comments client.issue_comments(@repo_slug, @pr_number).map { |item| item[:body] } end |
#create_status(state, context, target_url, description) ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'lib/ci_toolkit/github_pr.rb', line 71 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
51 52 53 |
# File 'lib/ci_toolkit/github_pr.rb', line 51 def delete_comment(comment_id) client.delete_comment(@repo_slug, comment_id) end |
#delete_comments_including_text(text) ⇒ Object
46 47 48 49 |
# File 'lib/ci_toolkit/github_pr.rb', line 46 def delete_comments_including_text(text) comments = find_comments_including_text(text) comments.each { |comment| delete_comment(comment[:id]) } end |
#files ⇒ Object
67 68 69 |
# File 'lib/ci_toolkit/github_pr.rb', line 67 def files client.pull_request_files(@repo_slug, @pr_number) end |
#find_comments_including_text(text) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/ci_toolkit/github_pr.rb', line 55 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
80 81 82 83 84 85 |
# File 'lib/ci_toolkit/github_pr.rb', line 80 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
111 112 113 114 115 116 |
# File 'lib/ci_toolkit/github_pr.rb', line 111 def get_status_description(context) status = get_status(context) return if status.nil? status[:description] end |
#infrastructure_work? ⇒ Boolean
91 92 93 |
# File 'lib/ci_toolkit/github_pr.rb', line 91 def infrastructure_work? !(title =~ /\[infra\]/i).nil? || labels.include?("Infra") end |
#labels ⇒ Object
63 64 65 |
# File 'lib/ci_toolkit/github_pr.rb', line 63 def labels client.labels_for_issue(@repo_slug, @pr_number).map { |item| item[:name] } end |
#lines_of_code_changed ⇒ Object
33 34 35 36 |
# File 'lib/ci_toolkit/github_pr.rb', line 33 def lines_of_code_changed pr = client.pull_request(@repo_slug, @pr_number) pr[:additions] + pr[:deletions] end |
#number ⇒ Object
29 30 31 |
# File 'lib/ci_toolkit/github_pr.rb', line 29 def number @pr_number end |
#realm_module_modified? ⇒ Boolean
103 104 105 |
# File 'lib/ci_toolkit/github_pr.rb', line 103 def realm_module_modified? @changes_detector.realm_module_modified(files) end |
#title ⇒ Object
25 26 27 |
# File 'lib/ci_toolkit/github_pr.rb', line 25 def title client.pull_request(@repo_slug, @pr_number).[](:title) || "" end |
#work_in_progress? ⇒ Boolean
95 96 97 |
# File 'lib/ci_toolkit/github_pr.rb', line 95 def work_in_progress? title.include?("[WIP]") || labels.include?("WIP") end |