Skip to content
Merged
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Please note that by submitting this pull request to **Img2Num**, you confirm tha

<!-- Use the fixes keyword below and the issue related to this PR to link them. -->

Fixes:
Fixes: #<issue-number> <!-- use "Fixes: none" if no related issue -->

## Changes

Expand Down
22 changes: 22 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
c/cpp:
- "**/*.c"
- "**/*.cpp"
- "**/*.h"
- "**/*.hpp"

docs:
- "**/*.md"

ci:
- ".github/**"

js/ts:
- "**/*.js"
- "**/*.jsx"
- "**/*.ts"
- "**/*.tsx"
- "vite.config.*" # Vite config files
- "vite.*.js" # optional extra patterns
- "package.json" # package manifest changes
- "package-lock.json"
- "yarn.lock"
21 changes: 21 additions & 0 deletions .github/workflows/pr-auto-label.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This workflow will triage pull requests and apply a label based on the
# paths that are modified in the pull request.
#
# To use this workflow, you will need to set up a .github/labeler.yml
# file with configuration. For more information, see:
# https://github.com/actions/labeler

name: Labeler
on: [pull_request_target]

jobs:
label:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write

steps:
- uses: actions/labeler@v4
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
Comment thread
Ryan-Millard marked this conversation as resolved.
Resolved
106 changes: 106 additions & 0 deletions .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
name: PR Validation

permissions:
contents: read

on:
pull_request:
types: [opened, edited, reopened, synchronize]

jobs:
title-check:
runs-on: ubuntu-latest
steps:
- name: Check PR title
uses: actions/github-script@v7
with:
script: |
const pr = context.payload.pull_request;
const title = pr.title;

const isWip = title.startsWith("WIP:");
const isDraft = pr.draft;

const conventionalRegex =
/^(build|ci|chore|docs|feat|fix|perf|refactor|revert|style|test)(\([^)]+\))?(!)?: .+/;

if (isDraft || isWip) {
core.info("Draft or WIP PR detected — skipping title enforcement.");
return;
}

if (!conventionalRegex.test(title)) {
core.setFailed(
`Invalid PR title.\n\n` +
`Expected:\n` +
`type(scope)!: description\n\n` +
`Allowed types:\n` +
`build, ci, chore, docs, feat, fix, perf, refactor, revert, style, test\n\n` +
`Examples:\n` +
`- feat: new feature\n` +
`- fix(scope): bug in scope\n` +
`- feat!: breaking change\n` +
`- chore(deps): update dependencies\n\n` +
`If this is WIP, prefix the title with "WIP:" or convert the PR to Draft.`
);
}

body-check:
Comment thread Fixed
needs: title-check
runs-on: ubuntu-latest
steps:
- name: Validate PR body
uses: actions/github-script@v7
with:
script: |
const pr = context.payload.pull_request;
const body = pr.body || "";
const title = pr.title || "";

const isDraft = pr.draft;
const isWip = title.startsWith("WIP:");

if (isDraft || isWip) {
core.info("Draft or WIP PR — skipping body enforcement.");
return;
}

const requiredSections = [
"## What was changed & why",
"## Changes",
"## Testing & Verification"
];

const missingSections = requiredSections.filter(
section => !body.includes(section)
);

if (missingSections.length > 0) {
core.setFailed(
`PR body is missing the following required sections:\n` +
missingSections.join("\n") +
`\n\nPlease add these sections to your PR body.`
);
}

// Check for multiple issue references like "fixes #2" or "fixes: #2"
const issueReferences = [...body.matchAll(/(fixes|closes|resolves)\s*:?\s*#\d+/gi)];

const hasNone = /\bnone\b/i.test(body);

// Convert matchAll result to boolean
const hasIssueKeyword = issueReferences.length > 0;

// Fail only if neither issue references nor "none" exists
if (!hasIssueKeyword && !hasNone) {
core.setFailed(
`PR must reference an issue or explicitly state "none".\n\n` +
`Use one or more of the following keywords:\n` +
`- Fixes #<issue-number>\n` +
`- Closes #<issue-number>\n` +
`- Resolves #<issue-number>\n\n` +
`You can list multiple issues:\n` +
`fixes #2\nfixes: #3\n\n` +
`If no issue applies, write "none" in the PR body.`
);
}
Comment thread Fixed
30 changes: 30 additions & 0 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This workflow warns and then closes issues and PRs that have had no activity for a specified amount of time.
#
# For more information, see:
# https://github.com/actions/stale
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
name: Mark stale issues and pull requests

on:
schedule:
- cron: "0 2 * * *" # every day at 02:00 UTC
workflow_dispatch:

jobs:
stale:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write

steps:
- uses: actions/stale@v10
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: "This issue has been inactive for 60 days. Please comment if it is still relevant or it will be closed in 14 days."
stale-pr-message: "This pull request has been inactive for 60 days. Please update it or it will be closed in 14 days."
stale-issue-label: "no-issue-activity"
stale-pr-label: "no-pr-activity"
days-before-stale: 60
days-before-close: 14
exempt-issue-labels: "pinned,important"
exempt-pr-labels: "pinned,important"