1
1
#!/usr/bin/env -S scala-cli shebang
2
2
// SPDX-License-Identifier: Apache-2.0
3
3
//> using scala " 2.13"
4
- //> using dep " io.circe::circe-yaml:0.15.1 "
5
- //> using dep " com.lihaoyi::os-lib:0.9.1 "
4
+ //> using dep " io.circe::circe-yaml:0.16.0 "
5
+ //> using dep " com.lihaoyi::os-lib:0.11.3 "
6
6
7
7
/* Generates a Mergify config YAML (to STDOUT) based on input config
8
8
*
9
9
* There are built-in conditions, but different CI requires different conditions
10
10
* Listed branches should be stable branches that we want to backport to, in ascending order
11
- * {{{
11
+ *
12
12
* conditions:
13
- - status-success=Travis CI - Pull Request
13
+ - status-success=all tests passed
14
14
branches:
15
- - 1.2 .x
16
- - 1.3 .x
17
- - 1.4 .x
18
- * }}}
15
+ - 3.6 .x
16
+ - 5 .x
17
+ - 6 .x
18
+ *
19
19
*/
20
20
21
21
import io .circe ._
22
22
import io .circe .syntax ._ // for .asJson
23
23
import io .circe .yaml .parser
24
24
import io .circe .yaml .syntax ._ // for .asYaml
25
25
26
- def mergeQueue (conditions : List [String ]) = Json .obj(
27
- " name" -> " default" .asJson,
28
- " conditions" -> conditions.asJson,
29
- " draft_bot_account" -> " chiselbot" .asJson,
30
- " update_bot_account" -> " chiselbot" .asJson,
31
- " merge_bot_account" -> " chiselbot" .asJson
32
- )
33
-
34
- val queueAction = Json .obj(
35
- " queue" -> Json .obj(
36
- " name" -> " default" .asJson,
37
- " method" -> " squash" .asJson,
38
- " update_method" -> " merge" .asJson,
39
- " update_bot_account" -> " chiselbot" .asJson,
40
- " merge_bot_account" -> " chiselbot" .asJson
41
- )
42
- )
43
-
44
- def mergeToMain (conditions : List [String ]) = Json .obj(
45
- " name" -> " automatic squash-and-merge on CI success and review" .asJson,
46
- " conditions" -> (conditions ++ List (
47
- " #approved-reviews-by>=1" ,
26
+ def mergeQueue (branch : String , conditions : List [String ]) = Json .obj(
27
+ " name" -> s " $branch merge queue " .asJson,
28
+ " queue_conditions" -> (conditions ++ List (
29
+ s " base= $branch" ,
48
30
" #changes-requested-reviews-by=0" ,
49
- " base=main" ,
50
- " label=\" Please Merge\" " ,
31
+ " label=\" Backport\" " ,
51
32
" label!=\" DO NOT MERGE\" " ,
52
33
" label!=\" bp-conflict\" "
53
34
)).asJson,
54
- " actions" -> queueAction
35
+ " merge_conditions" -> conditions.asJson,
36
+ " draft_bot_account" -> " chiselbot" .asJson,
37
+ " update_bot_account" -> " chiselbot" .asJson,
38
+ " merge_bot_account" -> " chiselbot" .asJson
55
39
)
56
40
57
41
def makeBackportRule (branches : List [String ]): Json = {
58
42
Json .obj(
59
43
" name" -> s """ backport to ${branches.mkString(" , " )}""" .asJson,
60
- " conditions" -> List (" merged" , " base=main " , s " milestone= ${branches.head}" ).asJson,
44
+ " conditions" -> List (" merged" , s " milestone= ${branches.head}" ).asJson,
61
45
" actions" -> Json .obj(
62
46
" backport" -> Json .obj(
63
47
" branches" -> branches.asJson,
64
48
" labels" -> List (" Backport" ).asJson,
65
49
" ignore_conflicts" -> true .asJson,
66
- " label_conflicts" -> " bp-conflict" .asJson
50
+ " merge_conflict_style" -> " diff3" .asJson,
51
+ " label_conflicts" -> " bp-conflict" .asJson,
52
+ " bot_account" -> " chiselbot" .asJson,
53
+ " report_mode" -> List (" comment" ).asJson
67
54
),
68
55
" label" -> Json .obj(
69
56
" add" -> List (" Backported" ).asJson
@@ -73,34 +60,40 @@ def makeBackportRule(branches: List[String]): Json = {
73
60
}
74
61
75
62
def backportMergeRule (conditions : List [String ])(branch : String ): Json = Json .obj(
76
- " name" -> s " automatic squash-and-mege of $branch backport PRs " .asJson,
63
+ " name" -> s " queue $branch backport PRs " .asJson,
77
64
" conditions" -> (conditions ++ List (
78
65
" #changes-requested-reviews-by=0" ,
79
66
s " base= $branch" ,
80
67
" label=\" Backport\" " ,
81
68
" label!=\" DO NOT MERGE\" " ,
82
69
" label!=\" bp-conflict\" "
83
70
)).asJson,
84
- " actions" -> queueAction
71
+ " actions" -> Json .obj(
72
+ " queue" -> Json .obj(
73
+ " name" -> s " $branch merge queue " .asJson
74
+ )
75
+ )
85
76
)
86
77
87
-
88
78
def error (msg : String ) = throw new Exception (msg) with scala.util.control.NoStackTrace
89
79
90
80
def processTemplate (path : os.Path ): (List [String ], List [String ]) = {
91
81
val contents = os.read(path)
92
- val parsed = parser.parse(contents)
93
- .getOrElse(error(s " Invalid YAML $path" ))
82
+ val parsed = parser
83
+ .parse(contents)
84
+ .getOrElse(error(s " Invalid YAML $path" ))
94
85
95
86
val cursor : HCursor = parsed.hcursor
96
87
97
- val conditions = cursor.downField(" conditions" )
98
- .as[List [String ]]
99
- .getOrElse(error(s " Invalid template, expected field 'conditions': List[String] " ))
88
+ val conditions = cursor
89
+ .downField(" conditions" )
90
+ .as[List [String ]]
91
+ .getOrElse(error(s " Invalid template, expected field 'conditions': List[String] " ))
100
92
101
- val branches = cursor.downField(" branches" )
102
- .as[List [String ]]
103
- .getOrElse(error(s " Invalid template, expected field 'branches': List[String] " ))
93
+ val branches = cursor
94
+ .downField(" branches" )
95
+ .as[List [String ]]
96
+ .getOrElse(error(s " Invalid template, expected field 'branches': List[String] " ))
104
97
(conditions, branches)
105
98
}
106
99
@@ -112,15 +105,13 @@ val (conditions, branches) = processTemplate(template)
112
105
val branchSets = branches.scanRight(List .empty[String ])(_ :: _).init.reverse
113
106
114
107
val config = Json .obj(
115
- " queue_rules" -> Json .fromValues(
116
- mergeQueue(conditions) ::
117
- Nil
118
- ),
119
- " pull_request_rules" -> Json .fromValues(
120
- mergeToMain(conditions) ::
121
- branchSets.map(makeBackportRule) :::
122
- branches.map(backportMergeRule(conditions))
123
- )
108
+ " queue_rules" -> Json .fromValues(
109
+ branches.map(mergeQueue(_, conditions))
110
+ ),
111
+ " pull_request_rules" -> Json .fromValues(
112
+ branchSets.map(makeBackportRule) :::
113
+ branches.map(backportMergeRule(conditions))
114
+ )
124
115
)
125
116
126
117
println(s " # Generated by $scriptPath" )
0 commit comments