summaryrefslogtreecommitdiff
path: root/danger/single_codebase/Dangerfile
blob: d1f538bec7f41296fc02c25251b5765b21154529 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
def new_teammates(usernames)
  usernames.map { |u| ::Gitlab::Danger::Teammate.new('username' => u) }
end

def mention_single_codebase_approvers
  canonical_branch_name =
    roulette.canonical_branch_name(gitlab.mr_json['source_branch'])

  random = roulette.new_random(canonical_branch_name)

  frontend_maintainers = new_teammates(%w[filipa iamphill])
  backend_maintainers = new_teammates(%w[rspeicher rymai yorickpeterse godfat])

  rows = []

  if gitlab.mr_labels.include?('frontend')
    frontend_maintainer =
      roulette.spin_for_person(frontend_maintainers, random: random)

    rows << "| ~frontend | #{frontend_maintainer.markdown_name}"
  end

  if gitlab.mr_labels.include?('backend')
    backend_maintainer =
      roulette.spin_for_person(backend_maintainers, random: random)

    rows << "| ~backend | #{backend_maintainer.markdown_name}"
  end

  if rows.empty?
    backup_maintainer = backend_maintainers.sample

    rows << "| ~frontend / ~backend | #{backup_maintainer.markdown_name}"
  end

  markdown(<<~MARKDOWN.strip)
    ## Single codebase changes

    This merge request contains changes related to the work of moving towards a
    [single codebase](https://gitlab.com/groups/gitlab-org/-/epics/802) for
    Community Edition and Enterprise Edition. These changes will need to be
    reviewed and approved by the following engineers:

    | Category | Reviewer
    |----------|---------
    #{rows.join("\n")}

    To make sure this happens, please follow these steps:

    1. Add all of the mentioned users to the list of merge request approvals.
    2. Assign the merge request to the first person in the above list.

    If you are a reviewer, please follow these steps:

    1. Review the merge request. If it is good to go, approve it.
    2. Once approved, assign to the next person in the above list. If you are
       the last person in the list, merge the merge request.
  MARKDOWN
end

if gitlab.mr_labels.include?('single codebase')
  mention_single_codebase_approvers
end