feat(.github): init (#1)

This commit is contained in:
Saahil 2024-09-21 14:37:17 -04:00 committed by GitHub
parent d8c534fc9c
commit b20cc8e9d4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 169 additions and 0 deletions

6
.github/labels.yml vendored Normal file
View file

@ -0,0 +1,6 @@
rice-setup: rice/*
feature: feat/*
site: website/*
scripts: scripts/*
fix: fix/*
bug: bug/*

28
.github/pull_request_template.md vendored Normal file
View file

@ -0,0 +1,28 @@
<!-- use this template if you are submitting a rice. if not delete all content in this template -->
<!-- PELASE DELETE THE FOLLOWING LINE BELOW IF YOU ARE NOT DOING A RICE -->
<!-- automation:labels:rice -->
## My rice
<!-- rice name here -->
## How many hours did it take to write this
<!-- x amount of hours here -->
<!-- ex: 5 hours -->
<!-- optional -->
## Source Code
<!-- if you have public source code to your dotfiles -->
<!-- this will improve the PR and make it easier to approve -->
## Screenshots of Rice
<!-- screenshots of rice -->
<!-- optional if source code is provided -->
<!-- highly recommended. -->
## Extra Comments
## Checklist
- [ ] I have filled out the form correctly
- [ ] I have read this [message (slack)](https://hackclub.slack.com/archives/C07MLF9A8H5/p1726689185936959)
<!-- NOTE: this is supposed to be automated but just in case. -->
- [ ] i have my pr labled correctly
<!-- TODO: Contributors? should this stay? -->
- [ ] I have not already submited one

17
.github/workflows/ci.yml vendored Normal file
View file

@ -0,0 +1,17 @@
on:
pull_request:
types: [opened, reopened,synchronize]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
permissions: write-all # feel free to change this in PR.
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: "20.x"
- run: OWNER_NAME=${{ github.event.repository.owner.login }} REPO_NAME=${{ github.event.repository.name }} GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} PR_NUMBER=${{ github.event.number }} node scripts/validate_prs.js

18
.github/workflows/form.yml vendored Normal file
View file

@ -0,0 +1,18 @@
on:
pull_request:
types: [closed]
jobs:
send-message:
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'rice-setup')
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v6
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '👋 Thanks for your PR!\nTo claim your free socks fill out this [form](...formlinkhere)'
})

19
.github/workflows/label.yml vendored Normal file
View file

@ -0,0 +1,19 @@
name: PR Labeler
on:
pull_request:
types: [opened]
permissions:
contents: read
jobs:
pr-labeler:
permissions:
contents: read # for TimonVS/pr-labeler-action to read config file
pull-requests: write # for TimonVS/pr-labeler-action to add labels in PR
runs-on: ubuntu-latest
steps:
- uses: TimonVS/pr-labeler-action@v5
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
configuration-path: .github/labels.yml # optional, .github/pr-labeler.yml is the default value

1
members.json Normal file
View file

@ -0,0 +1 @@
[]

80
scripts/validate_prs.js Normal file
View file

@ -0,0 +1,80 @@
// using node-fetch instead of octokit.
const fs = require("fs");
const simpleApiReq = (r, method, data, headers) => {
return fetch("https://api.github.com/" + r, {
method: method || "GET",
headers: {
...(headers ?? {}),
Accept: "application/vnd.github+json",
"Authorization": process.env.GITHUB_TOKEN,
},
body: data ? JSON.stringify(data) : undefined,
}).then((r) => r.json());
};
const owner = process.env.OWNER_NAME || "OtterCodes101";
const repo = process.env.REPO_NAME || "programmer-socks-ysws";
const pull_number = process.env.PR_NUMBER;
(async () => {
const prData = await simpleApiReq(
`repos/${owner}/${repo}/pulls/${pull_number}`,
undefined,
undefined,
{
"Accept": "application/vnd.github.text+json"
}
);
if (prData.body_text && prData.body_text.includes("automation:labels:rice")) {
simpleApiReq(`repos/${owner}/${repo}/issues/${pr_number}/labels`, "POST", {
labels: ["rice-setup"],
});
}
const commentError = (message) =>
simpleApiReq(
`repos/${owner}/${repo}/pulls/${pull_number}/comments`,
"POST",
{
event: "REQUEST_CHANGES",
body: message,
}
);
// validate members.json file
// schema
// name -> GH username here (ex: John Does dotfiles or what ever you name ur dotfiles)string (req)
// dotfiles git link (optional) string
// dotfiles os (nixos,arch,etc) string (req)
// TODO: any other props?
function validate(obj) {
if (!obj.name) throw "No Name";
if (!obj.os) throw "No OS provided";
if (obj.git && typeof obj.git !== "string") throw "git is not a string";
if (typeof obj.name !== "string") throw "Name is not a string";
if (typeof obj.os !== "string") throw "OS is not a string";
if (
obj.git &&
typeof obj.git === "string" &&
!obj.git.startsWith("https://")
)
throw "git is not a url";
return true;
}
const members = fs.readFileSync(process.cwd() + "/members.json");
let already_thrown = false;
try {
let parsed = JSON.parse(members);
if (Array.isArray(parsed)) {
parsed.forEach((e) => {
if (already_thrown) return;
try {
validate(e);
} catch (e) {
already_thrown = true;
commentError(e.message);
}
});
} else {
commentError(`Its not an array `);
}
} catch (e) {
commentError("Broken JSON:\n```" + e.message + "```");
}
})();