-
-
Notifications
You must be signed in to change notification settings - Fork 375
Expand file tree
/
Copy pathgetMergeRequestChanges.json
More file actions
209 lines (209 loc) · 12 KB
/
getMergeRequestChanges.json
File metadata and controls
209 lines (209 loc) · 12 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
[
{
"scope": "https://gitlab.com:443",
"method": "GET",
"path": "/api/v4/projects/456/merge_requests/27117/changes",
"body": "",
"status": 200,
"response": {
"id": 27253868,
"iid": 27117,
"project_id": 13083,
"title": "Stable reviewer roulette",
"description": "Change reviewer roulette to always pick the same reviewers for the same\nbranch name. We do this by:\n\n1. Making the branch name 'canonical' across CE and EE by stripping a\n leading 'ce-' or 'ee-' and a trailing '-ce' or '-ee'. If people are\n following our branch naming guidelines, this should give the same\n branch name in both repos.\n2. Converting the branch name to a stable integer by taking the integer\n form of its MD5.\n3. Passing that integer as a seed to Ruby's `Random` class, which 'may\n be used to ensure repeatable sequences of pseudo-random numbers\n between different runs of the program' (from the Ruby documentation).\n\nThe upshot is that the same branch name (in CE and EE) should always\npick the same reviewers, and those should be evenly distributed across\nthe set of possible reviewers due to the use of MD5.\n\nAgain, I have a test script:\n\n```ruby\nrequire 'ffaker'\n\nclass Foo\n include Gitlab::Danger::Helper\nend\n\ndef spin(team, project, category, branch_name)\n # Strip leading and trailing CE/EE markers\n canonical_branch_name = branch_name.gsub(/^[ce]e-/, '').gsub(/-[ce]e$/, '')\n rng = Random.new(Digest::MD5.hexdigest(canonical_branch_name).to_i(16))\n\n reviewers = team.select { |member| member.reviewer?(project, category) }\n traintainers = team.select { |member| member.traintainer?(project, category) }\n maintainers = team.select { |member| member.maintainer?(project, category) }\n\n # TODO: filter out people who are currently not in the office\n # https://gitlab.com/gitlab-org/gitlab-ce/issues/57652\n #\n # TODO: take CODEOWNERS into account?\n # https://gitlab.com/gitlab-org/gitlab-ce/issues/57653\n\n # Make traintainers have triple the chance to be picked as a reviewer\n reviewer = (reviewers + traintainers + traintainers).sample(random: rng)\n maintainer = maintainers.sample(random: rng)\n\n [reviewer.username, maintainer.username]\nend\n\ndef random_branch_name\n FFaker::Filesystem.file_name\nend\n\nFFaker::Random.seed = 123\nteam = Foo.new.project_team\nresults = Hash.new(0)\n\n10_000.times do\n reviewer, maintainer = spin(team, 'gitlab-ce', 'backend', random_branch_name)\n\n results[reviewer] += 1\n results[maintainer] += 1\nend\n\nresults.sort_by(&:last).reverse.each do |username, picked|\n puts \"#{username}: #{picked}\"\nend; nil\n```\n\nThis should output the same for you as it does for me, because we seed the branch names too!\n\n```\ndzaporozhets: 799\nmkozono: 797\ngrzesiek: 794\ngodfat: 793\nDouweM: 788\nnick.thomas: 773\ntkuah: 764\nstanhu: 761\nayufan: 759\njprovaznik: 758\njameslopez: 757\ndbalexandre: 754\nsmcgivern: 751\nsplattael: 744\nashmckenzie: 741\nrspeicher: 739\njarka: 738\nrymai: 735\nreprazent: 729\nmayra-cabrera: 713\nmdelaossa: 273\nrdavila: 269\nvsizov: 260\ntheoretick: 257\noswaldo: 255\nifarkas: 255\nbrytannia: 248\nengwan: 248\nfelipe_artur: 247\nrpereira2: 243\ntoon: 239\nrossfuhrman: 236\njamedjo: 235\nfjsanpedro: 229\nmatteeyah: 226\nbrodock: 226\nvzagorodny: 222\nzj: 220\nmarkglenfletcher: 219\ndosuken123: 206\n```\n\nCloses https://gitlab.com/gitlab-org/gitlab-ce/issues/57766.",
"state": "merged",
"created_at": "2019-04-08T10:59:38.140Z",
"updated_at": "2019-05-02T14:34:54.068Z",
"merged_by": {
"id": 283999,
"name": "Douglas Barbosa Alexandre",
"username": "dbalexandre",
"state": "active",
"avatar_url": "https://gl-canary.freetls.fastly.net/uploads/-/system/user/avatar/283999/avatar.png",
"web_url": "https://gitlab.com/dbalexandre"
},
"merged_at": "2019-04-09T13:57:11.931Z",
"closed_by": null,
"closed_at": null,
"target_branch": "master",
"source_branch": "stable-reviewer-roulette",
"user_notes_count": 4,
"upvotes": 3,
"downvotes": 0,
"assignee": {
"id": 283999,
"name": "Douglas Barbosa Alexandre",
"username": "dbalexandre",
"state": "active",
"avatar_url": "https://gl-canary.freetls.fastly.net/uploads/-/system/user/avatar/283999/avatar.png",
"web_url": "https://gitlab.com/dbalexandre"
},
"author": {
"id": 443319,
"name": "Sean McGivern",
"username": "smcgivern",
"state": "active",
"avatar_url": "https://gl-canary.freetls.fastly.net/uploads/-/system/user/avatar/443319/avatar.png",
"web_url": "https://gitlab.com/smcgivern"
},
"assignees": [
{
"id": 283999,
"name": "Douglas Barbosa Alexandre",
"username": "dbalexandre",
"state": "active",
"avatar_url": "https://gl-canary.freetls.fastly.net/uploads/-/system/user/avatar/283999/avatar.png",
"web_url": "https://gitlab.com/dbalexandre"
}
],
"source_project_id": 13083,
"target_project_id": 13083,
"labels": [
"Danger bot",
"Plan",
"backend",
"backstage"
],
"work_in_progress": false,
"milestone": {
"id": 655280,
"iid": 28,
"group_id": 9970,
"title": "11.11",
"description": "",
"state": "active",
"created_at": "2018-09-21T19:08:37.027Z",
"updated_at": "2019-01-16T19:48:19.411Z",
"due_date": "2019-05-22",
"start_date": "2019-04-08",
"web_url": "https://gitlab.com/groups/gitlab-org/-/milestones/28"
},
"merge_when_pipeline_succeeds": false,
"merge_status": "can_be_merged",
"sha": "28531ab43666b5fdf37e0a70db3bcbf7d3f92183",
"merge_commit_sha": "58d4099c1469dba9ff850733ba29da11f6eeb158",
"discussion_locked": null,
"should_remove_source_branch": null,
"force_remove_source_branch": true,
"reference": "!27117",
"web_url": "https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/27117",
"time_stats": {
"time_estimate": 0,
"total_time_spent": 0,
"human_time_estimate": null,
"human_total_time_spent": null
},
"squash": false,
"subscribed": false,
"changes_count": "1",
"latest_build_started_at": "2019-04-08T10:56:58.249Z",
"latest_build_finished_at": "2019-04-08T11:56:52.871Z",
"first_deployed_to_production_at": null,
"pipeline": {
"id": 55706028,
"sha": "28531ab43666b5fdf37e0a70db3bcbf7d3f92183",
"ref": "stable-reviewer-roulette",
"status": "success",
"web_url": "https://gitlab.com/gitlab-org/gitlab-ce/pipelines/55706028"
},
"head_pipeline": {
"id": 55706028,
"sha": "28531ab43666b5fdf37e0a70db3bcbf7d3f92183",
"ref": "stable-reviewer-roulette",
"status": "success",
"web_url": "https://gitlab.com/gitlab-org/gitlab-ce/pipelines/55706028",
"before_sha": "0000000000000000000000000000000000000000",
"tag": false,
"yaml_errors": null,
"user": {
"id": 443319,
"name": "Sean McGivern",
"username": "smcgivern",
"state": "active",
"avatar_url": "https://gl-canary.freetls.fastly.net/uploads/-/system/user/avatar/443319/avatar.png",
"web_url": "https://gitlab.com/smcgivern"
},
"created_at": "2019-04-08T10:56:50.639Z",
"updated_at": "2019-04-08T11:56:52.890Z",
"started_at": "2019-04-08T10:56:58.249Z",
"finished_at": "2019-04-08T11:56:52.871Z",
"committed_at": null,
"duration": 3592,
"coverage": "76.34",
"detailed_status": {
"icon": "status_warning",
"text": "passed",
"label": "passed with warnings",
"group": "success-with-warnings",
"tooltip": "passed",
"has_details": true,
"details_path": "/gitlab-org/gitlab-ce/pipelines/55706028",
"illustration": null,
"favicon": "https://gitlab.com/assets/ci_favicons/favicon_status_success-8451333011eee8ce9f2ab25dc487fe24a8758c694827a582f17f42b0a90446a2.png"
}
},
"diff_refs": {
"base_sha": "50cd5d9b776848cf23f1fd1ec52789dbdf946185",
"head_sha": "28531ab43666b5fdf37e0a70db3bcbf7d3f92183",
"start_sha": "50cd5d9b776848cf23f1fd1ec52789dbdf946185"
},
"merge_error": null,
"user": {
"can_merge": false
},
"changes": [
{
"old_path": "danger/roulette/Dangerfile",
"new_path": "danger/roulette/Dangerfile",
"a_mode": "100644",
"b_mode": "100644",
"new_file": false,
"renamed_file": false,
"deleted_file": false,
"diff": "@@ -1,5 +1,7 @@\n # frozen_string_literal: true\n \n+require 'digest/md5'\n+\n MESSAGE = <<MARKDOWN\n ## Reviewer roulette\n \n@@ -29,17 +31,22 @@ Please consider creating a merge request to\n for them.\n MARKDOWN\n \n-def spin(team, project, category)\n+def spin(team, project, category, branch_name)\n+ rng = Random.new(Digest::MD5.hexdigest(branch_name).to_i(16))\n+\n reviewers = team.select { |member| member.reviewer?(project, category) }\n traintainers = team.select { |member| member.traintainer?(project, category) }\n maintainers = team.select { |member| member.maintainer?(project, category) }\n \n # TODO: filter out people who are currently not in the office\n+ # https://gitlab.com/gitlab-org/gitlab-ce/issues/57652\n+ #\n # TODO: take CODEOWNERS into account?\n+ # https://gitlab.com/gitlab-org/gitlab-ce/issues/57653\n \n # Make traintainers have triple the chance to be picked as a reviewer\n- reviewer = (reviewers + traintainers + traintainers).sample\n- maintainer = maintainers.sample\n+ reviewer = (reviewers + traintainers + traintainers).sample(random: rng)\n+ maintainer = maintainers.sample(random: rng)\n \n \"| #{helper.label_for_category(category)} | #{reviewer&.markdown_name} | #{maintainer&.markdown_name} |\"\n end\n@@ -65,6 +72,12 @@ categories = changes.keys - [:unknown]\n # CSS Clean up MRs are reviewed using a slightly different process, so we\n # disable the review roulette for such MRs.\n if changes.any? && !gitlab.mr_labels.include?('single codebase') && !gitlab.mr_labels.include?('CSS cleanup')\n+ # Strip leading and trailing CE/EE markers\n+ canonical_branch_name = gitlab\n+ .mr_json['source_branch']\n+ .gsub(/^[ce]e-/, '')\n+ .gsub(/-[ce]e$/, '')\n+\n team =\n begin\n helper.project_team\n@@ -79,7 +92,7 @@ if changes.any? && !gitlab.mr_labels.include?('single codebase') && !gitlab.mr_l\n project = helper.project_name\n unknown = changes.fetch(:unknown, [])\n \n- rows = categories.map { |category| spin(team, project, category) }\n+ rows = categories.map { |category| spin(team, project, category, canonical_branch_name) }\n \n markdown(MESSAGE)\n markdown(CATEGORY_TABLE_HEADER + rows.join(\"\\n\")) unless rows.empty?\n"
}
],
"approvals_before_merge": 1
},
"rawHeaders": [
"Server",
"nginx",
"Date",
"Mon, 20 May 2019 11:12:29 GMT",
"Content-Type",
"application/json",
"Content-Length",
"9716",
"Connection",
"close",
"Cache-Control",
"max-age=0, private, must-revalidate",
"Etag",
"W/\"bf357e7f9ec7b9741dc37b4a7d3b06a5\"",
"Vary",
"Origin",
"X-Content-Type-Options",
"nosniff",
"X-Frame-Options",
"SAMEORIGIN",
"X-Request-Id",
"wFe4erjUq65",
"X-Runtime",
"0.254567",
"Strict-Transport-Security",
"max-age=31536000",
"Referrer-Policy",
"strict-origin-when-cross-origin",
"RateLimit-Limit",
"600",
"RateLimit-Observed",
"3",
"RateLimit-Remaining",
"597",
"RateLimit-Reset",
"1558350809",
"RateLimit-ResetTime",
"Mon, 20 May 2019 11:13:29 GMT"
]
}
]