module GitHubPrOperations
this module perform basic operations on prs and contain helper functions that use octokit client for retrieving info about the PR or commit
Public Instance Methods
commit_is_unreviewed?(comm_st)
click to toggle source
if the pr has travis test and one custom, we will have 2 elements. in this case, if the 1st element doesn't have the state property state property is “pending”, failure etc. if we don't have this, so we have 0 status the PRs is “unreviewed”
# File lib/gitarro/backend.rb, line 39 def commit_is_unreviewed?(comm_st) puts comm_st.statuses[0]['state'] return false rescue NoMethodError return true end
context_present?(cm_st)
click to toggle source
check it the cm of pr contain the context from gitarro already
# File lib/gitarro/backend.rb, line 26 def context_present?(cm_st) # 1) context_present == false triggers test. > # this means the PR is not with context tagged (0..cm_st.statuses.size - 1).any? do |pr_status| cm_st.statuses[pr_status]['context'] == @context end end
create_status(pr, status)
click to toggle source
Create a status for a PR
# File lib/gitarro/backend.rb, line 61 def create_status(pr, status) client.create_status(@repo, pr.head.sha, status, context: @context, description: @description, target_url: @target_url) end
failed_status?(comm_st)
click to toggle source
# File lib/gitarro/backend.rb, line 53 def failed_status?(comm_st) (0..comm_st.statuses.size - 1).any? do |pr_status| comm_st.statuses[pr_status]['context'] == @context && comm_st.statuses[pr_status]['state'] == 'failure' end end
pending_pr?(comm_st)
click to toggle source
check if the commit of a pr is on pending
# File lib/gitarro/backend.rb, line 17 def pending_pr?(comm_st) # 2) pending (0..comm_st.statuses.size - 1).any? do |pr_status| comm_st.statuses[pr_status]['context'] == @context && comm_st.statuses[pr_status]['state'] == 'pending' end end
pr_last_update_less_than(pr, sec)
click to toggle source
Return true if the PR was updated in less than the value of variable sec or if sec < 0 (the check was disabled) GitHub considers a PR updated when there is a new commit or a new comment
# File lib/gitarro/backend.rb, line 70 def pr_last_update_less_than(pr, sec) Time.now.utc - pr.updated_at < sec || sec < 0 ? true : false end
success_status?(comm_st)
click to toggle source
# File lib/gitarro/backend.rb, line 46 def success_status?(comm_st) (0..comm_st.statuses.size - 1).any? do |pr_status| comm_st.statuses[pr_status]['context'] == @context && comm_st.statuses[pr_status]['state'] == 'success' end end