Class: Danger::GithubUtils
- Inherits:
-
Plugin
- Object
- Plugin
- Danger::GithubUtils
- Defined in:
- lib/dangermattic/plugins/common/github_utils.rb
Overview
Provides common GitHub utility methods related to Pull Requests in a Danger context.
Instance Method Summary collapse
-
#active_reviewers? ⇒ Boolean
Checks if there are active reviewers providing feedback and potentially changing the state of the PR (e.g., approved, changes requested).
-
#main_branch? ⇒ Boolean
Checks if the current branch is a main branch (trunk, main, master, or develop).
-
#release_branch? ⇒ Boolean
Checks if the current branch is a release or hotfix branch.
-
#requested_reviewers? ⇒ Boolean
Checks if there are requested teams or reviewers who haven't reacted yet.
-
#wip_feature? ⇒ Boolean
Checks if the PR is a work-in-progress (WIP) based on labels or title.
Instance Method Details
#active_reviewers? ⇒ Boolean
Checks if there are active reviewers providing feedback and potentially changing the state of the PR (e.g., approved, changes requested).
29 30 31 32 33 34 |
# File 'lib/dangermattic/plugins/common/github_utils.rb', line 29 def active_reviewers? repo_name = github.pr_json['base']['repo']['full_name'] pr_number = github.pr_json['number'] !github.api.pull_request_reviews(repo_name, pr_number).empty? end |
#main_branch? ⇒ Boolean
Checks if the current branch is a main branch (trunk, main, master, or develop).
47 48 49 |
# File 'lib/dangermattic/plugins/common/github_utils.rb', line 47 def main_branch? %w[trunk main master develop].include?(github.branch_for_base) end |
#release_branch? ⇒ Boolean
Checks if the current branch is a release or hotfix branch.
54 55 56 |
# File 'lib/dangermattic/plugins/common/github_utils.rb', line 54 def release_branch? github.branch_for_base.start_with?('release/') || github.branch_for_base.start_with?('hotfix/') end |
#requested_reviewers? ⇒ Boolean
Checks if there are requested teams or reviewers who haven't reacted yet.
39 40 41 42 |
# File 'lib/dangermattic/plugins/common/github_utils.rb', line 39 def requested_reviewers? has_requested_reviews = !github.pr_json['requested_teams'].to_a.empty? || !github.pr_json['requested_reviewers'].to_a.empty? has_requested_reviews || active_reviewers? end |
#wip_feature? ⇒ Boolean
Checks if the PR is a work-in-progress (WIP) based on labels or title.
61 62 63 64 65 66 |
# File 'lib/dangermattic/plugins/common/github_utils.rb', line 61 def wip_feature? has_wip_label = github.pr_labels.any? { |label| label.include?('WIP') } has_wip_title = github.pr_title.include?('WIP') has_wip_label || has_wip_title end |