Skip to main content

Validate (lint) GitHub issues.

Project description

gh-issue-validator

gh-issue-validator is a customizable "linter" for issues in a GitHub repository. It ensures issues conform to a specified format.

Installation

You typically wouldn't install this package on your local machine. It expects to be used in GitHub Actions.

Usage

Write your validation script

To get started, you'll need to write a validation script. We suggest creating it at .github/issue_validator.py.

At the top of the script, include PEP723 metadata to enable automated installation of dependencies. At minimum, we'll need to add this project, gh-issue-validator, as a dependency.

# /// script
# requires-python = ">=3.12"
# dependencies = [
#   "gh-issue-validator",
# ]
# ///
import typing

from gh_issue_validator import ValidationCheck, ValidationIssue, ValidationReport, validate
from gh_issue_validator.checks.headings import CheckMissingHeadings, HeadingRequirement
from gh_issue_validator.types import SegmentsMap


# Optional: Create your own validator based on the ValidationCheck ABC.
class ProblemStatementQualityCheck(ValidationCheck):
    """Reject problem statements that are just a URL."""

    @typing.override
    def check(self, *, segments: SegmentsMap, report: ValidationReport) -> None:
        heading_to_check = "Problem statement"
        content = segments.get(heading_to_check, [])
        if not content:
            return  # Empty content is handled by first-party CheckWordCount check.

        text = str(content).strip()
        if text.startswith("http") and " " not in text:
            # Our custom "issue" to report:
            report.add_issue(ValidationIssue(
                code="problem-statement-is-url",
                message="Problem statement should be a description, not just a URL.",
                heading=heading_to_check,
            ))

HEADING_REQUIREMENTS =[
    {"heading": "Problem statement", "min_words": 10},
    {"heading": "Proposed solution", "min_words": 5, "max_words": 100},
]

validate(checks=[
    CheckMissingHeadings(requirements=HEADING_REQUIREMENTS),
    CheckWordCount(requirements=HEADING_REQUIREMENTS)
    ProblemStatementQualityCheck(),
])

Call it from GitHub Actions

on:
  issues:
    types:
      - "opened"
      - "edited"
      - "labeled"
      - "unlabeled"

jobs:
  validate:
    # Filter for only issues labeled as "initiative"
    if: "contains(github.event.issue.labels.*.name, 'initiative')"
    runs-on: "ubuntu-latest"
    permissions:
      issues: "write"
    steps:
      - uses: "actions/checkout@v4"
      - uses: "astral-sh/setup-uv@v5"
      - run: "uv run .github/issue_validator.py"
        env:
          GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
          GITHUB_ISSUE_NUMBER: "${{ github.event.issue.number }}"

Development

Tools: uv, prek

Get started

uv sync
prek install

Run tests

prek run -a
uv run mypy
uv run pytest

Acknowledgement

This validator is inspired by the https://github.com/2i2c-org/initiatives project.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gh_issue_validator-0.0.2.tar.gz (68.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gh_issue_validator-0.0.2-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file gh_issue_validator-0.0.2.tar.gz.

File metadata

  • Download URL: gh_issue_validator-0.0.2.tar.gz
  • Upload date:
  • Size: 68.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for gh_issue_validator-0.0.2.tar.gz
Algorithm Hash digest
SHA256 9b0d3b130365076a2c021119d29f69e64d82b3fd21ced3e1b8d9dd15d146a9ca
MD5 c72cf4a00dd267764a269086e45c87e2
BLAKE2b-256 e32af6ea3c28f20d0bf640b099284d6a915dfdf784fbaecca38275d2f8233154

See more details on using hashes here.

Provenance

The following attestation bundles were made for gh_issue_validator-0.0.2.tar.gz:

Publisher: publish.yml on mfisher87/gh-issue-validator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gh_issue_validator-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for gh_issue_validator-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4f983ed7d21eb77c3559f3901e3816d63fd6e7b84403ed1e644dc74c5bf37274
MD5 00ad02dc0d81c3d93d3e467cee28ca1c
BLAKE2b-256 1ed2312a7ec7a241ddf71a5274b4fd6a2f22ae2709e266243a75313fc9ff9136

See more details on using hashes here.

Provenance

The following attestation bundles were made for gh_issue_validator-0.0.2-py3-none-any.whl:

Publisher: publish.yml on mfisher87/gh-issue-validator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page