Add links to ecosystem check result (#5631)

## Summary

Add links for ecosystem check result. This is useful for developers to
quickly check the added/removed violations with a single click.

There are a few downsides of this approach:
* Syntax highlighting is not available for the output
* Content length is increased because of the additional anchor tags

## Test Plan

`python scripts/check_ecosystem.py ./target/debug/ruff ../ruff-test/target/debug/ruff`

<details><summary>Example Output:</summary>

ℹ️ ecosystem check **detected changes**. (+6, -0, 0 error(s))

<details><summary>airflow (+1, -0)</summary>
<p>

<pre>
+ <a
href='https://github.com/apache/airflow/blob/main/dev/breeze/src/airflow_breeze/commands/release_management_commands.py#L654'>dev/breeze/src/airflow_breeze/commands/release_management_commands.py:654:25:</a>
PERF401 Use a list comprehension to create a transformed list
</pre>

</p>
</details>
<details><summary>bokeh (+3, -0)</summary>
<p>

<pre>
+ <a
href='https://github.com/bokeh/bokeh/blob/branch-3.2/src/bokeh/model/model.py#L315'>src/bokeh/model/model.py:315:17:</a>
PERF401 Use a list comprehension to create a transformed list
+ <a
href='https://github.com/bokeh/bokeh/blob/branch-3.2/src/bokeh/resources.py#L470'>src/bokeh/resources.py:470:25:</a>
PERF401 Use a list comprehension to create a transformed list
+ <a
href='https://github.com/bokeh/bokeh/blob/branch-3.2/src/bokeh/sphinxext/bokeh_sampledata_xref.py#L134'>src/bokeh/sphinxext/bokeh_sampledata_xref.py:134:17:</a>
PERF401 Use a list comprehension to create a transformed list
</pre>

</p>
</details>
<details><summary>zulip (+2, -0)</summary>
<p>

<pre>
+ <a
href='https://github.com/zulip/zulip/blob/main/zerver/actions/create_user.py#L197'>zerver/actions/create_user.py:197:17:</a>
PERF401 Use a list comprehension to create a transformed list
+ <a
href='https://github.com/zulip/zulip/blob/main/zerver/lib/markdown/__init__.py#L2412'>zerver/lib/markdown/__init__.py:2412:13:</a>
PERF401 Use a list comprehension to create a transformed list
</pre>

</p>
</details>

</details>

---------

Co-authored-by: konsti <konstin@mailbox.org>
This commit is contained in:
Dhruv Manilawala 2023-07-10 09:25:26 +05:30 committed by GitHub
parent c9d7c0d7d5
commit 52b22ceb6e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -82,6 +82,17 @@ class Repository(NamedTuple):
yield Path(checkout_dir)
def url_for(self: Self, path: str, lnum: int | None = None) -> str:
"""Return the GitHub URL for the given path and line number, if given."""
# Default to main branch
url = (
f"https://github.com/{self.org}/{self.repo}"
f"/blob/{self.ref or 'main'}/{path}"
)
if lnum:
url += f"#L{lnum}"
return url
REPOSITORIES: list[Repository] = [
Repository("apache", "airflow", "main", select="ALL"),
@ -272,6 +283,11 @@ def read_projects_jsonl(projects_jsonl: Path) -> dict[tuple[str, str], Repositor
return repositories
DIFF_LINE_RE = re.compile(
r"^(?P<pre>[+-]) (?P<inner>(?P<path>[^:]+):(?P<lnum>\d+):\d+:) (?P<post>.*)$",
)
T = TypeVar("T")
@ -352,18 +368,27 @@ async def main(
print("<p>")
print()
diff_str = "\n".join(diff)
repo = repositories[(org, repo)]
diff_lines = list(diff)
print("```diff")
print(diff_str)
print("```")
print("<pre>")
for line in diff_lines:
match = DIFF_LINE_RE.match(line)
if match is None:
print(line)
continue
pre, inner, path, lnum, post = match.groups()
url = repo.url_for(path, int(lnum))
print(f"{pre} <a href='{url}'>{inner}</a> {post}")
print("</pre>")
print()
print("</p>")
print("</details>")
# Count rule changes
for line in diff_str.splitlines():
for line in diff_lines:
# Find rule change for current line or construction
# + <rule>/<path>:<line>:<column>: <rule_code> <message>
matches = re.search(r": ([A-Z]{1,4}[0-9]{3,4})", line)