forked from duckduckgo/privacy-configuration
-
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
1 parent
4d63cfb
commit 959174c
Showing
5 changed files
with
199 additions
and
6 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,65 @@ | ||
const { Octokit } = require('@octokit/rest'); | ||
const fs = require('fs'); | ||
|
||
const githubToken = process.env.GITHUB_TOKEN; | ||
const repoFullName = process.env.GITHUB_REPOSITORY; | ||
const [owner, repo] = repoFullName.split('/'); | ||
const prNumber = process.env.GITHUB_EVENT_PATH; | ||
|
||
const octokit = new Octokit({ | ||
auth: githubToken, | ||
}); | ||
|
||
async function postComment(pr) { | ||
const diffOutput = fs.readFileSync('diff_output.txt', 'utf-8'); | ||
|
||
const commentBody = ` | ||
Integration script output: | ||
\`\`\`diff | ||
${diffOutput} | ||
\`\`\` | ||
`; | ||
|
||
if (quotes.length > 0 || diffOutput) { | ||
await octokit.rest.issues.createComment({ | ||
owner, | ||
repo, | ||
issue_number: pr.number, | ||
body: commentBody, | ||
}); | ||
} | ||
} | ||
|
||
async function main() { | ||
/* | ||
const pr = await octokit.rest.pulls.get({ | ||
owner, | ||
repo, | ||
pull_number: prNumber, | ||
});*/ | ||
|
||
const diffOutput = fs.readFileSync('diff_output.txt', 'utf-8'); | ||
|
||
const commentBody = ` | ||
Integration script output: | ||
\`\`\`diff | ||
${diffOutput} | ||
\`\`\` | ||
`; | ||
await octokit.rest.issues.createComment({ | ||
owner, | ||
repo, | ||
issue_number: prNumber, | ||
body: commentBody, | ||
}); | ||
|
||
const prBody = pr.data.body; | ||
await postComment(pr.data); | ||
} | ||
|
||
main().catch((err) => { | ||
console.error(err); | ||
process.exit(1); | ||
}); |
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,57 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const diff = require('diff'); | ||
|
||
function readFilesRecursively(directory) { | ||
const filenames = fs.readdirSync(directory); | ||
const files = {}; | ||
|
||
filenames.forEach((filename) => { | ||
const filePath = path.join(directory, filename); | ||
const fileStats = fs.statSync(filePath); | ||
|
||
if (fileStats.isDirectory()) { | ||
const nestedFiles = readFilesRecursively(filePath); | ||
for (const [nestedFilePath, nestedFileContent] of Object.entries(nestedFiles)) { | ||
files[path.join(filename, nestedFilePath)] = nestedFileContent; | ||
} | ||
} else { | ||
files[filename] = fs.readFileSync(filePath, 'utf-8'); | ||
} | ||
}); | ||
|
||
return files; | ||
} | ||
|
||
function displayDiffs(dir1Files, dir2Files) { | ||
for (const [filePath, fileContent] of Object.entries(dir1Files)) { | ||
if (dir2Files.hasOwnProperty(filePath)) { | ||
const fileDiff = diff.createPatch(filePath, fileContent, dir2Files[filePath]); | ||
|
||
if (fileDiff) { | ||
console.log(fileDiff); | ||
} | ||
|
||
delete dir2Files[filePath]; | ||
} else { | ||
console.log(`File ${filePath} only exists in directory 1`); | ||
} | ||
} | ||
|
||
for (const filePath of Object.keys(dir2Files)) { | ||
console.log(`File ${filePath} only exists in directory 2`); | ||
} | ||
} | ||
|
||
if (process.argv.length !== 4) { | ||
console.error('Usage: node diff_directories.js <directory1> <directory2>'); | ||
process.exit(1); | ||
} | ||
|
||
const dir1 = process.argv[2]; | ||
const dir2 = process.argv[3]; | ||
|
||
const dir1Files = readFilesRecursively(dir1); | ||
const dir2Files = readFilesRecursively(dir2); | ||
|
||
displayDiffs(dir1Files, dir2Files); |
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,54 @@ | ||
name: Auto Respond to PR | ||
|
||
on: | ||
pull_request: | ||
types: | ||
- opened | ||
- synchronize | ||
|
||
jobs: | ||
auto_respond: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
with: | ||
ref: main | ||
repository: ${{ github.event.pull_request.head.repo.full_name }} | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Build main | ||
run: | | ||
node index.js | ||
- name: Copy main generated output to tmp | ||
run: | | ||
cp -r generated ${{ runner.temp }} | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
with: | ||
ref: ${{ github.event.pull_request.head.ref }} | ||
repository: ${{ github.event.pull_request.head.repo.full_name }} | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Build branch | ||
run: | | ||
node index.js | ||
- name: Install dependencies | ||
run: | | ||
npm install @octokit/rest | ||
- name: Run diff script | ||
run: node .github/scripts/diff-directories.js ${{ runner.temp }}/generated/ generated/ > diff_output.txt | ||
|
||
- uses: github-actions-up-and-running/pr-comment@f1f8ab2bf00dce6880a369ce08758a60c61d6c0b | ||
with: | ||
repo-token: ${{ secrets.GITHUB_TOKEN }} | ||
message: "$( cat diff_output.txt )" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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