Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions mergify_cli/ci/cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import click

from mergify_cli import utils
Expand Down Expand Up @@ -99,7 +101,7 @@ def _process_tests_target_branch(
type=JUnitFile(),
)
@utils.run_with_asyncio
async def junit_upload( # noqa: PLR0913
async def junit_upload(
*,
api_url: str,
token: str,
Expand Down Expand Up @@ -170,7 +172,7 @@ async def junit_upload( # noqa: PLR0913
type=JUnitFile(),
)
@utils.run_with_asyncio
async def junit_process( # noqa: PLR0913
async def junit_process(
*,
api_url: str,
token: str,
Expand Down Expand Up @@ -262,7 +264,7 @@ def scopes(
type=click.Path(exists=True),
)
@utils.run_with_asyncio
async def scopes_send( # noqa: PLR0913, PLR0917
async def scopes_send(
api_url: str,
token: str,
repository: str,
Expand Down
2 changes: 2 additions & 0 deletions mergify_cli/ci/detector.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import json
import os
import pathlib
Expand Down
8 changes: 5 additions & 3 deletions mergify_cli/ci/junit_processing/cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import sys

import click
Expand All @@ -8,7 +10,7 @@
from mergify_cli.ci.junit_processing import upload


async def process_junit_files( # noqa: PLR0913
async def process_junit_files(
*,
api_url: str,
token: str,
Expand Down Expand Up @@ -98,7 +100,7 @@ async def process_junit_files( # noqa: PLR0913
quarantine_final_failure_message = (
"Unable to determine quarantined failures due to above error"
)
except Exception as exc: # noqa: BLE001
except Exception as exc:
msg = (
f"❌ An unexpected error occurred when checking quarantined tests: {exc!s}"
)
Expand All @@ -121,7 +123,7 @@ async def process_junit_files( # noqa: PLR0913
repository=repository,
spans=spans,
)
except Exception as e: # noqa: BLE001
except Exception as e:
click.echo(
click.style(f"❌ Error uploading JUnit XML reports: {e}", fg="red"),
err=True,
Expand Down
8 changes: 5 additions & 3 deletions mergify_cli/ci/junit_processing/junit.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import dataclasses
import os
import pathlib
Expand Down Expand Up @@ -45,7 +47,7 @@ async def files_to_spans(
spans.extend(
await junit_to_spans(
run_id,
pathlib.Path(filename).read_bytes(), # noqa: ASYNC240
pathlib.Path(filename).read_bytes(),
test_language=test_language,
test_framework=test_framework,
),
Expand Down Expand Up @@ -265,9 +267,9 @@ async def junit_to_spans(

spans.append(span)

testsuite_span._start_time = min_start_time # noqa: SLF001
testsuite_span._start_time = min_start_time
session_start_time = min(session_start_time, min_start_time)

session_span._start_time = session_start_time # noqa: SLF001
session_span._start_time = session_start_time

return spans
9 changes: 7 additions & 2 deletions mergify_cli/ci/junit_processing/quarantine.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
from __future__ import annotations

import dataclasses
import typing

import click
import httpx
from opentelemetry.sdk.trace import ReadableSpan
import opentelemetry.trace
import tenacity

from mergify_cli import utils


if typing.TYPE_CHECKING:
from opentelemetry.sdk.trace import ReadableSpan


@dataclasses.dataclass
class QuarantineFailedError(Exception):
message: str
Expand Down Expand Up @@ -71,7 +76,7 @@ async def check_and_update_failing_spans(
span.name in quarantined_tests_tuple.quarantined_tests_names,
)

span._attributes = dict(span.attributes) | { # noqa: SLF001
span._attributes = dict(span.attributes) | {
"cicd.test.quarantined": quarantined,
}
if (
Expand Down
9 changes: 7 additions & 2 deletions mergify_cli/ci/junit_processing/upload.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
from __future__ import annotations

import contextlib
import io
import logging
import typing

from opentelemetry.exporter.otlp.proto.http import Compression
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.trace import ReadableSpan
from opentelemetry.sdk.trace import export

from mergify_cli import console


if typing.TYPE_CHECKING:
from opentelemetry.sdk.trace import ReadableSpan


class UploadError(Exception):
pass


@contextlib.contextmanager
def capture_log(logger: logging.Logger) -> typing.Generator[io.StringIO, None, None]:
def capture_log(logger: logging.Logger) -> typing.Generator[io.StringIO]:
# Create a string stream to capture logs
log_capture_string = io.StringIO()

Expand Down
2 changes: 1 addition & 1 deletion mergify_cli/ci/scopes/changed_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ChangedFilesError(exceptions.ScopesError):


def _run(cmd: list[str]) -> str:
return subprocess.check_output(cmd, text=True, encoding="utf-8").strip()
return subprocess.check_output(cmd, text=True, encoding="utf-8").strip() # noqa: S603


def has_merge_base(base: str, head: str) -> bool:
Expand Down
2 changes: 2 additions & 0 deletions mergify_cli/ci/scopes/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from mergify_cli.ci.scopes.config.root import Config
from mergify_cli.ci.scopes.config.root import ConfigInvalidError
from mergify_cli.ci.scopes.config.scopes import FileFilters
Expand Down
4 changes: 3 additions & 1 deletion mergify_cli/ci/scopes/config/root.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pathlib
import typing

Expand All @@ -20,7 +22,7 @@ class Config(pydantic.BaseModel):
@classmethod
def from_dict(
cls,
data: dict[str, typing.Any] | typing.Any, # noqa: ANN401
data: dict[str, typing.Any] | typing.Any,
) -> typing.Self:
try:
return cls.model_validate(data)
Expand Down
3 changes: 3 additions & 0 deletions mergify_cli/ci/scopes/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
from __future__ import annotations


class ScopesError(Exception):
pass
3 changes: 2 additions & 1 deletion mergify_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
@click.pass_context
def cli(
ctx: click.Context,
*,
debug: bool,
) -> None:
ctx.obj = {"debug": debug}
Expand All @@ -53,7 +54,7 @@ def main() -> None:
# Let's try our best by forcing utf-8 and if it's impossible, just returns escaped character
if os.name == "nt" and not sys.flags.utf8_mode:
os.environ["PYTHONUTF8"] = "1"
p = subprocess.Popen(
p = subprocess.Popen( # noqa: S603
sys.argv,
env=os.environ,
stdin=sys.stdin,
Expand Down
2 changes: 2 additions & 0 deletions mergify_cli/github_types.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import typing


Expand Down
15 changes: 10 additions & 5 deletions mergify_cli/stack/changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,23 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

from __future__ import annotations

import asyncio
import dataclasses
import re
import sys
import typing

import httpx

from mergify_cli import console
from mergify_cli import github_types
from mergify_cli import utils


if typing.TYPE_CHECKING:
import httpx


CHANGEID_RE = re.compile(r"Change-Id: (I[0-9a-z]{40})")

ChangeId = typing.NewType("ChangeId", str)
Expand Down Expand Up @@ -126,6 +128,7 @@ def commit_short_sha(self) -> str:

def get_log_from_local_change(
self,
*,
dry_run: bool,
create_as_draft: bool,
) -> str:
Expand Down Expand Up @@ -184,7 +187,7 @@ def get_log_from_local_change(

@dataclasses.dataclass
class OrphanChange(Change):
def get_log_from_orphan_change(self, dry_run: bool) -> str:
def get_log_from_orphan_change(self, *, dry_run: bool) -> str:
action = "to delete" if dry_run else "deleted"
title = self.pull["title"] if self.pull else "<unknown>"
url = self.pull["html_url"] if self.pull else "<unknown>"
Expand All @@ -201,6 +204,7 @@ class Changes:

def display_plan(
changes: Changes,
*,
create_as_draft: bool,
) -> None:
for change in changes.locals:
Expand All @@ -215,7 +219,8 @@ def display_plan(
console.log(orphan.get_log_from_orphan_change(dry_run=True))


async def get_changes( # noqa: PLR0913,PLR0917
async def get_changes(
*,
base_commit_sha: str,
stack_prefix: str,
base_branch: str,
Expand Down
9 changes: 7 additions & 2 deletions mergify_cli/stack/checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,27 @@

import dataclasses
import sys
from typing import TYPE_CHECKING

from mergify_cli import console
from mergify_cli import github_types
from mergify_cli import utils
from mergify_cli.stack import changes


if TYPE_CHECKING:
from mergify_cli import github_types


@dataclasses.dataclass
class ChangeNode:
pull: github_types.PullRequest
up: ChangeNode | None = None


async def stack_checkout( # noqa: PLR0913, PLR0917
async def stack_checkout(
github_server: str,
token: str,
*,
user: str,
repo: str,
branch_prefix: str | None,
Expand Down
22 changes: 13 additions & 9 deletions mergify_cli/stack/cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import asyncio
import os
from urllib import parse
Expand Down Expand Up @@ -170,8 +172,9 @@ async def edit() -> None:
help="Only update existing pull requests, do not create new ones",
)
@utils.run_with_asyncio
async def push( # noqa: PLR0913, PLR0917
async def push(
ctx: click.Context,
*,
setup: bool,
dry_run: bool,
next_only: bool,
Expand Down Expand Up @@ -239,8 +242,9 @@ async def push( # noqa: PLR0913, PLR0917
help="Change the target branch of the stack.",
)
@utils.run_with_asyncio
async def checkout( # noqa: PLR0913, PLR0917
async def checkout(
ctx: click.Context,
*,
author: str | None,
repository: str,
branch: str,
Expand All @@ -252,13 +256,13 @@ async def checkout( # noqa: PLR0913, PLR0917
await stack_checkout_mod.stack_checkout(
ctx.obj["github_server"],
ctx.obj["token"],
user,
repo,
branch_prefix,
branch,
author,
trunk,
dry_run,
user=user,
repo=repo,
branch_prefix=branch_prefix,
branch=branch,
author=author,
trunk=trunk,
dry_run=dry_run,
)


Expand Down
2 changes: 2 additions & 0 deletions mergify_cli/stack/edit.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import os

from mergify_cli import utils
Expand Down
Loading