mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-26 12:08:37 +08:00
Improve comment processing in filter-links workflow
Refactor comment handling and logging for GitHub repo link filtering.
This commit is contained in:
51
.github/workflows/filter-links.yml
vendored
51
.github/workflows/filter-links.yml
vendored
@@ -19,24 +19,35 @@ jobs:
|
||||
with:
|
||||
script: |
|
||||
const comment = context.payload.comment;
|
||||
if (!comment) return;
|
||||
|
||||
const body = comment.body;
|
||||
|
||||
// Regex for GitHub repo links
|
||||
const githubRepoRegex = /https?:\/\/github\.com\/[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+(?:[^\s]*)?/gi;
|
||||
|
||||
if (githubRepoRegex.test(body)) {
|
||||
const sanitized = body.replace(
|
||||
githubRepoRegex,
|
||||
"Links to external GitHub repositories are not allowed"
|
||||
);
|
||||
|
||||
await github.rest.issues.updateComment({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
comment_id: comment.id,
|
||||
body: sanitized
|
||||
});
|
||||
if (!comment) {
|
||||
console.log("No comment found in payload");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
console.log("Original comment body:", comment.body);
|
||||
|
||||
const githubRepoRegex = /https?:\/\/github\.com\/[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+(?:[^\s]*)?/gi;
|
||||
|
||||
const matches = comment.body.match(githubRepoRegex);
|
||||
console.log("Regex matches:", matches);
|
||||
|
||||
if (!matches) {
|
||||
console.log("No GitHub repo links found — nothing to replace");
|
||||
return;
|
||||
}
|
||||
|
||||
const sanitized = comment.body.replace(
|
||||
githubRepoRegex,
|
||||
"Links to external GitHub repositories are not allowed"
|
||||
);
|
||||
|
||||
console.log("Sanitized body:", sanitized);
|
||||
|
||||
await github.rest.issues.updateComment({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
comment_id: comment.id,
|
||||
body: sanitized
|
||||
});
|
||||
|
||||
console.log("Comment updated successfully");
|
||||
|
||||
Reference in New Issue
Block a user