-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`); | ||
} | ||
} |