Skip to content

Commit 512c61c

Browse files
authored
Merge pull request #5 from sbmmahato/main
feat: setup
2 parents 9782963 + b97c532 commit 512c61c

File tree

4 files changed

+83
-1
lines changed

4 files changed

+83
-1
lines changed

.github/pull_request_template.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
## Description
3+
4+
> Give a brief description of the pull request.
5+
6+
## Semver Changes
7+
8+
- [ ] Patch (bug fix, no new features)
9+
- [ ] Minor (new features, no breaking changes)
10+
- [ ] Major (breaking changes)
11+
12+
## Issues
13+
14+
> List any issues that this pull request closes.
15+
16+
## Checklist
17+
18+
- [ ] I have read the [Contributing Guidelines](../Contributor_Guide/Contruting.md).
19+

.github/workflows/checklabels.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Label Checker
2+
3+
on:
4+
pull_request:
5+
types: [opened, edited, synchronize, reopened, labeled, unlabeled]
6+
7+
jobs:
8+
check-labels:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
- name: Set up Node.js
13+
uses: actions/setup-node@v3
14+
with:
15+
node-version: 16
16+
- name: Install dependencies
17+
run: npm install @actions/github @actions/core
18+
- name: Run Label Checker
19+
run: node .github/workflows/label-checker.js
20+
env:
21+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/label-checker.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { getOctokit, context } from '@actions/github';
2+
import { setFailed } from '@actions/core';
3+
4+
async function run() {
5+
try {
6+
const token = process.env.GITHUB_TOKEN;
7+
const octokit = new getOctokit(token);
8+
9+
const pullRequest = context.payload.pull_request;
10+
const owner = pullRequest.base.repo.owner.login;
11+
const repo = pullRequest.base.repo.name;
12+
const pullNumber = pullRequest.number;
13+
14+
const { data: labels } = await octokit.rest.issues.listLabelsOnIssue({
15+
owner,
16+
repo,
17+
issue_number: pullNumber,
18+
});
19+
20+
const labelNames = labels.map((label) => label.name);
21+
22+
const requiredLabels = [
23+
['Type:Easy', 'Type:Medium', 'Type:Hard'],
24+
['Semver:major', 'Semver:minor', 'Semver:patch'],
25+
['PR:Accept'],
26+
];
27+
28+
const hasRequiredLabels = requiredLabels.every((labelGroup) =>
29+
labelGroup.some((label) => labelNames.includes(label))
30+
);
31+
32+
if (!hasRequiredLabels) {
33+
setFailed(
34+
'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.'
35+
);
36+
}
37+
} catch (error) {
38+
setFailed(error.message);
39+
}
40+
}
41+
42+
run();

.github/workflows/prmerged.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ jobs:
2929
API_AUTH_TOKEN: ${{ secrets.API_AUTH_TOKEN }}
3030
run: |
3131
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 }}"}')
32-
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $API_AUTH_TOKEN" -d "$payload" "$API_URL"
32+
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $API_AUTH_TOKEN" -d "$payload" "$API_URL"

0 commit comments

Comments
 (0)