7
7
import requests
8
8
9
9
10
+ def get_versions (versions_file ):
11
+ """Get the versions of the packages used in the linter job.
12
+
13
+ Parameters
14
+ ----------
15
+ versions_file : str
16
+ The path to the file that contains the versions of the packages.
17
+
18
+ Returns
19
+ -------
20
+ versions : dict
21
+ A dictionary with the versions of the packages.
22
+ """
23
+ with open ("versions.txt" , "r" ) as f :
24
+ return dict (line .strip ().split ("=" ) for line in f )
25
+
26
+
10
27
def get_step_message (log , start , end , title , message , details ):
11
28
"""Get the message for a specific test.
12
29
@@ -52,10 +69,29 @@ def get_step_message(log, start, end, title, message, details):
52
69
return res
53
70
54
71
55
- def get_message (log_file , repo , pr_number , sha , run_id , details ):
72
+ def get_message (log_file , repo , pr_number , sha , run_id , details , versions ):
56
73
with open (log_file , "r" ) as f :
57
74
log = f .read ()
58
75
76
+ sub_text = (
77
+ "\n \n <sub> _Generated for commit:"
78
+ f" [{ sha [:7 ]} ](https://github.com/{ repo } /pull/{ pr_number } /commits/{ sha } ). "
79
+ "Link to the linter CI: [here]"
80
+ f"(https://github.com/{ repo } /actions/runs/{ run_id } )_ </sub>"
81
+ )
82
+
83
+ if "### Linting completed ###" not in log :
84
+ return (
85
+ "## ❌ Linting issues\n \n "
86
+ "There was an issue running the linter job. Please update with "
87
+ "`upstream/main` ([link]("
88
+ "https://scikit-learn.org/dev/developers/contributing.html"
89
+ "#how-to-contribute)) and push the changes. If you already have done "
90
+ "that, please send an empty commit with `git commit --allow-empty` "
91
+ "and push the changes to trigger the CI.\n \n "
92
+ + sub_text
93
+ )
94
+
59
95
message = ""
60
96
61
97
# black
@@ -68,7 +104,8 @@ def get_message(log_file, repo, pr_number, sha, run_id, details):
68
104
"`black` detected issues. Please run `black .` locally and push "
69
105
"the changes. Here you can see the detected issues. Note that "
70
106
"running black might also fix some of the issues which might be "
71
- "detected by `ruff`."
107
+ "detected by `ruff`. Note that the installed `black` version is "
108
+ f"`black={ versions ['black' ]} `."
72
109
),
73
110
details = details ,
74
111
)
@@ -82,7 +119,8 @@ def get_message(log_file, repo, pr_number, sha, run_id, details):
82
119
message = (
83
120
"`ruff` detected issues. Please run `ruff --fix --show-source .` "
84
121
"locally, fix the remaining issues, and push the changes. "
85
- "Here you can see the detected issues."
122
+ "Here you can see the detected issues. Note that the installed "
123
+ f"`ruff` version is `ruff={ versions ['ruff' ]} `."
86
124
),
87
125
details = details ,
88
126
)
@@ -95,7 +133,8 @@ def get_message(log_file, repo, pr_number, sha, run_id, details):
95
133
title = "`mypy`" ,
96
134
message = (
97
135
"`mypy` detected issues. Please fix them locally and push the changes. "
98
- "Here you can see the detected issues."
136
+ "Here you can see the detected issues. Note that the installed `mypy` "
137
+ f"version is `mypy={ versions ['mypy' ]} `."
99
138
),
100
139
details = details ,
101
140
)
@@ -108,7 +147,9 @@ def get_message(log_file, repo, pr_number, sha, run_id, details):
108
147
title = "`cython-lint`" ,
109
148
message = (
110
149
"`cython-lint` detected issues. Please fix them locally and push "
111
- "the changes. Here you can see the detected issues."
150
+ "the changes. Here you can see the detected issues. Note that the "
151
+ "installed `cython-lint` version is "
152
+ f"`cython-lint={ versions ['cython-lint' ]} `."
112
153
),
113
154
details = details ,
114
155
)
@@ -152,13 +193,6 @@ def get_message(log_file, repo, pr_number, sha, run_id, details):
152
193
details = details ,
153
194
)
154
195
155
- sub_text = (
156
- "\n \n <sub> _Generated for commit:"
157
- f" [{ sha [:7 ]} ](https://github.com/{ repo } /pull/{ pr_number } /commits/{ sha } ). "
158
- "Link to the linter CI: [here]"
159
- f"(https://github.com/{ repo } /actions/runs/{ run_id } )_ </sub>"
160
- )
161
-
162
196
if not message :
163
197
# no issues detected, so this script "fails"
164
198
return (
@@ -215,10 +249,8 @@ def find_lint_bot_comments(repo, token, pr_number):
215
249
response .raise_for_status ()
216
250
all_comments = response .json ()
217
251
218
- failed_comment = "This PR is introducing linting issues. Here's a summary of the"
219
- success_comment = (
220
- "All linting checks passed. Your pull request is in excellent shape"
221
- )
252
+ failed_comment = "❌ Linting issues"
253
+ success_comment = "✔️ Linting Passed"
222
254
223
255
# Find all comments that match the linting bot, and return the first one.
224
256
# There should always be only one such comment, or none, if the PR is
@@ -269,6 +301,9 @@ def create_or_update_comment(comment, message, repo, pr_number, token):
269
301
sha = os .environ ["BRANCH_SHA" ]
270
302
log_file = os .environ ["LOG_FILE" ]
271
303
run_id = os .environ ["RUN_ID" ]
304
+ versions_file = os .environ ["VERSIONS_FILE" ]
305
+
306
+ versions = get_versions (versions_file )
272
307
273
308
if not repo or not token or not pr_number or not log_file or not run_id :
274
309
raise ValueError (
@@ -290,6 +325,7 @@ def create_or_update_comment(comment, message, repo, pr_number, token):
290
325
sha = sha ,
291
326
run_id = run_id ,
292
327
details = True ,
328
+ versions = versions ,
293
329
)
294
330
create_or_update_comment (
295
331
comment = comment ,
@@ -309,6 +345,7 @@ def create_or_update_comment(comment, message, repo, pr_number, token):
309
345
sha = sha ,
310
346
run_id = run_id ,
311
347
details = False ,
348
+ versions = versions ,
312
349
)
313
350
create_or_update_comment (
314
351
comment = comment ,
0 commit comments