Skip to content

Commit 8944612

Browse files
Change issue status after merge request is merged.
1 parent c101e6a commit 8944612

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ One of the following environment variables need to be set:
4141
They must contain secrets which have to be configured in GitLab/GitHub to
4242
authenticate webhooks.
4343

44+
Optionally, you can also set the following variables:
45+
46+
* `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.
48+
4449
Export the environment variable(s) in your bash or webserver config.
4550
Examples with Phusion Passenger webserver can be found here:
4651
https://www.phusionpassenger.com/library/indepth/environment_variables.html

app/models/merge_request.rb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class MergeRequest < ActiveRecord::Base
1010
# update the author name only once.
1111
attr_readonly :author_name
1212

13-
after_save :scan_description_for_issue_ids
13+
after_save :scan_description_for_issue_ids, :update_mentioned_issues_status
1414

1515
def self.find_all_by_issue(issue)
1616
includes(:issues).where(issues: { id: issue.id })
@@ -31,4 +31,22 @@ def mentioned_issue_ids
3131
(value || '').scan(ISSUE_ID_REGEXP)
3232
end.uniq
3333
end
34+
35+
def update_mentioned_issues_status
36+
redmine_user_id = ENV['REDMINE_MERGE_REQUEST_LINKS_GITLAB_REDMINE_USER_ID']
37+
after_merge_status = ENV['REDMINE_MERGE_REQUEST_LINKS_AFTER_MERGE_STATUS']
38+
39+
if state != 'merged' || redmine_user_id.blank? || after_merge_status.blank?
40+
return
41+
end
42+
43+
mentioned_issue_ids.map do |match|
44+
issue = Issue.find_by_id(match[0])
45+
if issue.present?
46+
issue.init_journal(User.find(redmine_user_id))
47+
issue.status = IssueStatus.find_by_name(after_merge_status)
48+
issue.save!
49+
end
50+
end
51+
end
3452
end

0 commit comments

Comments
 (0)