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

Add linting with tox #34

Merged
merged 6 commits into from
Mar 6, 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
33 changes: 33 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
name: check
on: [push, pull_request]

concurrency:
group: check-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
name: test with ${{ matrix.py }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
py:
- "3.12"
os:
- ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup python for test ${{ matrix.py }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.py }}
- name: Install tox
run: python -m pip install tox-gh>=1.2
- name: Setup test suite
run: tox -vv --notest
- name: Run test suite
run: tox --skip-pkg-install
1 change: 1 addition & 0 deletions config/konflux.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
jira:
# url: https://issues.redhat.com
project-id: KONFLUX
Expand Down
1 change: 1 addition & 0 deletions config/plnsrvce.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
jira:
# url: https://issues.redhat.com
project-id: PLNSRVCE
Expand Down
1 change: 1 addition & 0 deletions config/rhtap.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
jira:
# url: https://issues.redhat.com
project-id: RHTAP
Expand Down
1 change: 1 addition & 0 deletions config/stoneintg.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
jira:
# url: https://issues.redhat.com
project-id: STONEINTG
Expand Down
3 changes: 2 additions & 1 deletion config/template.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
jira:
# url: https://issues.redhat.com
project-id: #PROJECT_KEY
project-id: # PROJECT_KEY
team_automation:
issues:
Epic:
Expand Down
9 changes: 7 additions & 2 deletions src/automation.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ def main(dry_run: bool, config_file: str, token: str) -> None:
collector = getattr(
jira_module, issue_config.get("collector", "get_issues")
)
issues = collector(jira_client, config["jira"]["project-id"], config["jira"]["subquery"], issue_type)
issues = collector(
jira_client,
config["jira"]["project-id"],
config["jira"]["subquery"],
issue_type,
)
issue_rules = [
getattr(rules_modules[automation], rule)
for rule in issue_config.get("rules", [])
Expand All @@ -79,7 +84,7 @@ def process_type(
count = len(issues)
for index, issue in enumerate(issues):
print(
f"\n### [{index+1}/{count}]\t{issue.key}: {issue.fields.summary}\t[{issue.fields.assignee}/{issue.fields.status}]"
f"\n### [{index + 1}/{count}]\t{issue.key}: {issue.fields.summary}\t[{issue.fields.assignee}/{issue.fields.status}]"
)
context = {
"comments": [],
Expand Down
2 changes: 2 additions & 0 deletions src/rules/program/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
from .components import check_components
from .target_end import check_target_end_date

__all__ = [check_components, check_target_end_date]
4 changes: 1 addition & 3 deletions src/rules/program/components.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from time import strftime

import jira

from utils.jira import refresh, update
from utils.jira import update


def check_components(issue: jira.resources.Issue, context: dict, dry_run: bool) -> None:
Expand Down
2 changes: 1 addition & 1 deletion src/rules/program/target_end.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import jira

from utils.jira import refresh, update
from utils.jira import update

today = strftime("%Y-%m-%d")

Expand Down
10 changes: 10 additions & 0 deletions src/rules/team/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,13 @@
from .quarter_label import check_quarter_label
from .rank import check_rank
from .target_dates import check_target_dates

__all__ = [
check_due_date,
set_fix_version,
check_parent_link,
check_priority,
check_quarter_label,
check_rank,
check_target_dates,
]
4 changes: 2 additions & 2 deletions src/rules/team/due_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import jira

from utils.jira import refresh, update
from utils.jira import update

today = strftime("%Y-%m-%d")

Expand Down Expand Up @@ -48,5 +48,5 @@ def check_due_date(issue: jira.resources.Issue, context: dict, dry_run: bool) ->
end_date = getattr(issue.fields, end_date_id)
if end_date and target_due_date and end_date > target_due_date:
context["updates"].append(
f" ? Target Date exceeds Due Date. You may want to notify the Program Managers."
" ? Target Date exceeds Due Date. You may want to notify the Program Managers."
)
2 changes: 1 addition & 1 deletion src/rules/team/parent.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
def check_parent_link(issue: jira.resources.Issue, context: dict, _: bool) -> None:
if issue.raw["Context"]["Related Issues"]["Parent"] is None:
context["non-compliant"] = True
context["comments"].append(f" * Issue is missing the link to its parent.")
context["comments"].append(" * Issue is missing the link to its parent.")
3 changes: 2 additions & 1 deletion src/rules/team/rank.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
This helps prioritize the work that is currently on-going rather than future
improvements that have been ranked very high.
"""

import jira


Expand Down Expand Up @@ -78,7 +79,7 @@ def _set_rank(
else:
jira_client.rank(issue=issue.key, prev_issue=previous_issue.key)
previous_issue = issue
print(f"\r{100*(index+1)//total}%", end="", flush=True)
print(f"\r{100 * (index + 1) // total}%", end="", flush=True)


class Block:
Expand Down
8 changes: 4 additions & 4 deletions src/rules/team/target_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ def check_target_dates(

if start_date:
if start_date < today and issue.fields.status in ["New", "Refinement"]:
context["updates"].append(f" > Issue Target Start Date is obsolete.")
context["updates"].append(" > Issue Target Start Date is obsolete.")
elif parent_is_inprogress:
context["updates"].append(f" * Issue Target Start Date unset.")
context["updates"].append(" * Issue Target Start Date unset.")
if end_date:
# Query ensure the issue is not closed
if end_date < today:
context["updates"].append(f" * Issue Target End Date is obsolete.")
context["updates"].append(" * Issue Target End Date is obsolete.")
elif parent_is_inprogress:
context["updates"].append(f" * Issue Target End Date unset.")
context["updates"].append(" * Issue Target End Date unset.")
4 changes: 3 additions & 1 deletion src/utils/jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import jira


def get_issues(jira_client: jira.client.JIRA, project_id: str, subquery: str, issue_type: str) -> list:
def get_issues(
jira_client: jira.client.JIRA, project_id: str, subquery: str, issue_type: str
) -> list:
result = query_issues(jira_client, project_id, subquery, issue_type)
preprocess(jira_client, result)
return result
Expand Down
Empty file added tests/__init__.py
Empty file.
41 changes: 41 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[tox]
envlist = flake8,black,isort,test,yamllint

[flake8]
ignore = E731,W504,W503
max-line-length = 160
exclude =
./.tox
./.git
./.env
./.direnv
[isort]
profile = black

[testenv:flake8]
basepython = python3
skip_install = true
deps = flake8
commands = flake8 {posargs}

[testenv:black]
skip_install = true
deps = black
commands = black --check --diff {posargs:src/ tests/}

[testenv:black-format]
# this step format code automatically based on black rules
# it can be triggered manually
skip_install = true
deps = black
commands = black {posargs:src/ tests/}

[testenv:isort]
skip_install = true
deps = isort
commands = isort --check --diff {posargs:.}

[testenv:yamllint]
skip_install = true
deps = yamllint
commands = yamllint -s -f colored {posargs:config/}
Loading