Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 8.0.0 #58

Merged
merged 1 commit into from
Sep 15, 2024
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
26 changes: 25 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,29 @@ Types of changes are:

## [Unreleased]

## [8.0.0] - 2024-09-15

### Breaking changes

- Configuration option `tool.delfino.plugins.delfino-core.branch_prefix` has been moved to `tool.delfino.plugins.delfino-core.vcs.branch_prefix`.
- Configuration option `tool.delfino.plugins.delfino-core.typecheck` has been moved to `tool.delfino.plugins.delfino-core.mypy`.

### Features

#### Integration with Jira issue tracker

In the `vcs`/`gh`/`glab` `pr`/`mr` `start` commands, the integration attempts to fetch issue title. The resulting branch name will be set to `<ISSUE_PREFIX>-<ISSUE_NUMBER>/<ISSUE_TITLE>` and the first commit message will be set to `<ISSUE_TITLE>`. Use the issue number in place of the title to trigger it. For example `delfino mr start 123`.

##### New configuration options under `tool.delfino.plugins.delfino-core.issue_tracking`
- `issue_prefix` - The issue prefix (including a trailing dash).
- `tracker_url` - The issue tracker URL. If not set, the integration will be disabled.
- `username_env_var` - The environment variable containing the username for the issue tracker. Defaults to `DELFINO_CORE_ISSUE_TRACKING_USERNAME`.
- `api_key_env_var` - The environment variable containing the API key for the issue tracker. Defaults to `DELFINO_CORE_ISSUE_TRACKING_API_KEY`.

##### New optional install dependencies

- `vcs` - Installs `httpx` used for fetching issue title.

## [7.5.0] - 2024-08-02

### Features
Expand Down Expand Up @@ -484,7 +507,8 @@ If `tool.delfino.plugins.delfino-core.dockerhub` exists in the `pyproject.toml`:

- Initial source code

