Skip to content

Commit

Permalink
chore: updated setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Prayas248 committed Mar 23, 2024
1 parent 15c5a92 commit 9a93d0e
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

## 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).

21 changes: 21 additions & 0 deletions .github/workflows/checklabels.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
42 changes: 42 additions & 0 deletions .github/workflows/label-checker.js
Original file line number Diff line number Diff line change
@@ -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();

0 comments on commit 9a93d0e

Please sign in to comment.