forked from Eclipse-Laboratories-Inc/program-registry
-
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
0 parents
commit 7b6253f
Showing
206 changed files
with
143,047 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,101 @@ | ||
import { createRequire } from 'module'; | ||
import fetch from 'node-fetch'; | ||
import yaml from 'js-yaml'; | ||
|
||
const require = createRequire(import.meta.url); | ||
const fs = require('fs'); | ||
|
||
const owner = process.env.REPO_OWNER; | ||
const repo = process.env.REPO_NAME; | ||
const pull_number = process.env.PR_NUMBER; | ||
|
||
const requiredKeys = [ | ||
'name', | ||
'description', | ||
'repo', | ||
'icon', | ||
'framework', | ||
'program_address', | ||
'categories' | ||
]; | ||
|
||
async function validateAndMerge() { | ||
const { Octokit } = await import('@octokit/rest'); | ||
|
||
const octokit = new Octokit({ | ||
auth: process.env.GITHUB_TOKEN, | ||
request: { | ||
fetch: fetch, | ||
}, | ||
}); | ||
|
||
try { | ||
const { data: pr } = await octokit.pulls.get({ | ||
owner, | ||
repo, | ||
pull_number, | ||
}); | ||
|
||
const { data: files } = await octokit.pulls.listFiles({ | ||
owner, | ||
repo, | ||
pull_number, | ||
}); | ||
|
||
const yamlFile = files.find(file => file.filename.endsWith('.yaml') || file.filename.endsWith('.yml')); | ||
|
||
if (!yamlFile) { | ||
console.log('No YAML file found in the PR'); | ||
return; | ||
} | ||
|
||
const { data: fileContent } = await octokit.repos.getContent({ | ||
owner, | ||
repo, | ||
path: yamlFile.filename, | ||
ref: pr.head.ref, | ||
}); | ||
|
||
const content = Buffer.from(fileContent.content, 'base64').toString('utf-8'); | ||
|
||
// Parse all YAML documents in the file | ||
const yamlDocuments = yaml.load(content); | ||
|
||
for (const document of yamlDocuments) { | ||
const isValid = validateSubdocument(document); | ||
if (!isValid) { | ||
console.log(`Invalid subdocument: ${JSON.stringify(document)}`); | ||
return; | ||
} | ||
} | ||
|
||
await octokit.pulls.merge({ | ||
owner, | ||
repo, | ||
pull_number, | ||
merge_method: 'squash', | ||
}); | ||
|
||
console.log('PR automatically merged'); | ||
} catch (error) { | ||
console.error('Error:', error.message); | ||
} | ||
} | ||
|
||
function validateSubdocument(subdocument) { | ||
const isValid = requiredKeys.every(key => key in subdocument); | ||
|
||
if (!isValid) { | ||
console.log(`Subdocument is missing required keys: ${JSON.stringify(subdocument)}`); | ||
return false; | ||
} | ||
|
||
if (!Array.isArray(subdocument.categories) || subdocument.categories.length === 0) { | ||
console.log('Categories must be a non-empty array'); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
validateAndMerge(); |
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,24 @@ | ||
|
||
name: Auto-merge PR | ||
|
||
on: | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
|
||
jobs: | ||
auto-merge: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: '18' | ||
- name: Install dependencies | ||
run: npm install | ||
- name: Validate and auto-merge PR | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
PR_NUMBER: ${{ github.event.pull_request.number }} | ||
REPO_OWNER: ${{ github.repository_owner }} | ||
REPO_NAME: ${{ github.event.repository.name }} | ||
run: node --experimental-modules .github/scripts/validate-and-merge.mjs |
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,2 @@ | ||
|
||
node_modules |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.