tarekziade HF Staff commited on
Commit
bd0f095
·
verified ·
1 Parent(s): 1d04345

Publish unified PR diff prototype with complete review threads and filters

Browse files
Files changed (8) hide show
  1. Dockerfile +7 -0
  2. LICENSE +203 -0
  3. README.md +23 -5
  4. app.py +62 -0
  5. data/comments.json.gz +3 -0
  6. data/pr.diff +0 -0
  7. patch_view.html +218 -0
  8. patch_view.js +160 -0
Dockerfile ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ FROM python:3.12-slim
2
+ RUN useradd --create-home --uid 1000 space
3
+ WORKDIR /app
4
+ COPY --chown=space:space . /app
5
+ USER space
6
+ EXPOSE 7860
7
+ CMD ["python", "-u", "app.py"]
LICENSE ADDED
@@ -0,0 +1,203 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Copyright 2018- The Hugging Face team. All rights reserved.
2
+
3
+ Apache License
4
+ Version 2.0, January 2004
5
+ http://www.apache.org/licenses/
6
+
7
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
+
9
+ 1. Definitions.
10
+
11
+ "License" shall mean the terms and conditions for use, reproduction,
12
+ and distribution as defined by Sections 1 through 9 of this document.
13
+
14
+ "Licensor" shall mean the copyright owner or entity authorized by
15
+ the copyright owner that is granting the License.
16
+
17
+ "Legal Entity" shall mean the union of the acting entity and all
18
+ other entities that control, are controlled by, or are under common
19
+ control with that entity. For the purposes of this definition,
20
+ "control" means (i) the power, direct or indirect, to cause the
21
+ direction or management of such entity, whether by contract or
22
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
23
+ outstanding shares, or (iii) beneficial ownership of such entity.
24
+
25
+ "You" (or "Your") shall mean an individual or Legal Entity
26
+ exercising permissions granted by this License.
27
+
28
+ "Source" form shall mean the preferred form for making modifications,
29
+ including but not limited to software source code, documentation
30
+ source, and configuration files.
31
+
32
+ "Object" form shall mean any form resulting from mechanical
33
+ transformation or translation of a Source form, including but
34
+ not limited to compiled object code, generated documentation,
35
+ and conversions to other media types.
36
+
37
+ "Work" shall mean the work of authorship, whether in Source or
38
+ Object form, made available under the License, as indicated by a
39
+ copyright notice that is included in or attached to the work
40
+ (an example is provided in the Appendix below).
41
+
42
+ "Derivative Works" shall mean any work, whether in Source or Object
43
+ form, that is based on (or derived from) the Work and for which the
44
+ editorial revisions, annotations, elaborations, or other modifications
45
+ represent, as a whole, an original work of authorship. For the purposes
46
+ of this License, Derivative Works shall not include works that remain
47
+ separable from, or merely link (or bind by name) to the interfaces of,
48
+ the Work and Derivative Works thereof.
49
+
50
+ "Contribution" shall mean any work of authorship, including
51
+ the original version of the Work and any modifications or additions
52
+ to that Work or Derivative Works thereof, that is intentionally
53
+ submitted to Licensor for inclusion in the Work by the copyright owner
54
+ or by an individual or Legal Entity authorized to submit on behalf of
55
+ the copyright owner. For the purposes of this definition, "submitted"
56
+ means any form of electronic, verbal, or written communication sent
57
+ to the Licensor or its representatives, including but not limited to
58
+ communication on electronic mailing lists, source code control systems,
59
+ and issue tracking systems that are managed by, or on behalf of, the
60
+ Licensor for the purpose of discussing and improving the Work, but
61
+ excluding communication that is conspicuously marked or otherwise
62
+ designated in writing by the copyright owner as "Not a Contribution."
63
+
64
+ "Contributor" shall mean Licensor and any individual or Legal Entity
65
+ on behalf of whom a Contribution has been received by Licensor and
66
+ subsequently incorporated within the Work.
67
+
68
+ 2. Grant of Copyright License. Subject to the terms and conditions of
69
+ this License, each Contributor hereby grants to You a perpetual,
70
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
71
+ copyright license to reproduce, prepare Derivative Works of,
72
+ publicly display, publicly perform, sublicense, and distribute the
73
+ Work and such Derivative Works in Source or Object form.
74
+
75
+ 3. Grant of Patent License. Subject to the terms and conditions of
76
+ this License, each Contributor hereby grants to You a perpetual,
77
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
78
+ (except as stated in this section) patent license to make, have made,
79
+ use, offer to sell, sell, import, and otherwise transfer the Work,
80
+ where such license applies only to those patent claims licensable
81
+ by such Contributor that are necessarily infringed by their
82
+ Contribution(s) alone or by combination of their Contribution(s)
83
+ with the Work to which such Contribution(s) was submitted. If You
84
+ institute patent litigation against any entity (including a
85
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
86
+ or a Contribution incorporated within the Work constitutes direct
87
+ or contributory patent infringement, then any patent licenses
88
+ granted to You under this License for that Work shall terminate
89
+ as of the date such litigation is filed.
90
+
91
+ 4. Redistribution. You may reproduce and distribute copies of the
92
+ Work or Derivative Works thereof in any medium, with or without
93
+ modifications, and in Source or Object form, provided that You
94
+ meet the following conditions:
95
+
96
+ (a) You must give any other recipients of the Work or
97
+ Derivative Works a copy of this License; and
98
+
99
+ (b) You must cause any modified files to carry prominent notices
100
+ stating that You changed the files; and
101
+
102
+ (c) You must retain, in the Source form of any Derivative Works
103
+ that You distribute, all copyright, patent, trademark, and
104
+ attribution notices from the Source form of the Work,
105
+ excluding those notices that do not pertain to any part of
106
+ the Derivative Works; and
107
+
108
+ (d) If the Work includes a "NOTICE" text file as part of its
109
+ distribution, then any Derivative Works that You distribute must
110
+ include a readable copy of the attribution notices contained
111
+ within such NOTICE file, excluding those notices that do not
112
+ pertain to any part of the Derivative Works, in at least one
113
+ of the following places: within a NOTICE text file distributed
114
+ as part of the Derivative Works; within the Source form or
115
+ documentation, if provided along with the Derivative Works; or,
116
+ within a display generated by the Derivative Works, if and
117
+ wherever such third-party notices normally appear. The contents
118
+ of the NOTICE file are for informational purposes only and
119
+ do not modify the License. You may add Your own attribution
120
+ notices within Derivative Works that You distribute, alongside
121
+ or as an addendum to the NOTICE text from the Work, provided
122
+ that such additional attribution notices cannot be construed
123
+ as modifying the License.
124
+
125
+ You may add Your own copyright statement to Your modifications and
126
+ may provide additional or different license terms and conditions
127
+ for use, reproduction, or distribution of Your modifications, or
128
+ for any such Derivative Works as a whole, provided Your use,
129
+ reproduction, and distribution of the Work otherwise complies with
130
+ the conditions stated in this License.
131
+
132
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
133
+ any Contribution intentionally submitted for inclusion in the Work
134
+ by You to the Licensor shall be under the terms and conditions of
135
+ this License, without any additional terms or conditions.
136
+ Notwithstanding the above, nothing herein shall supersede or modify
137
+ the terms of any separate license agreement you may have executed
138
+ with Licensor regarding such Contributions.
139
+
140
+ 6. Trademarks. This License does not grant permission to use the trade
141
+ names, trademarks, service marks, or product names of the Licensor,
142
+ except as required for reasonable and customary use in describing the
143
+ origin of the Work and reproducing the content of the NOTICE file.
144
+
145
+ 7. Disclaimer of Warranty. Unless required by applicable law or
146
+ agreed to in writing, Licensor provides the Work (and each
147
+ Contributor provides its Contributions) on an "AS IS" BASIS,
148
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
149
+ implied, including, without limitation, any warranties or conditions
150
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
151
+ PARTICULAR PURPOSE. You are solely responsible for determining the
152
+ appropriateness of using or redistributing the Work and assume any
153
+ risks associated with Your exercise of permissions under this License.
154
+
155
+ 8. Limitation of Liability. In no event and under no legal theory,
156
+ whether in tort (including negligence), contract, or otherwise,
157
+ unless required by applicable law (such as deliberate and grossly
158
+ negligent acts) or agreed to in writing, shall any Contributor be
159
+ liable to You for damages, including any direct, indirect, special,
160
+ incidental, or consequential damages of any character arising as a
161
+ result of this License or out of the use or inability to use the
162
+ Work (including but not limited to damages for loss of goodwill,
163
+ work stoppage, computer failure or malfunction, or any and all
164
+ other commercial damages or losses), even if such Contributor
165
+ has been advised of the possibility of such damages.
166
+
167
+ 9. Accepting Warranty or Additional Liability. While redistributing
168
+ the Work or Derivative Works thereof, You may choose to offer,
169
+ and charge a fee for, acceptance of support, warranty, indemnity,
170
+ or other liability obligations and/or rights consistent with this
171
+ License. However, in accepting such obligations, You may act only
172
+ on Your own behalf and on Your sole responsibility, not on behalf
173
+ of any other Contributor, and only if You agree to indemnify,
174
+ defend, and hold each Contributor harmless for any liability
175
+ incurred by, or claims asserted against, such Contributor by reason
176
+ of your accepting any such warranty or additional liability.
177
+
178
+ END OF TERMS AND CONDITIONS
179
+
180
+ APPENDIX: How to apply the Apache License to your work.
181
+
182
+ To apply the Apache License to your work, attach the following
183
+ boilerplate notice, with the fields enclosed by brackets "[]"
184
+ replaced with your own identifying information. (Don't include
185
+ the brackets!) The text should be enclosed in the appropriate
186
+ comment syntax for the file format. We also recommend that a
187
+ file or class name and description of purpose be included on the
188
+ same "printed page" as the copyright notice for easier
189
+ identification within third-party archives.
190
+
191
+ Copyright [yyyy] [name of copyright owner]
192
+
193
+ Licensed under the Apache License, Version 2.0 (the "License");
194
+ you may not use this file except in compliance with the License.
195
+ You may obtain a copy of the License at
196
+
197
+ http://www.apache.org/licenses/LICENSE-2.0
198
+
199
+ Unless required by applicable law or agreed to in writing, software
200
+ distributed under the License is distributed on an "AS IS" BASIS,
201
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
202
+ See the License for the specific language governing permissions and
203
+ limitations under the License.
README.md CHANGED
@@ -1,10 +1,28 @@
1
  ---
2
- title: Transformers Pr Diff Prototype
3
- emoji: 😻
4
- colorFrom: gray
5
- colorTo: purple
6
  sdk: docker
 
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: Transformers PR Diff Prototype
3
+ emoji: 🔍
4
+ colorFrom: blue
5
+ colorTo: green
6
  sdk: docker
7
+ app_port: 7860
8
  pinned: false
9
+ license: apache-2.0
10
+ short_description: Explore a Transformers PR diff and its review threads
11
  ---
12
 
13
+ Interactive prototype of the unified diff panel for the Transformers CI dashboard.
14
+
15
+ This demo includes a saved public snapshot of
16
+ [huggingface/transformers PR #43451 — Add Molmo2](https://github.com/huggingface/transformers/pull/43451),
17
+ with 23 changed files and all 730 inline review comments and replies. The snapshot
18
+ was downloaded on October 10, 2026; it does not refresh from GitHub.
19
+
20
+ Use the file and comment filters to explore the changes. Reviews open by default;
21
+ select **Inline** for code review threads. **Show the line(s)** highlights the code,
22
+ including saved context for comments on an earlier revision.
23
+
24
+ The server uses only Python's standard library and runs on the free CPU tier.
25
+ It has no GitHub credentials or access to the production dashboard.
26
+
27
+ The diff contains source code from Hugging Face Transformers, licensed under
28
+ Apache 2.0. Comments retain their authors and public GitHub attribution.
app.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Standalone server for the PR diff prototype and its public GitHub snapshot."""
2
+
3
+ from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
4
+ from pathlib import Path
5
+ from urllib.parse import parse_qs, urlparse
6
+ import os
7
+
8
+ ROOT = Path(__file__).resolve().parent
9
+ ASSETS = {
10
+ "/": ("patch_view.html", "text/html; charset=utf-8", None),
11
+ "/patch-view": ("patch_view.html", "text/html; charset=utf-8", None),
12
+ "/patch-view/script.js": ("patch_view.js", "text/javascript; charset=utf-8", None),
13
+ "/patch-view/data": ("data/pr.diff", "text/plain; charset=utf-8", None),
14
+ "/patch-view/comments": (
15
+ "data/comments.json.gz",
16
+ "application/json; charset=utf-8",
17
+ "gzip",
18
+ ),
19
+ }
20
+
21
+
22
+ class Handler(BaseHTTPRequestHandler):
23
+ def do_GET(self): # noqa: N802
24
+ parsed = urlparse(self.path)
25
+ if parsed.path == "/health":
26
+ self.reply(200, "text/plain", b"ok")
27
+ return
28
+ asset = ASSETS.get(parsed.path)
29
+ if asset is None:
30
+ self.reply(404, "text/plain", b"Not found")
31
+ return
32
+ if parsed.path in {"/patch-view/data", "/patch-view/comments"}:
33
+ params = parse_qs(parsed.query)
34
+ if (
35
+ params.get("pr", ["43451"])[0] != "43451"
36
+ or params.get("repository", ["huggingface/transformers"])[0]
37
+ != "huggingface/transformers"
38
+ ):
39
+ self.reply(
40
+ 400,
41
+ "text/plain",
42
+ b"This prototype contains the saved huggingface/transformers PR #43451 snapshot.",
43
+ )
44
+ return
45
+ name, content_type, encoding = asset
46
+ self.reply(200, content_type, (ROOT / name).read_bytes(), encoding)
47
+
48
+ def reply(self, status, content_type, body, encoding=None):
49
+ self.send_response(status)
50
+ self.send_header("Content-Type", content_type)
51
+ self.send_header("Content-Length", str(len(body)))
52
+ self.send_header("Cache-Control", "no-cache")
53
+ if encoding:
54
+ self.send_header("Content-Encoding", encoding)
55
+ self.end_headers()
56
+ self.wfile.write(body)
57
+
58
+
59
+ if __name__ == "__main__":
60
+ port = int(os.environ.get("PORT", "7860"))
61
+ print(f"Serving prototype on :{port}", flush=True)
62
+ ThreadingHTTPServer(("0.0.0.0", port), Handler).serve_forever()
data/comments.json.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0223ca12949420bf42296e7390e812a09cfc9a87e2d2c239ad54bf83a50aab1b
3
+ size 3460009
data/pr.diff ADDED
The diff for this file is too large to render. See raw diff
 
patch_view.html ADDED
@@ -0,0 +1,218 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!doctype html>
2
+ <html lang="en"><head><meta charset="utf-8">
3
+ <meta name="viewport" content="width=device-width, initial-scale=1">
4
+ <title>PR diff</title>
5
+ <style>
6
+ :root{color-scheme:dark;--bg:#111217;--card:#181b1f;--fg:#d8d9da;--muted:#9fa3a9;--border:#34363c;--add:#173326;--del:#3d2227;--hunk:#192c42;--link:#8ab8ff}
7
+ :root.light{color-scheme:light;--bg:#fff;--card:#f6f8fa;--fg:#24292f;--muted:#6e7781;--border:#d0d7de;--add:#e6ffec;--del:#ffebe9;--hunk:#ddf4ff;--link:#0969da}
8
+ *{box-sizing:border-box}body{margin:0;padding:12px;background:var(--bg);color:var(--fg);font:13px/1.5 Inter,system-ui,sans-serif}
9
+ .back-to-top{position:fixed;bottom:16px;left:16px;z-index:10;box-shadow:0 2px 8px #0004}body{padding-bottom:64px}
10
+ a{color:var(--link);text-decoration:none}a:hover{text-decoration:underline}
11
+ header{display:flex;gap:12px;align-items:center;flex-wrap:wrap}#source{font-weight:600}button{font:inherit;background:var(--card);color:var(--fg);border:1px solid var(--border);border-radius:4px;padding:4px 10px;cursor:pointer}button:disabled{opacity:.5;cursor:wait}#message{color:var(--muted);padding:14px 0}#message.error{color:#f2495c}
12
+ .patch-toolbar{display:flex;justify-content:space-between;align-items:center;gap:12px;margin:12px 0;flex-wrap:wrap;color:var(--muted)}
13
+ .patch-file{border:1px solid var(--border);border-radius:4px;margin-bottom:12px;overflow:hidden}
14
+ .patch-file-header{padding:8px 12px;background:var(--card);cursor:pointer;font:12px/1.5 ui-monospace,SFMono-Regular,Menlo,monospace;overflow-wrap:anywhere}
15
+ .patch-counts{float:right;margin-left:16px;color:var(--muted)}.patch-scroll{overflow-x:auto}
16
+ .patch-table{border-collapse:collapse;width:100%;font:12px/21px ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}
17
+ .patch-number{min-width:48px;width:48px;text-align:right;padding:0 10px;color:var(--muted);border-right:1px solid var(--border);user-select:none}
18
+ .patch-code{padding:0 12px;white-space:pre;tab-size:4}.patch-line.add{background:var(--add)}.patch-line.del{background:var(--del)}.patch-line.hunk{background:var(--hunk);color:var(--link)}.patch-line.meta{color:var(--muted);background:var(--card)}
19
+ .patch-raw summary{cursor:pointer;color:var(--muted)}.patch-raw pre{overflow:auto;font-size:12px}
20
+ .file-filters{display:flex;gap:16px;flex-wrap:wrap;margin-top:12px;color:var(--muted);font-size:12px}.filter-check{display:inline-flex;align-items:center;gap:6px;cursor:pointer}.filter-check input{accent-color:var(--link)}.bot-filter{font-size:11px;color:var(--muted);margin-top:10px}
21
+ .patch-line.line-highlight{outline:1px solid #ffb357;outline-offset:-1px;background:#6b4b2040}.comment-context{margin:12px;border:1px solid var(--link);padding:10px;border-radius:4px}.comment-context p{margin-top:0;color:var(--link);overflow-wrap:anywhere}.comment-navigation-status{font-size:11px;color:var(--muted);margin-top:6px}
22
+ .layout{display:grid;grid-template-columns:minmax(0,1fr) 340px;gap:16px;align-items:start;margin-top:12px}.diff-column{min-width:0}
23
+ .comments-sidebar{position:sticky;top:12px;border:1px solid var(--border);border-radius:5px;background:var(--card);max-height:calc(100vh - 24px);display:flex;flex-direction:column;min-height:180px}
24
+ .comments-heading{padding:12px;border-bottom:1px solid var(--border)}.comments-heading h2{font-size:14px;margin:0 0 10px}.comment-filters{display:flex;gap:6px;flex-wrap:wrap}.comment-filters button{font-size:11px;padding:3px 8px}.comment-filters button[aria-pressed=true]{border-color:var(--link);color:var(--link);background:var(--hunk)}
25
+ #comments-list{overflow-y:auto;padding:12px;min-height:0}.comments-status{color:var(--muted);padding:12px}.comments-status.error{color:#f2495c}
26
+ .comment-card{border:1px solid var(--border);border-radius:4px;padding:10px;margin-bottom:10px;background:var(--bg)}.comment-card:last-child{margin-bottom:0}
27
+ .comment-card.review-approved{background:var(--add);border-color:#3d8656}.comment-card.review-changes-requested{background:var(--del);border-color:#b7656e}
28
+ .comment-thread{border:1px solid var(--border);border-radius:4px;margin-bottom:12px;background:var(--bg)}.comment-thread>summary{padding:9px 10px;font-weight:600;font-size:12px;cursor:pointer;background:var(--card)}.comment-thread .comment-card{border:0;border-top:1px solid var(--border);border-radius:0;margin:0}.comment-thread .comment-reply{border-left:2px solid var(--border);margin-left:10px}.thread-filter-note{font-size:10px;color:var(--muted);margin:8px 0 0}.comment-context-label{font-size:10px;color:var(--muted);margin-top:4px}
29
+ .comment-meta{display:flex;align-items:baseline;gap:8px;justify-content:space-between;flex-wrap:wrap}.comment-author{font-weight:600}.comment-time{font-size:10px;color:var(--muted)}.comment-kind{font-size:10px;color:var(--muted);margin-top:4px}.comment-location{font:11px/1.5 ui-monospace,SFMono-Regular,Menlo,monospace;overflow-wrap:anywhere;margin:8px 0;color:var(--link)}.comment-body{white-space:pre-wrap;overflow-wrap:anywhere;font-size:12px;margin:8px 0;max-height:300px;overflow:auto}.comment-link{font-size:11px}
30
+ @media(max-width:850px){.layout{grid-template-columns:minmax(0,1fr)}.comments-sidebar{position:static;max-height:600px}}
31
+ </style></head><body>
32
+ <header><a id="source" target="_blank" rel="noopener"></a><button id="reload">Refresh</button><button id="collapse">Collapse all</button></header>
33
+ <div class="file-filters" role="group" aria-label="Filter changed files">
34
+ <label class="filter-check"><input type="checkbox" id="hide-tests" checked>Hide test changes</label>
35
+ <label class="filter-check"><input type="checkbox" id="only-python" checked>Only .py changes</label>
36
+ <label class="filter-check"><input type="checkbox" id="only-models" checked>Only model changes</label>
37
+ <label class="filter-check"><input type="checkbox" id="hide-generated" checked>Hide generated files</label>
38
+ <label class="filter-check"><input type="checkbox" id="hide-comment-lines" checked>Hide comment lines</label>
39
+ <label class="filter-check"><input type="checkbox" id="hide-module-headers" checked>Hide module headers</label>
40
+ </div>
41
+ <main class="layout">
42
+ <section class="diff-column" aria-label="Unified diff"><div id="message" role="status">Loading diff…</div><div id="patch-view"></div></section>
43
+ <aside class="comments-sidebar" aria-label="PR comments">
44
+ <div class="comments-heading"><h2>Comments <span id="comment-count"></span></h2>
45
+ <div class="comment-filters" role="group" aria-label="Filter comments">
46
+ <button data-filter="all" aria-pressed="false">All</button><button data-filter="discussion" aria-pressed="false">Discussion</button><button data-filter="review" aria-pressed="true">Reviews</button><button data-filter="inline" aria-pressed="false">Inline</button>
47
+ </div>
48
+ <label class="filter-check bot-filter"><input type="checkbox" id="hide-bots" checked>Hide bot comments</label>
49
+ <label class="filter-check bot-filter"><input type="checkbox" id="hide-resolved" checked disabled>Hide resolved</label>
50
+ <label class="filter-check bot-filter"><input type="checkbox" id="hide-commands" checked>Hide command comments</label>
51
+ <label class="filter-check bot-filter"><input type="checkbox" id="maintainers-only">Maintainers only</label>
52
+ <p class="thread-filter-note">Filters select threads. Replies stay visible for context.</p>
53
+ </div>
54
+ <div id="comments-status" class="comments-status" role="status">Loading comments…</div><div id="comments-list"></div>
55
+ </aside>
56
+ </main>
57
+ <button id="back-to-top" class="back-to-top" aria-label="Back to top">↑ Back to top</button>
58
+ <script src="/patch-view/script.js"></script>
59
+ <script>
60
+ (() => {
61
+ document.getElementById('back-to-top').onclick = () => {
62
+ window.scrollTo({top:0, behavior:window.matchMedia('(prefers-reduced-motion: reduce)').matches ? 'instant' : 'smooth'});
63
+ };
64
+ const params = new URLSearchParams(location.search);
65
+ const pr = params.get('pr') || '43451', repository = params.get('repository') || 'huggingface/transformers';
66
+ try {
67
+ if (params.get('theme') === 'light' || (parent.grafanaBootData && parent.grafanaBootData.user.lightTheme)) document.documentElement.classList.add('light');
68
+ } catch (_) {}
69
+ const source = document.getElementById('source'), message = document.getElementById('message'), reload = document.getElementById('reload');
70
+ let currentPatch = '';
71
+ const hideTests = document.getElementById('hide-tests'), onlyPython = document.getElementById('only-python'), hideBots = document.getElementById('hide-bots'), onlyModels = document.getElementById('only-models'), hideResolved = document.getElementById('hide-resolved'), hideGenerated = document.getElementById('hide-generated'), hideCommands = document.getElementById('hide-commands'), maintainersOnly = document.getElementById('maintainers-only'), hideCommentLines = document.getElementById('hide-comment-lines'), hideModuleHeaders = document.getElementById('hide-module-headers');
72
+ function renderDiff() {
73
+ if (!currentPatch) return;
74
+ TCIPatch.render(document.getElementById('patch-view'), currentPatch, {hideTests:hideTests.checked, onlyPython:onlyPython.checked, onlyModels:onlyModels.checked, hideGenerated:hideGenerated.checked, hideComments:hideCommentLines.checked, hideModuleHeaders:hideModuleHeaders.checked});
75
+ document.getElementById('collapse').textContent = 'Collapse all';
76
+ }
77
+ hideTests.onchange = renderDiff; onlyPython.onchange = renderDiff; onlyModels.onchange = renderDiff; hideGenerated.onchange = renderDiff; hideCommentLines.onchange = renderDiff; hideModuleHeaders.onchange = renderDiff;
78
+ source.textContent = repository + ' · PR #' + pr;
79
+ if (/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/.test(repository) && /^[1-9][0-9]*$/.test(pr)) source.href = 'https://github.com/' + repository + '/pull/' + pr + '/files';
80
+ async function loadDiff() {
81
+ currentPatch = '';
82
+ message.hidden = false; message.className = ''; message.textContent = 'Loading diff…';
83
+ document.getElementById('patch-view').replaceChildren();
84
+ try {
85
+ const r = await fetch('/patch-view/data?' + new URLSearchParams({pr, repository}), {cache:'no-store'});
86
+ const text = await r.text();
87
+ if (!r.ok) throw Error(text);
88
+ if (!text.trim()) { message.textContent = 'This PR has no changes.'; return; }
89
+ currentPatch = text; renderDiff();
90
+ message.hidden = true;
91
+ document.getElementById('collapse').textContent = 'Collapse all';
92
+ } catch (e) { message.className = 'error'; message.textContent = e.message; }
93
+ }
94
+ let comments = [], filter = 'review';
95
+ const commentStatus = document.getElementById('comments-status'), commentList = document.getElementById('comments-list');
96
+ function node(tag, cls, text) {
97
+ const el = document.createElement(tag); el.className = cls; el.textContent = text; return el;
98
+ }
99
+ function isMaintainer(comment) {
100
+ return comment.is_maintainer === true || ['OWNER', 'MEMBER', 'COLLABORATOR'].includes(comment.author_association);
101
+ }
102
+ function matchesComment(c) {
103
+ const body = (c.body || '').trimStart().toLowerCase();
104
+ const author = (c.author || '').toLowerCase();
105
+ const bot = c.is_bot || author.endsWith('[bot]') || author === 'huggingfacedocbuilderdev';
106
+ return (filter === 'all' || c.kind === filter) && (!hideBots.checked || !bot) && (!hideResolved.checked || c.resolved !== true) && (!hideCommands.checked || !(body.startsWith('run-slow:') || body.startsWith('@askserge'))) && (!maintainersOnly.checked || isMaintainer(c));
107
+ }
108
+ function groupComments() {
109
+ const byId = new Map(comments.filter(c => c.kind === 'inline').map(c => [c.id, c]));
110
+ const groups = new Map();
111
+ for (const c of comments) {
112
+ let root = c;
113
+ const seen = new Set();
114
+ while (root.kind === 'inline' && byId.has(root.reply_to) && !seen.has(root.id)) {
115
+ seen.add(root.id); root = byId.get(root.reply_to);
116
+ }
117
+ const key = c.kind === 'inline' ? 'inline:' + (c.thread_id || root.thread_id || root.reply_to || root.id) : c.kind + ':' + c.id;
118
+ if (!groups.has(key)) groups.set(key, []);
119
+ groups.get(key).push(c);
120
+ }
121
+ const ascending = (a, b) => (a.created_at || '').localeCompare(b.created_at || '') || a.id - b.id;
122
+ return [...groups.values()].map(group => group.sort(ascending)).sort((a, b) => ascending(b[b.length-1], a[a.length-1]));
123
+ }
124
+ function renderComments() {
125
+ commentList.replaceChildren();
126
+ const visible = groupComments().filter(group => group.some(matchesComment));
127
+ const count = visible.reduce((n, group) => n + group.length, 0);
128
+ document.getElementById('comment-count').textContent = '(' + count + (count !== comments.length ? '/' + comments.length : '') + ')';
129
+ if (!visible.length) commentList.append(node('p', 'comments-status', comments.length ? 'No comments match these filters.' : 'No comments yet.'));
130
+ for (const group of visible) {
131
+ if (group.length === 1) { commentList.append(buildCommentCard(group[0])); continue; }
132
+ const thread = node('details', 'comment-thread', ''); thread.open = true;
133
+ thread.dataset.threadId = group[0].thread_id || group[0].id;
134
+ thread.append(node('summary', '', 'Thread · ' + group.length + ' comments'));
135
+ group.forEach((c, i) => thread.append(buildCommentCard(c, {reply:i > 0, context:!matchesComment(c)})));
136
+ commentList.append(thread);
137
+ }
138
+ }
139
+ function buildCommentCard(c, options = {}) {
140
+ const card = node('article', 'comment-card', '');
141
+ if (c.kind === 'review' && c.state === 'APPROVED') card.classList.add('review-approved');
142
+ if (c.kind === 'review' && c.state === 'CHANGES_REQUESTED') card.classList.add('review-changes-requested');
143
+ card.dataset.commentId = c.id;
144
+ if (options.reply) card.classList.add('comment-reply');
145
+ const meta = node('div', 'comment-meta', '');
146
+ const date = new Date(c.created_at);
147
+ const time = node('time', 'comment-time', isNaN(date) ? '' : date.toLocaleString([], {month:'short', day:'numeric', hour:'2-digit', minute:'2-digit'}));
148
+ time.dateTime = c.created_at; time.title = c.created_at;
149
+ const author = node('span', 'comment-author', c.author);
150
+ if (isMaintainer(c)) {
151
+ const crown = node('span', 'maintainer-crown', ' 👑'); crown.title = 'Maintainer · ' + (c.author_association || 'repository access').toLowerCase(); crown.setAttribute('aria-label', 'Maintainer'); author.append(crown);
152
+ }
153
+ meta.append(author, time);
154
+ card.append(meta, node('div', 'comment-kind', ({discussion:'Discussion', review:'Review', inline:'Inline comment'})[c.kind] + (c.state ? ' · ' + c.state.toLowerCase().replaceAll('_', ' ') : '') + (c.reply_to ? ' · Reply' : '')));
155
+ if (options.context) card.append(node('div', 'comment-context-label', 'Included for thread context'));
156
+ if (c.path) card.append(node('div', 'comment-location', c.path + (c.line ? ':' + (c.start_line && c.start_line !== c.line ? c.start_line + '–' : '') + c.line : '') + (c.outdated ? ' · Outdated' : '') + (c.resolved === true ? ' · Resolved' : '')));
157
+ card.append(node('div', 'comment-body', c.body));
158
+ if (c.path && c.line) {
159
+ const show = node('button', 'comment-link', 'Show the line(s)');
160
+ const status = node('div', 'comment-navigation-status', ''); status.setAttribute('role','status');
161
+ show.onclick = () => {
162
+ const container = document.getElementById('patch-view');
163
+ const exists = [...container.querySelectorAll('.patch-file')].some(file => file.dataset.path === c.path);
164
+ let adjusted = false;
165
+ if (!exists && currentPatch) {
166
+ // Reveal a comment's file when a file filter currently excludes it.
167
+ const files = TCIPatch.parse(currentPatch), file = files.find(f => f.name === c.path);
168
+ if (file) {
169
+ if (hideTests.checked && TCIPatch.isTestFile(c.path)) { hideTests.checked = false; adjusted = true; }
170
+ if (onlyPython.checked && !c.path.endsWith('.py')) { onlyPython.checked = false; adjusted = true; }
171
+ if (onlyModels.checked && (!c.path.startsWith('src/transformers/models/') || TCIPatch.isGeneratedFile(file, files))) { onlyModels.checked = false; adjusted = true; }
172
+ if (hideGenerated.checked && TCIPatch.isGeneratedFile(file, files)) { hideGenerated.checked = false; adjusted = true; }
173
+ if (adjusted) renderDiff();
174
+ }
175
+ }
176
+ status.textContent = TCIPatch.showLines(container, c) ? (adjusted ? 'File filters adjusted to show this comment.' : '') : 'These lines are not available in the saved diff context.';
177
+ };
178
+ card.append(show, status);
179
+ }
180
+ return card;
181
+ }
182
+ hideBots.onchange = renderComments;
183
+ hideResolved.onchange = renderComments;
184
+ hideCommands.onchange = renderComments;
185
+ maintainersOnly.onchange = renderComments;
186
+ async function loadComments() {
187
+ commentStatus.hidden = false; commentStatus.className = 'comments-status'; commentStatus.textContent = 'Loading comments…'; commentList.replaceChildren();
188
+ try {
189
+ const r = await fetch('/patch-view/comments?' + new URLSearchParams({pr, repository}), {cache:'no-store'});
190
+ if (!r.ok) throw Error(await r.text());
191
+ const data = await r.json(); comments = data.comments.slice().sort((a, b) => (b.created_at || '').localeCompare(a.created_at || '') || b.id - a.id);
192
+ hideResolved.disabled = !data.resolution_available;
193
+ hideResolved.title = data.resolution_available ? '' : 'GitHub review-thread status is unavailable.';
194
+ if (hideResolved.disabled) hideResolved.checked = false;
195
+ commentStatus.hidden = !data.truncated;
196
+ commentStatus.textContent = 'Showing the first 500 entries in each category. View the full conversation on GitHub.';
197
+ renderComments();
198
+ } catch(e) { comments = []; document.getElementById('comment-count').textContent = ''; commentStatus.className = 'comments-status error'; commentStatus.textContent = 'Could not load comments: ' + e.message; }
199
+ }
200
+ document.querySelectorAll('[data-filter]').forEach(button => { button.onclick = () => {
201
+ filter = button.dataset.filter;
202
+ document.querySelectorAll('[data-filter]').forEach(b => b.setAttribute('aria-pressed', String(b === button)));
203
+ renderComments();
204
+ }; });
205
+ async function load() {
206
+ reload.disabled = true;
207
+ await Promise.all([loadDiff(), loadComments()]);
208
+ reload.disabled = false;
209
+ }
210
+ reload.onclick = load;
211
+ document.getElementById('collapse').onclick = e => {
212
+ const open = e.target.textContent === 'Expand all';
213
+ document.querySelectorAll('.patch-file').forEach(file => { file.open = open; });
214
+ e.target.textContent = open ? 'Collapse all' : 'Expand all';
215
+ };
216
+ load();
217
+ })();
218
+ </script></body></html>
patch_view.js ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Shared unified diff renderer. Patch content is always inserted as text. */
2
+ (() => {
3
+ function parse(patch) {
4
+ const files = [];
5
+ let file, oldLine = null, newLine = null;
6
+ for (const line of patch.replace(/\r\n/g, "\n").replace(/\n$/, "").split("\n")) {
7
+ if (line.startsWith("diff --git ")) {
8
+ file = {name: line.slice(11), rows: [], additions: 0, deletions: 0};
9
+ files.push(file);
10
+ oldLine = newLine = null;
11
+ }
12
+ if (!file) {
13
+ file = {name: "Patch", rows: [], additions: 0, deletions: 0};
14
+ files.push(file);
15
+ }
16
+ const hunk = line.match(/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/);
17
+ let kind = "meta", old = null, next = null;
18
+ if ((line.startsWith("+++ ") || line.startsWith("--- ")) && oldLine === null) {
19
+ if (line.slice(4) !== "/dev/null") file.name = line.slice(4).replace(/^[ab]\//, "");
20
+ }
21
+ if (hunk) {
22
+ oldLine = Number(hunk[1]); newLine = Number(hunk[2]); kind = "hunk";
23
+ } else if (oldLine !== null) {
24
+ if (line.startsWith("+")) {
25
+ kind = "add"; next = newLine++; file.additions++;
26
+ } else if (line.startsWith("-")) {
27
+ kind = "del"; old = oldLine++; file.deletions++;
28
+ } else if (line.startsWith(" ")) {
29
+ kind = "context"; old = oldLine++; next = newLine++;
30
+ }
31
+ }
32
+ file.rows.push({text: line, kind, old, next});
33
+ }
34
+ return files;
35
+ }
36
+
37
+ function el(tag, cls, value) {
38
+ const node = document.createElement(tag);
39
+ node.className = cls;
40
+ if (value != null) node.textContent = value;
41
+ return node;
42
+ }
43
+
44
+ function isTestFile(path) {
45
+ return /(^|\/)(tests?|__tests__)(\/|$)|(^|\/)test_[^/]+$|(^|\/)[^/]+_test\.[^/]+$|\.(test|spec)\.[^/]+$/.test(path);
46
+ }
47
+
48
+ function isGeneratedFile(file, files) {
49
+ if (file.rows.some(row => row.kind !== 'del' && /This file was automatically generated from/.test(row.text))) return true;
50
+ const dir = file.name.slice(0, file.name.lastIndexOf('/') + 1);
51
+ return (file.name.slice(dir.length) === '__init__.py' || /^(configuration|modeling|processing|image_processing(?:_pil|_fast)?|video_processing|tokenization(?:_fast)?|feature_extraction)_/.test(file.name.slice(dir.length))) && files.some(f => f.name.startsWith(dir + 'modular_') && !f.name.slice(dir.length).includes('/'));
52
+ }
53
+
54
+ function createRow(row) {
55
+ const tr = el('tr', `patch-line ${row.kind}`);
56
+ if (row.old != null) tr.dataset.oldLine = row.old;
57
+ if (row.next != null) tr.dataset.newLine = row.next;
58
+ tr.append(el('td', 'patch-number', row.old), el('td', 'patch-number', row.next), el('td', 'patch-code', row.text));
59
+ return tr;
60
+ }
61
+
62
+ function isCommentLine(file, row) {
63
+ return file.name.endsWith('.py') && ['add', 'del', 'context'].includes(row.kind) && /^\s*#/.test(row.text.slice(1));
64
+ }
65
+
66
+ function moduleHeaderRows(file) {
67
+ const hidden = new Set();
68
+ const markdown = /\.mdx?$/.test(file.name);
69
+ if (!file.name.endsWith('.py') && !markdown) return hidden;
70
+ for (const coordinate of ['old', 'next']) {
71
+ const source = file.rows.filter(row => row[coordinate] != null);
72
+ if (!source.length || source[0][coordinate] !== 1) continue;
73
+ const header = [];
74
+ if (markdown) {
75
+ let started = false, closed = false;
76
+ for (const row of source) {
77
+ const content = row.text.slice(1).trim();
78
+ if (!started && content && !content.startsWith('<!--')) break;
79
+ header.push(row);
80
+ if (content.startsWith('<!--')) started = true;
81
+ if (started && content.includes('-->')) { closed = true; break; }
82
+ }
83
+ if (closed && header.some(row => /copyright/i.test(row.text))) header.forEach(row => hidden.add(row));
84
+ continue;
85
+ }
86
+ for (const row of source) {
87
+ const content = row.text.slice(1).trim();
88
+ if (content && !content.startsWith('#')) break;
89
+ header.push(row);
90
+ }
91
+ if (header.some(row => /copyright|licensed under|SPDX-License-Identifier|automatically generated/i.test(row.text))) header.forEach(row => hidden.add(row));
92
+ }
93
+ return hidden;
94
+ }
95
+
96
+ function render(container, patch, options = {}) {
97
+ const allFiles = parse(patch);
98
+ const files = allFiles.filter(file => (!options.hideTests || !isTestFile(file.name)) && (!options.onlyPython || file.name.endsWith('.py')) && (!options.onlyModels || file.name.startsWith('src/transformers/models/')) && (!(options.hideGenerated || options.onlyModels) || !isGeneratedFile(file, allFiles)));
99
+ const wrapper = el("div", "patch-view");
100
+ const toolbar = el("div", "patch-toolbar");
101
+ toolbar.append(el("span", "", `${files.length === allFiles.length ? files.length : files.length + ' of ' + allFiles.length} file${files.length === 1 ? "" : "s"} · +${files.reduce((n, f) => n + f.additions, 0)} −${files.reduce((n, f) => n + f.deletions, 0)}`));
102
+ const download = el("a", "secondary nav-link", "Download full patch");
103
+ const url = URL.createObjectURL(new Blob([patch], {type: "text/plain"}));
104
+ const previous = container.dataset.patchUrl;
105
+ if (previous) URL.revokeObjectURL(previous);
106
+ container.dataset.patchUrl = url;
107
+ download.href = url; download.download = "pr.diff";
108
+ toolbar.append(download);
109
+ wrapper.append(toolbar);
110
+ if (!files.length) wrapper.append(el('p', 'comments-status', 'No files match these filters.'));
111
+ for (const file of files) {
112
+ const details = el("details", "patch-file"); details.open = true;
113
+ details.dataset.path = file.name;
114
+ const summary = el("summary", "patch-file-header");
115
+ summary.append(el("span", "patch-filename", file.name), el("span", "patch-counts", `+${file.additions} −${file.deletions}`));
116
+ const scroll = el("div", "patch-scroll");
117
+ const table = el("table", "patch-table");
118
+ table.setAttribute("aria-label", `Unified diff for ${file.name}`);
119
+ const body = document.createElement("tbody");
120
+ const headerRows = options.hideModuleHeaders ? moduleHeaderRows(file) : new Set();
121
+ for (const row of file.rows) {
122
+ if (headerRows.has(row)) continue;
123
+ if (options.hideComments && isCommentLine(file, row)) continue;
124
+ body.append(createRow(row));
125
+ }
126
+ table.append(body); scroll.append(table); details.append(summary, scroll); wrapper.append(details);
127
+ }
128
+ const raw = el("details", "patch-raw");
129
+ raw.append(el("summary", "", "Raw full patch"), el("pre", "", patch));
130
+ wrapper.append(raw);
131
+ container.replaceChildren(wrapper);
132
+ }
133
+
134
+ function showLines(container, comment) {
135
+ container.querySelectorAll('.line-highlight').forEach(row => row.classList.remove('line-highlight'));
136
+ container.querySelectorAll('.comment-context').forEach(context => context.remove());
137
+ const file = [...container.querySelectorAll('.patch-file')].find(f => f.dataset.path === comment.path);
138
+ const key = comment.side === 'LEFT' ? 'oldLine' : 'newLine';
139
+ const end = Number(comment.outdated ? comment.original_line || comment.line : comment.line);
140
+ const start = Number((comment.outdated ? comment.original_start_line : comment.start_line) || end);
141
+ let rows = file && !comment.outdated ? [...file.querySelectorAll('.patch-line')].filter(row => row.dataset[key] != null && Number(row.dataset[key]) >= start && Number(row.dataset[key]) <= end) : [];
142
+ if (!rows.length && comment.diff_hunk) {
143
+ const parsed = parse(comment.diff_hunk)[0];
144
+ const coordinate = key === 'oldLine' ? 'old' : 'next';
145
+ const nearby = parsed.rows.filter(row => row.kind === 'hunk' || (row[coordinate] != null && row[coordinate] >= start - 4 && row[coordinate] <= end + 4));
146
+ const context = el('section', 'comment-context');
147
+ context.append(el('p', '', `${comment.path} · ${comment.outdated ? 'Comment context from an earlier revision' : 'Comment context'}`));
148
+ const scroll = el('div', 'patch-scroll'), table = el('table', 'patch-table'), body = document.createElement('tbody');
149
+ nearby.forEach(row => body.append(createRow(row))); table.append(body); scroll.append(table); context.append(scroll);
150
+ if (file) file.append(context); else container.prepend(context);
151
+ rows = [...context.querySelectorAll('.patch-line')].filter(row => row.dataset[key] != null && Number(row.dataset[key]) >= start && Number(row.dataset[key]) <= end);
152
+ }
153
+ if (!rows.length) return false;
154
+ if (file) file.open = true;
155
+ rows.forEach(row => row.classList.add('line-highlight'));
156
+ rows[0].tabIndex = -1; rows[0].focus({preventScroll:true}); rows[0].scrollIntoView({behavior:'smooth', block:'center', inline:'nearest'});
157
+ return true;
158
+ }
159
+ globalThis.TCIPatch = {parse, render, isTestFile, isGeneratedFile, showLines, isCommentLine, moduleHeaderRows};
160
+ })();