diff options
author | Thomas Balthazar <thomas@balthazar.info> | 2016-09-08 12:18:41 +0300 |
---|---|---|
committer | Thomas Balthazar <thomas@balthazar.info> | 2016-10-03 10:36:21 +0300 |
commit | ddbe676dc318b87c3d656a08bbf5d75485ad544b (patch) | |
tree | db8d14ffb9979d8d46772776237e33815848222e /app/models/merge_request.rb | |
parent | bcb2699f04646e4738bb87410aab49b2c3a686fb (diff) |
Add a /wip slash command
It toggles the 'WIP' prefix in the MR title.
Diffstat (limited to 'app/models/merge_request.rb')
-rw-r--r-- | app/models/merge_request.rb | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index aec555dcec0..a431d46cc9e 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -155,6 +155,20 @@ class MergeRequest < ActiveRecord::Base where("merge_requests.id IN (#{union.to_sql})") end + WIP_REGEX = /\A\s*(\[WIP\]\s*|WIP:\s*|WIP\s+)+\s*/i.freeze + + def self.work_in_progress?(title) + !!(title =~ WIP_REGEX) + end + + def self.wipless_title(title) + title.sub(WIP_REGEX, "") + end + + def self.wip_title(title) + work_in_progress?(title) ? title : "WIP: #{title}" + end + def to_reference(from_project = nil) reference = "#{self.class.reference_prefix}#{iid}" @@ -389,14 +403,16 @@ class MergeRequest < ActiveRecord::Base @closed_event ||= target_project.events.where(target_id: self.id, target_type: "MergeRequest", action: Event::CLOSED).last end - WIP_REGEX = /\A\s*(\[WIP\]\s*|WIP:\s*|WIP\s+)+\s*/i.freeze - def work_in_progress? - !!(title =~ WIP_REGEX) + self.class.work_in_progress?(title) end def wipless_title - self.title.sub(WIP_REGEX, "") + self.class.wipless_title(self.title) + end + + def wip_title + self.class.wip_title(self.title) end def mergeable?(skip_ci_check: false) |