class Danger::DangerClubhouse
This is your plugin class. Any attributes or methods you expose here will be available from within your Dangerfile.
To be published on the Danger
plugins site, you will need to have the public interface documented. Danger
uses [YARD](yardoc.org/) for generating documentation from your plugin source, and you can verify by running `danger plugins lint` or `bundle exec rake spec`.
You should replace these comments with a public description of your library.
@example Ensure people are well warned about merging on Mondays
my_plugin.warn_on_mondays
@see Teng Siong Ong/danger-clubhouse @tags monday, weekends, time, rattata
This plugin will detect stories from clubhouse and link to them.
@example Customize the clubhouse organization and check for stories to link to them.
clubhouse.organization = 'organization' clubhouse.link_stories!
@see siong1987/danger-clubhouse @tags clubhouse
Attributes
The clubhouse organization name, you must set this!
@return [String]
Public Instance Methods
Find clubhouse story id in the body
@return [String, nil]
# File lib/clubhouse/plugin.rb, line 58 def find_story_id(body) if (match = body.match(/ch(\d+)/)) return match[1] end nil end
Check the branch and commit messages to find clubhouse stories to link to.
@return [void]
# File lib/clubhouse/plugin.rb, line 37 def link_stories! clubhouse_story_ids = [] # Check for the branch if (story_id = find_story_id(github.branch_for_head)) clubhouse_story_ids << story_id end # Check all the commit messages messages.each do |message| if (story_id = find_story_id(message)) clubhouse_story_ids << story_id end end post!(clubhouse_story_ids) unless clubhouse_story_ids.empty? end
Private Instance Methods
# File lib/clubhouse/plugin.rb, line 76 def messages git.commits.map(&:message) end
# File lib/clubhouse/plugin.rb, line 68 def post!(story_ids) message = "### Clubhouse Stories\n\n" story_ids.each do |id| message << "* [https://app.clubhouse.io/#{organization}/story/#{id}](https://app.clubhouse.io/#{organization}/story/#{id}) \n" end markdown message end