diff options
author | ash wilson <smashwilson@gmail.com> | 2013-05-30 23:16:49 +0000 |
---|---|---|
committer | Ash Wilson <smashwilson@gmail.com> | 2013-08-25 18:58:41 -0400 |
commit | c8a115c0e3a9c8242c2a422572d47a49e0cb2874 (patch) | |
tree | 5a36c3e0f364fdfb710e01090fc81b9676ea53c4 /app/models/commit.rb | |
parent | 2b36dee64485062c69779217d4a202e5ca1b67bd (diff) | |
download | gitlab-ce-c8a115c0e3a9c8242c2a422572d47a49e0cb2874.tar.gz |
Link issues from comments and automatically close them
Any mention of Issues, MergeRequests, or Commits via GitLab-flavored markdown
references in descriptions, titles, or attached Notes creates a back-reference
Note that links to the original referencer. Furthermore, pushing commits with
commit messages that match a (configurable) regexp to a project's default
branch will close any issues mentioned by GFM in the matched closing phrase.
If accepting a merge request would close any Issues in this way, a banner is
appended to the merge request's main panel to indicate this.
Diffstat (limited to 'app/models/commit.rb')
-rw-r--r-- | app/models/commit.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb index da80c2940ff..f8ca6a5fe82 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -2,6 +2,9 @@ class Commit include ActiveModel::Conversion include StaticModel extend ActiveModel::Naming + include Mentionable + + attr_mentionable :safe_message # Safe amount of files with diffs in one commit to render # Used to prevent 500 error on huge commits by suppressing diff @@ -65,6 +68,29 @@ class Commit end end + # Regular expression that identifies commit message clauses that trigger issue closing. + def issue_closing_regex + @issue_closing_regex ||= Regexp.new(Gitlab.config.gitlab.issue_closing_pattern) + end + + # Discover issues should be closed when this commit is pushed to a project's + # default branch. + def closes_issues project + md = issue_closing_regex.match(safe_message) + if md + extractor = Gitlab::ReferenceExtractor.new + extractor.analyze(md[0]) + extractor.issues_for(project) + else + [] + end + end + + # Mentionable override. + def gfm_reference + "commit #{sha[0..5]}" + end + def method_missing(m, *args, &block) @raw.send(m, *args, &block) end |