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 |
# File 'lib/dangermattic/plugins/common/github_utils.rb', line 29 def active_reviewers? !github.api.pull_request_reviews(pr_repo_name, pr_number).empty? end |
#main_branch? ⇒ Boolean
Checks if the current branch is a main branch (trunk, main, master, or develop).
49 50 51 |
# File 'lib/dangermattic/plugins/common/github_utils.rb', line 49 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.
56 57 58 |
# File 'lib/dangermattic/plugins/common/github_utils.rb', line 56 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.
36 37 38 39 40 41 42 43 44 |
# File 'lib/dangermattic/plugins/common/github_utils.rb', line 36 def requested_reviewers? # GitHub strips `requested_teams` from the pull request payload — and therefore from `pr_json` — # for tokens that cannot see the organization's teams, such as a bot account that is only an # outside collaborator. The dedicated endpoint reports them regardless. review_requests = github.api.pull_request_review_requests(pr_repo_name, pr_number) has_requested_reviews = !review_requests['users'].to_a.empty? || !review_requests['teams'].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.
63 64 65 66 67 68 |
# File 'lib/dangermattic/plugins/common/github_utils.rb', line 63 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 |