Class: CiToolkit::GitlabPr
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", "Acceptance Prod DEBUG"], bot = CiToolkit::GitlabBot.new) ⇒ GitlabPr
constructor
A new instance of GitlabPr.
- #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", "Acceptance Prod DEBUG"], bot = CiToolkit::GitlabBot.new) ⇒ GitlabPr
Returns a new instance of GitlabPr.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ci_toolkit/gitlab_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", "Acceptance Prod DEBUG"], bot = CiToolkit::GitlabBot.new ) super() @pr_number = env.pull_request_number @repo_slug = env.repository_path @commit_sha = env.git_commit @_client = bot.client @build_types = build_types @bot = bot end |
Instance Method Details
#big? ⇒ Boolean
107 108 109 |
# File 'lib/ci_toolkit/gitlab_pr.rb', line 107 def big? lines_of_code_changed.to_i > 500 end |
#build_types ⇒ Object
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/ci_toolkit/gitlab_pr.rb', line 88 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
42 43 44 45 |
# File 'lib/ci_toolkit/gitlab_pr.rb', line 42 def comment(text) # github comment character limit is 65536 client.create_merge_request_note(@repo_slug, @pr_number, text[0...65_500]) end |
#comments ⇒ Object
38 39 40 |
# File 'lib/ci_toolkit/gitlab_pr.rb', line 38 def comments client.merge_request_notes(@repo_slug, @pr_number).map(&:body) end |
#create_status(state, context, target_url, description) ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'lib/ci_toolkit/gitlab_pr.rb', line 72 def create_status(state, context, target_url, description) client.update_commit_status( @repo_slug, @commit_sha, state, { name: context, target_url:, description: } ) end |
#delete_comment(comment_id) ⇒ Object
52 53 54 |
# File 'lib/ci_toolkit/gitlab_pr.rb', line 52 def delete_comment(comment_id) client.delete_merge_request_note(@repo_slug, @pr_number, comment_id) end |
#delete_comments_including_text(text) ⇒ Object
47 48 49 50 |
# File 'lib/ci_toolkit/gitlab_pr.rb', line 47 def delete_comments_including_text(text) comments = find_comments_including_text(text) comments.each { |comment| delete_comment(comment.id) } end |
#files ⇒ Object
68 69 70 |
# File 'lib/ci_toolkit/gitlab_pr.rb', line 68 def files client.merge_request_changes(@repo_slug, @pr_number).changes end |
#find_comments_including_text(text) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/ci_toolkit/gitlab_pr.rb', line 56 def find_comments_including_text(text) comments = [] client.merge_request_notes(@repo_slug, @pr_number).map do |item| comments << item if item.body&.include? text end comments end |
#get_status(context) ⇒ Object
81 82 83 84 85 86 |
# File 'lib/ci_toolkit/gitlab_pr.rb', line 81 def get_status(context) client.commit_status(@repo_slug, @commit_sha).each do |status| return status if status.name == context end nil end |
#get_status_description(context) ⇒ Object
116 117 118 119 120 121 |
# File 'lib/ci_toolkit/gitlab_pr.rb', line 116 def get_status_description(context) status = get_status(context) return if status.nil? status.description end |
#infrastructure_work? ⇒ Boolean
99 100 101 |
# File 'lib/ci_toolkit/gitlab_pr.rb', line 99 def infrastructure_work? !(title =~ /\[infra\]/i).nil? || labels.include?("Infra") end |
#labels ⇒ Object
64 65 66 |
# File 'lib/ci_toolkit/gitlab_pr.rb', line 64 def labels client.merge_request(@repo_slug, @pr_number).labels.map { |item| item } end |
#lines_of_code_changed ⇒ Object
33 34 35 36 |
# File 'lib/ci_toolkit/gitlab_pr.rb', line 33 def lines_of_code_changed pr = client.merge_request(@repo_slug, @pr_number) pr.changes_count end |
#number ⇒ Object
29 30 31 |
# File 'lib/ci_toolkit/gitlab_pr.rb', line 29 def number @pr_number end |
#realm_module_modified? ⇒ Boolean
111 112 113 114 |
# File 'lib/ci_toolkit/gitlab_pr.rb', line 111 def realm_module_modified? modified_files = files.select { |file| file&.old_path&.start_with? "cache/" } modified_files.length.positive? end |
#title ⇒ Object
25 26 27 |
# File 'lib/ci_toolkit/gitlab_pr.rb', line 25 def title client.merge_request(@repo_slug, @pr_number).title || "" end |
#work_in_progress? ⇒ Boolean
103 104 105 |
# File 'lib/ci_toolkit/gitlab_pr.rb', line 103 def work_in_progress? title.include?("[WIP]") || labels.include?("WIP") end |