Class: FlashFlow::Data::Github
- Inherits:
-
Object
- Object
- FlashFlow::Data::Github
- Defined in:
- lib/flash_flow/data/github.rb
Instance Attribute Summary collapse
-
#repo ⇒ Object
Returns the value of attribute repo.
-
#unmergeable_label ⇒ Object
Returns the value of attribute unmergeable_label.
Instance Method Summary collapse
- #add_to_merge(branch) ⇒ Object
- #branch_link(branch) ⇒ Object
- #can_ship?(branch) ⇒ Boolean
- #code_reviewed?(branch) ⇒ Boolean
- #fetch ⇒ Object
-
#initialize(config = {}) ⇒ Github
constructor
A new instance of Github.
- #initialize_connection!(token) ⇒ Object
- #mark_failure(branch) ⇒ Object
- #mark_success(branch) ⇒ Object
- #remove_from_merge(branch) ⇒ Object
Constructor Details
#initialize(config = {}) ⇒ Github
Returns a new instance of Github.
10 11 12 13 14 15 16 17 18 |
# File 'lib/flash_flow/data/github.rb', line 10 def initialize(config={}) initialize_connection!(config['token']) @repo = config['repo'] @master_branch = config['master_branch'] || master @unmergeable_label = config['unmergeable_label'] || 'unmergeable' @do_not_merge_label = config['do_not_merge_label'] || 'do not merge' @code_reviewed_label = config['code_reviewed_label'] || 'code reviewed' @shippable_label = config['shippable_label'] || 'shippable' end |
Instance Attribute Details
#repo ⇒ Object
Returns the value of attribute repo.
8 9 10 |
# File 'lib/flash_flow/data/github.rb', line 8 def repo @repo end |
#unmergeable_label ⇒ Object
Returns the value of attribute unmergeable_label.
8 9 10 |
# File 'lib/flash_flow/data/github.rb', line 8 def unmergeable_label @unmergeable_label end |
Instance Method Details
#add_to_merge(branch) ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/flash_flow/data/github.rb', line 47 def add_to_merge(branch) pr = pr_for(branch) pr ||= create_pr(branch.ref, branch.ref, branch.ref) branch.((pr)) if pr && @do_not_merge_label remove_label(pr.number, @do_not_merge_label) end end |
#branch_link(branch) ⇒ Object
74 75 76 |
# File 'lib/flash_flow/data/github.rb', line 74 def branch_link(branch) branch.['pr_url'] end |
#can_ship?(branch) ⇒ Boolean
70 71 72 |
# File 'lib/flash_flow/data/github.rb', line 70 def can_ship?(branch) has_label?(branch.['pr_number'], @shippable_label) end |
#code_reviewed?(branch) ⇒ Boolean
66 67 68 |
# File 'lib/flash_flow/data/github.rb', line 66 def code_reviewed?(branch) has_label?(branch.['pr_number'], @code_reviewed_label) end |
#fetch ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/flash_flow/data/github.rb', line 36 def fetch pull_requests.map do |pr| Branch.from_hash( 'ref' => pr.head.ref, 'status' => status_from_labels(pr), 'metadata' => (pr), 'sha' => pr.head.sha ) end end |
#initialize_connection!(token) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/flash_flow/data/github.rb', line 20 def initialize_connection!(token) if token.nil? raise RuntimeError.new("Github token must be set in your flash_flow config file.") end octokit.configure do |c| c.access_token = token end end |
#mark_failure(branch) ⇒ Object
62 63 64 |
# File 'lib/flash_flow/data/github.rb', line 62 def mark_failure(branch) add_label(branch.['pr_number'], @unmergeable_label) end |
#mark_success(branch) ⇒ Object
58 59 60 |
# File 'lib/flash_flow/data/github.rb', line 58 def mark_success(branch) remove_label(branch.['pr_number'], @unmergeable_label) end |
#remove_from_merge(branch) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/flash_flow/data/github.rb', line 29 def remove_from_merge(branch) pr = pr_for(branch) if pr && @do_not_merge_label add_label(pr.number, @do_not_merge_label) end end |