[Unreleased]: https://github.com/radeklat/delfino-core/compare/7.5.0...HEAD
[Unreleased]: https://github.com/radeklat/delfino-core/compare/8.0.0...HEAD
[8.0.0]: https://github.com/radeklat/delfino-core/compare/7.5.0...8.0.0
[7.5.0]: https://github.com/radeklat/delfino-core/compare/7.4.6...7.5.0
[7.4.6]: https://github.com/radeklat/delfino-core/compare/7.4.5...7.4.6
[7.4.5]: https://github.com/radeklat/delfino-core/compare/7.4.4...7.4.5
Expand Down
31 changes: 27 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Using `[all]` installs all the [optional dependencies](https://setuptools.pypa.i
- `format`
- `dependencies-update`
- `pre-commit`
- `vsc`
- For groups of commands:
- `test` - for testing and coverage commands
- `lint` - for all the linting commands
Expand Down Expand Up @@ -114,21 +115,43 @@ test_commands = ["pytest", "coverage-report"]

# Do not install pre-commit if this is set to true.
disable_pre_commit = false

# Enable to manually specify the branch prefix. By default it is set to git username.
# branch_prefix = ""
```

## Commands configuration

Several commands have their own configuration as well:
Several commands have their own configuration as well.

### `mypy`

```toml
[tool.delfino.plugins.delfino-core.mypy]
# One or more directories where type hint will be required. By default they are optional.
strict_directories = []
```

### `vcs`

```toml
[tool.delfino.plugins.delfino-core.vcs]
# Enable to manually specify the branch prefix. By default it is set to git username.
# branch_prefix = ""

[tool.delfino.plugins.delfino-core.vcs.issue_tracker]
# Prefix for issue numbers, including a trailing hyphen if used. If not set, just the issue numbers will be used.
# issue_prefix = "ISSUE-"

# URL for the issue tracker. If not set, issue tracker integration will be disabled.
# Implemented trackers: Jira.
# tracker_url = "https://<SUBDOMAIN>.atlassian.net"

# Environment variable name for the issue tracking username. If not set, 'ISSUE_TRACKER_USERNAME' will be used by default.
# username_env_var = ""

# Environment variable name for the issue tracking API key. If not set, 'ISSUE_TRACKER_API_KEY' will be used by default.
# api_key_env_var = ""
```


# Usage

Run `delfino --help`.
Expand Down
124 changes: 120 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 11 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name="delfino-core"
version="7.5.0"
version="8.0.0"
authors = ["Radek Lát <radek.lat@gmail.com>"]
description="Delfino core plugin"
license = "MIT License"
Expand Down Expand Up @@ -43,6 +43,7 @@ shellingham = {version = "*", optional = true}
psutil = {version = "*", optional = true}
PyYAML = {version = "*", optional = true}
ruff = {version = ">=0.5.0", optional = true}
httpx = {version = "*", optional = true}

# https://python-poetry.org/docs/pyproject/#plugins
[tool.poetry.plugins]
Expand All @@ -67,19 +68,21 @@ psutil = "^6.0"
gitpython = "^3.1"
pyupgrade = "^3.7"
ruff = "^0.5.2"
httpx = "^0.27.2"
types-termcolor = "*"
types-toml = "*"
types-psutil = "*"
types-pyyaml = "*"

[tool.poetry.extras]
all = ["black", "isort", "pyupgrade", "pre-commit", "pytest", "coverage", "pytest-cov", "mypy", "pylint", "pycodestyle", "pydocstyle", "psutil", "gitpython", "PyYAML", "ruff"]
all = ["black", "isort", "pyupgrade", "pre-commit", "pytest", "coverage", "pytest-cov", "mypy", "pylint", "pycodestyle", "pydocstyle", "psutil", "gitpython", "PyYAML", "ruff", "httpx"]
verify = ["black", "isort", "pyupgrade", "pre-commit", "pytest", "coverage", "pytest-cov", "mypy", "pylint", "pycodestyle", "pydocstyle", "psutil", "ruff"]
format = ["black", "isort", "pyupgrade", "pre-commit"]
test = ["pytest", "coverage", "pytest-cov"]
mypy = ["mypy"]
lint = ["pylint", "pycodestyle", "pydocstyle", "psutil", "ruff"]
dependencies_update = ["gitpython"]
vcs = ["httpx"]
pre_commit = ["PyYAML"]

[tool.isort]
Expand Down Expand Up @@ -155,5 +158,9 @@ add-ignore = [
[tool.ruff]
line-length = 120

[tool.delfino.plugins.local]
#branch_prefix = ""
[tool.delfino.plugins.local.vcs]
#branch_prefix = ""

[tool.delfino.plugins.local.issue_tracking]
issue_prefix = "PCAT-"
tracker_url = "https://heurekagroup.atlassian.net"
42 changes: 42 additions & 0 deletions src/delfino_core/commands/issue_tracker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from abc import ABC, abstractmethod
from base64 import b64encode
from typing import Dict

from click import Abort

from delfino_core.config import IssueTrackingConfig

try:
import httpx
except ImportError:
pass


class _BaseIssuerTrackerClient(ABC):
def __init__(self, settings: IssueTrackingConfig):
self._settings = settings

@abstractmethod
def get_issue_title(self, issue_number: int) -> str:
"""Fetches the title of an issue using its issue number."""


class JiraClient(_BaseIssuerTrackerClient):
def _headers(self) -> Dict[str, str]:
token = b64encode(f"{self._settings.username}:{self._settings.api_key}".encode()).decode()
return {
"Accept": "application/json",
"Authorization": f"Basic {token}",
}

def get_issue_title(self, issue_number: int) -> str:
issue_key = f"{self._settings.issue_prefix.rstrip('-')}-{issue_number}"
url = f"{self._settings.tracker_url.rstrip('/')}/rest/api/3/issue/{issue_key}"

response = httpx.get(url, headers=self._headers())

if response.status_code == 200:
data = response.json()
return data["fields"]["summary"]

raise Abort(f"Failed to fetch issue: {response.status_code}, {response.text}")
2 changes: 1 addition & 1 deletion src/delfino_core/commands/typecheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def run_mypy(
folder for folder in app_context.pyproject_toml.tool.delfino.local_command_folders if folder.exists()
)

strict_paths = plugin_config.typecheck.strict_directories
strict_paths = plugin_config.mypy.strict_directories
grouped_paths = groupby(
target_paths,
lambda current_path: is_path_relative_to_paths(current_path, strict_paths),
Expand Down
Loading
Loading