Module: GitHubPrOperations

Included in:
Backend
Defined in:
lib/gitarro/backend.rb

Overview

this module perform basic operations on prs and contain helper functions that use octokit client for retrieving info about the PR or commit

Instance Method Summary collapse

Instance Method Details

#commit_is_unreviewed?(comm_st) ⇒ Boolean

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”

Returns:

  • (Boolean)


39
40
41
42
43
44
# 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) ⇒ Boolean

check it the cm of pr contain the context from gitarro already

Returns:

  • (Boolean)


26
27
28
29
30
31
32
# 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) ⇒ Object

Create a status for a PR



61
62
63
64
65
# 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) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
56
57
58
# 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) ⇒ Boolean

check if the commit of a pr is on pending

Returns:

  • (Boolean)


17
18
19
20
21
22
23
# 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) ⇒ Object

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



70
71
72
# 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) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
49
50
51
# 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