diff options
Diffstat (limited to 'danger/rules/milestones/Dangerfile')
-rw-r--r-- | danger/rules/milestones/Dangerfile | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/danger/rules/milestones/Dangerfile b/danger/rules/milestones/Dangerfile new file mode 100644 index 000000000..ce74bbb87 --- /dev/null +++ b/danger/rules/milestones/Dangerfile @@ -0,0 +1,23 @@ +unless gitlab.mr_json["milestone"] + issues = gitlab.api.merge_request_closes_issues(gitlab.mr_json['project_id'], gitlab.mr_json['iid']) + + milestone_id = issues + .map { |i| i.milestone } + .compact + .reject { |m| m.state == "closed" || m.due_date.nil? } + .sort_by { |m| m.due_date } + .first + &.id + + if milestone_id + gitlab.api.update_merge_request( + gitlab.mr_json['project_id'], + gitlab.mr_json['iid'], + milestone_id: milestone_id + ) + else + warn "No milestone was set, nor could it be detected from the issues this merge request closes." + end +end + +# vim: ft=ruby |