Skip to content

Commit db75482

Browse files
Add support for fixing keywords
1 parent 06a2634 commit db75482

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ authenticate webhooks.
4444
Optionally, you can also set the following variables:
4545

4646
* `REDMINE_MERGE_REQUEST_LINKS_AFTER_MERGE_STATUS` - Name of issue status which should be set after the merge request is merged.
47-
* `REDMINE_MERGE_REQUEST_LINKS_GITLAB_REDMINE_USER_ID` - ID of Redmine user who should change the status - used as journal author.
47+
* `REDMINE_MERGE_REQUEST_LINKS_REDMINE_USER_ID` - ID of Redmine user who should change the status - used as journal author.
48+
* `REDMINE_MERGE_REQUEST_LINKS_FIXING_KEYWORD_PATTERN` - Fixing keyword pattern. When set, the issue status is changed only when issue ID is preceeded with the fixing pattern. Example pattern: `(?:clos(?:e[sd]?|ing)|fix(?:e[sd]|ing)?|resolv(?:e[sd]?|ing))`
4849

4950
Export the environment variable(s) in your bash or webserver config.
5051
Examples with Phusion Passenger webserver can be found here:

app/models/merge_request.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,22 @@ def mentioned_issue_ids
3232
end.uniq
3333
end
3434

35+
def fixed_issue_ids(fixing_pattern)
36+
fixed_issue_regexp = fixing_pattern + ISSUE_ID_REGEXP.source
37+
[description, title].flat_map do |value|
38+
(value || '').scan(/#{fixed_issue_regexp}/i)
39+
end.uniq
40+
end
41+
3542
def update_mentioned_issues_status
36-
redmine_user_id = ENV['REDMINE_MERGE_REQUEST_LINKS_GITLAB_REDMINE_USER_ID']
43+
redmine_user_id = ENV['REDMINE_MERGE_REQUEST_LINKS_REDMINE_USER_ID']
3744
after_merge_status = ENV['REDMINE_MERGE_REQUEST_LINKS_AFTER_MERGE_STATUS']
38-
45+
fixing_pattern = ENV['REDMINE_MERGE_REQUEST_LINKS_FIXING_KEYWORD_PATTERN']
3946
if state != 'merged' || redmine_user_id.blank? || after_merge_status.blank?
4047
return
4148
end
42-
43-
mentioned_issue_ids.map do |match|
49+
issue_ids = fixing_pattern.present? ? fixed_issue_ids(fixing_pattern) : mentioned_issue_ids
50+
issue_ids.map do |match|
4451
issue = Issue.find_by_id(match[0])
4552
if issue.present?
4653
issue.init_journal(User.find(redmine_user_id))

0 commit comments

Comments
 (0)