diff --git a/.github/PULL_REQUEST_TEMPLATE/pr.md b/.github/PULL_REQUEST_TEMPLATE/pr.md index 655c7ff..08e2a43 100644 --- a/.github/PULL_REQUEST_TEMPLATE/pr.md +++ b/.github/PULL_REQUEST_TEMPLATE/pr.md @@ -15,5 +15,4 @@ ## Checklist -- [ ] I have read the [Contributing Guidelines](../Contributor_Guide/Contruting.md). - +- [ ] I have read the [Contributing Guidelines](../Contributor_Guide/Contruting.md). \ No newline at end of file diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..08e2a43 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,18 @@ + +## Description + +> Give a brief description of the pull request. + +## Semver Changes + +- [ ] Patch (bug fix, no new features) +- [ ] Minor (new features, no breaking changes) +- [ ] Major (breaking changes) + +## Issues + +> List any issues that this pull request closes. + +## Checklist + +- [ ] I have read the [Contributing Guidelines](../Contributor_Guide/Contruting.md). \ No newline at end of file diff --git a/.github/workflows/checklabels.yaml b/.github/workflows/checklabels.yaml new file mode 100644 index 0000000..1b752ff --- /dev/null +++ b/.github/workflows/checklabels.yaml @@ -0,0 +1,21 @@ +name: Label Checker + +on: + pull_request: + types: [opened, edited, synchronize, reopened, labeled, unlabeled] + +jobs: + check-labels: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: 16 + - name: Install dependencies + run: npm install @actions/github @actions/core + - name: Run Label Checker + run: node .github/workflows/label-checker.js + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/commitlint.yaml b/.github/workflows/commitlint.yaml index 7c61d10..75c761d 100644 --- a/.github/workflows/commitlint.yaml +++ b/.github/workflows/commitlint.yaml @@ -33,4 +33,4 @@ jobs: - name: Validate PR commits with commitlint if: github.event_name == 'pull_request' - run: npx commitlint --from ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }} --to ${{ github.event.pull_request.head.sha }} --verbose + run: npx commitlint --from ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }} --to ${{ github.event.pull_request.head.sha }} --verbose \ No newline at end of file diff --git a/.github/workflows/label-checker.js b/.github/workflows/label-checker.js new file mode 100644 index 0000000..aae7358 --- /dev/null +++ b/.github/workflows/label-checker.js @@ -0,0 +1,42 @@ +import { getOctokit, context } from '@actions/github'; +import { setFailed } from '@actions/core'; + +async function run() { + try { + const token = process.env.GITHUB_TOKEN; + const octokit = new getOctokit(token); + + const pullRequest = context.payload.pull_request; + const owner = pullRequest.base.repo.owner.login; + const repo = pullRequest.base.repo.name; + const pullNumber = pullRequest.number; + + const { data: labels } = await octokit.rest.issues.listLabelsOnIssue({ + owner, + repo, + issue_number: pullNumber, + }); + + const labelNames = labels.map((label) => label.name); + + const requiredLabels = [ + ['Type:Easy', 'Type:Medium', 'Type:Hard'], + ['Semver:major', 'Semver:minor', 'Semver:patch'], + ['PR:Accept'], + ]; + + const hasRequiredLabels = requiredLabels.every((labelGroup) => + labelGroup.some((label) => labelNames.includes(label)) + ); + + if (!hasRequiredLabels) { + setFailed( + 'This pull request must have at least one label from each of the following groups: Type (Easy, Medium, Hard), Semver (Major, Minor, Patch), and PR:Accept.' + ); + } + } catch (error) { + setFailed(error.message); + } +} + +run(); \ No newline at end of file diff --git a/.github/workflows/prmerged.yaml b/.github/workflows/prmerged.yaml index 319c68d..0570c31 100644 --- a/.github/workflows/prmerged.yaml +++ b/.github/workflows/prmerged.yaml @@ -29,4 +29,4 @@ jobs: API_AUTH_TOKEN: ${{ secrets.API_AUTH_TOKEN }} run: | payload=$(echo '{"owner":"${{ steps.get-pr-data.outputs.owner }}","labels":"${{ steps.get-pr-data.outputs.labels }}","repository_name":"${{ steps.get-pr-data.outputs.repo_name }}","repository_url":"${{ steps.get-pr-data.outputs.repo_url }}"}') - curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $API_AUTH_TOKEN" -d "$payload" "$API_URL" + curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $API_AUTH_TOKEN" -d "$payload" "$API_URL" \ No newline at end of file