Skip to content

Commit

Permalink
flow test
Browse files Browse the repository at this point in the history
  • Loading branch information
habby1337 committed Feb 15, 2024
1 parent 9247b05 commit 864f3fe
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/create_setup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Create setup file
on:
issues:
types:
- closed

jobs:
create-setup-file:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Check if issue meets criteria
uses: actions/setup-node@v3
with:
node-version: "20"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Run script
run: |
CONTEXT="$(echo '${{ toJson(github.event) }}')"
echo "$CONTEXT" > context.json # Save the context to a file for debugging
node ./src/script.js
20 changes: 20 additions & 0 deletions issue_close.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"action": "closed",
"sender": {
"login": "habby1337"
},
"issue": {
"state": "closed",
"number": 1,
"title": "[SETUP] bmw_m3_gt2@ks_nordschleife",
"user": {
"login": "habby1337"
},
"labels": [
{
"name": "Awaiting Approval"
}
],
"body": "⚠️ Do not change any name, just add the needed information ⚠️\n\n❗ Change the issue title to the car name and track with this format: bmw_m3_gt2@ks_nordschleife❗\n\nNOTE: Use the assetto corsa name of the car (i.e., ferrari_f40_s3)\nNOTE: Use the assetto corsa name of the track (i.e., ks_nordschleife)\n\n## Track Information:\n- **Track name:** Test\n- **Car name:** Testcar\n- **Lap Time:** 1:54\n\n## Additional Details:\n- **Track Temps (if applicable):**\n- **Driving Aids (if used):**\n- **Tires:** SS\n- **Link of Hotlap Video:** WHOT\n\n"
}
}
46 changes: 46 additions & 0 deletions src/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const fs = require("fs");
const path = require("path");

const contextJson = fs.readFileSync("./context.json", "utf8");
const context = JSON.parse(contextJson);
const issue = context.issue;
console.log(issue);
const isClosed = issue.state === "closed";
console.log(issue.labels);
// const hasLabel = issue.labels.map((label) => label.name).includes("Awaiting Approval");
const hasLabel = issue.labels.some((label) => label.name === "Awaiting Approval");
const hasSetupTag = issue.title.includes("[SETUP]");

if (isClosed && hasLabel && hasSetupTag) {
// get from issue.body the car and track name: **Track name:** Test\n- **Car name:** Testcar\n

const carName = issue.body.match(/\*\*Car name:\*\* (.*)/)[1].trim();
const trackName = issue.body.match(/\*\*Track name:\*\* (.*)/)[1].trim();
console.log(carName, trackName);
const username = issue.user.login.trim();
const approvedBy = context.sender.login.trim();
const setupFilePath = `./setups/${carName}/${trackName}/${username}.ini`;
const dirPath = path.dirname(setupFilePath);

if (!fs.existsSync(dirPath)) {
console.log(
`Creating setup file for ${carName} at ${trackName} from ${username} approved by ${approvedBy} dirpath: ${dirPath}, path: ${setupFilePath}, ${process.cwd()}`,
);
try {
fs.mkdirSync(dirPath, {
recursive: true,
});
} catch (err) {
console.error(err);
}

try {
fs.writeFileSync(setupFilePath, "Hello test");
} catch (err) {
console.error(err);
}
// fs.writeFileSync(setupFilePath, "");
} else {
console.log(`Setup file for ${carName} at ${trackName} from ${username} already exists`);
}
}

0 comments on commit 864f3fe

Please sign in to comment.