Skip to content

Commit

Permalink
ci(project-structure): package and tools config by pyproject.toml
Browse files Browse the repository at this point in the history
- add commitizen support to pyproject.toml
- add Danger for GitHub
- add pre-commit hook for codespell
- add pre-commit hook prettier - formatting Markdown files
- add pre-commit workflow to CI
  • Loading branch information
tomassebestik committed Feb 13, 2024
1 parent 6301172 commit ee5a61f
Show file tree
Hide file tree
Showing 18 changed files with 166 additions and 373 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/dangerjs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: DangerJS Pull Request linter
on:
pull_request_target:
types: [opened, edited, reopened, synchronize]

permissions:
pull-requests: write
contents: write

jobs:
pull-request-style-linter:
runs-on: ubuntu-latest
steps:
- name: Check out PR head
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: DangerJS pull request linter
uses: espressif/shared-github-dangerjs@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
instructions-contributions-file: 'CONTRIBUTING.md'
16 changes: 16 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Check pre-commit

on:
pull_request:

jobs:
check-pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v5
- uses: pre-commit/[email protected]
env:
SKIP: pip-compile
16 changes: 0 additions & 16 deletions .github/workflows/test_jira_sync.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,6 @@ venv.bak/
.mypy_cache/
.ruff_cache/
__pycache__/*

# Generated by setuptools-scm when using pip install -e
version.py
28 changes: 23 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ repos:
- id: double-quote-string-fixer # Converts single quotes to double quotes in strings

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.280
rev: v0.2.1
hooks:
- id: ruff # Runs ruff linter (replaces flake8)
args: [--fix, --exit-non-zero-on-fix]
Expand All @@ -29,7 +29,7 @@ repos:
- id: reorder-python-imports # Reorders Python imports to a standard format (replaces isort)

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.4.1
rev: v1.8.0
hooks:
- id: mypy # Runs mypy for Python type checking
additional_dependencies: ['types-all']
Expand All @@ -41,11 +41,29 @@ repos:
stages: [commit-msg]

- repo: https://github.com/psf/black
rev: '23.7.0'
rev: '24.1.1'
hooks:
- id: black # Formats Python code using black

- repo: https://github.com/pylint-dev/pylint
rev: v2.17.5
rev: v3.0.3
hooks:
- id: pylint # Runs pylint on Python code
- id: pylint # Runs pylint on Python code

- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
hooks:
- id: codespell # Code spell checker
args: ["--write-changes"]
additional_dependencies: [tomli]


# Local hooks
- repo: local
hooks:
- id: pip-compile
name: compile requirements.txt
entry: bash -c 'pip-compile --output-file=requirements.txt pyproject.toml > /dev/null'
language: system
pass_filenames: false
files: requirements.txt|pyproject.toml
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
---
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ RUN pip install --no-cache-dir -r /tmp/requirements.txt
RUN npm i -g @shogobg/[email protected]

# Copy Python scripts
COPY src/ /src
COPY sync_jira_actions/ /sync_jira_actions

# Define the entrypoint to use the virtual environment's Python interpreter
ENTRYPOINT ["/opt/venv/bin/python", "/sync_jira_actions/sync_to_jira.py"]
11 changes: 4 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,7 @@ name: Sync remaining PRs to Jira
# Note that PRs can also get synced when a new PR comment is created
on:
schedule:
- cron: '0 * * * *'

# Limit to single concurrent run for workflows which can create Jira issues.
# Same concurrency group is used in issue_comment.yml
- cron: "0 * * * *"
concurrency: jira_issues

jobs:
Expand Down Expand Up @@ -149,11 +146,11 @@ on:
workflow_dispatch:
inputs:
action:
description: 'Action to be performed'
description: "Action to be performed"
required: true
default: 'mirror-issues'
default: "mirror-issues"
issue-numbers:
description: 'Issue numbers'
description: "Issue numbers"
required: true
concurrency: jira_issues
Expand Down
85 changes: 76 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,79 @@
max-line-length = 120 # Specifies the maximum line length for pylint checks


[tool.pytest.ini_options]
addopts = "-s --log-cli-level DEBUG --cov=. --cov-report=term"
python_classes = ["Test*"]
python_files = ["test_*.py"]
python_functions = ["test_*"]
testpaths = ["tests"]

[tool.coverage.run]
omit = ["__*__.py", "tests/*"]
[tool.pytest.ini_options]
addopts = "-s --log-cli-level DEBUG --cov=. --cov-report=term"
python_classes = ["Test*"]
python_files = ["test_*.py"]
python_functions = ["test_*"]
testpaths = ["tests"]

[tool.coverage.run]
omit = ["__*__.py", "tests/*"]

[tool.commitizen]
annotated_tag = true
bump_message = "change: release v$new_version"
name = "cz_customize"
tag_format = "v$version"
update_changelog_on_bump = true
version_provider = "scm"

[tool.commitizen.customize]
bump_map = { "change" = "MINOR", "feat" = "MINOR", "fix" = "PATCH", "refactor" = "PATCH", "remove" = "PATCH", "revert" = "PATCH" }
bump_pattern = "^(change|feat|fix|refactor|remove|revert)"
change_type_order = [
"change",
"ci",
"docs",
"feat",
"fix",
"refactor",
"remove",
"revert",
]
example = "change: this is a custom change type"
message_template = "{% if scope %}{{change_type}}({{scope}}): {{message}}{% else %}{{change_type}}: {{message}}{% endif %}{% if body %}\n\n{{body}}{% endif %}{% if is_breaking_change %}\n\nBREAKING CHANGE{% endif %}{% if footer %}\n\n{{footer}}{% endif %}"
schema = "<type>(<scope>): <summary>"
schema_pattern = "^([a-z]+)(\\([\\w\\-\\.]+\\))?:\\s.*"

[[tool.commitizen.customize.questions]]
choices = [
{ value = "change", name = "change: A change made to the codebase." },
{ value = "ci", name = "ci: Changes to our CI configuration files and scripts." },
{ value = "docs", name = "docs: Documentation only changes." },
{ value = "feat", name = "feat: A new feature." },
{ value = "fix", name = "fix: A bug fix." },
{ value = "refactor", name = "refactor: A code change that neither fixes a bug nor adds a feature." },
{ value = "remove", name = "remove: Removing code or files." },
{ value = "revert", name = "revert: Revert to a commit." },
]
message = "Select the TYPE of change you are committing"
name = "change_type"
type = "list"

[[tool.commitizen.customize.questions]]
message = "What is the SCOPE of this change (press enter to skip)?"
name = "scope"
type = "input"

[[tool.commitizen.customize.questions]]
message = "Describe the changes made (SUMMARY of commit message):"
name = "message"
type = "input"

[[tool.commitizen.customize.questions]]
message = "Provide additional contextual information - commit message BODY: (press [enter] to skip)"
name = "body"
type = "input"

[[tool.commitizen.customize.questions]]
default = false
message = "Is this a BREAKING CHANGE? Correlates with MAJOR in SemVer"
name = "is_breaking_change"
type = "confirm"

[[tool.commitizen.customize.questions]]
message = "Footer. Information about Breaking Changes and reference issues that this commit closes: (press [enter] to skip)"
name = "footer"
type = "input"
File renamed without changes.
2 changes: 1 addition & 1 deletion src/sync_issue.py → sync_jira_actions/sync_issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ def _get_jira_issue_type(jira, gh_issue):
print('GitHub label is \'Type: Feature Request\'. Mapping to New Feature Jira issue type')
return {'id': JIRA_NEW_FEATURE_TYPE_ID} # JIRA API needs JSON here
# Some projects use Label with bug icon represented by ":bug:" in label name.
# This if mathes those to Bug Jira issue type
# This if matches those to Bug Jira issue type
if gh_label == 'Type: Bug :bug:':
print('GitHub label is \'Type: Bug :bug:\'. Mapping to Bug Jira issue type')
return {'id': JIRA_BUG_TYPE_ID} # JIRA API needs JSON here
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions src/sync_to_jira.py → sync_jira_actions/sync_to_jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def main():

# Check if it's a cron job
if os.environ.get('INPUT_CRON_JOB'):
print('Running as a cron job. Syncing remaining PRs...')
sync_remain_prs(jira)
return

Expand Down
16 changes: 0 additions & 16 deletions sync_jira_actions/version.py

This file was deleted.

Loading

0 comments on commit ee5a61f

Please sign in to comment.