Skip to content

SearXNG is a free internet metasearch engine which aggregates results from various search services and databases. Users are neither tracked nor profiled.

[enh] ci: convert script to esm (#6725)

Ivan Gabaldon12f8b6515ca7
diff --git a/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md
similarity index 100%
rename from PULL_REQUEST_TEMPLATE.md
rename to .github/PULL_REQUEST_TEMPLATE.md
diff --git a/.github/scripts/aiPolicy.mjs b/.github/scripts/aiPolicy.mjs
new file mode 100644
index 000000000..1534ec02e
--- /dev/null
+++ b/.github/scripts/aiPolicy.mjs
@@ -0,0 +1,41 @@
+// @ts-check
+// Closes issues and prs whose authors/agents don't accept the ai policy
+// https://github.com/searxng/searxng/blob/master/AI_POLICY.rst
+
+const boxCocRegex = /\[\s*[Xx]\s*\].*AI Policy/;
+const refCocRegex = /\[AI Policy\](?::\s*|\()https:\/\/github\.com\/searxng\/searxng\/.*AI_POLICY/;
+
+export default async ({ github, context }) => {
+ const item = context.payload.issue ?? context.payload.pull_request;
+ if (!item?.body) {
+ return;
+ }
+
+ if (boxCocRegex.test(item.body) && refCocRegex.test(item.body)) {
+ return;
+ }
+
+ const type = context.payload.issue ? "issue" : "pull request";
+
+ await github.rest.issues.createComment({
+ issue_number: item.number,
+ body: `Hello! Thank you for your contribution.
+
+Unfortunately your ${type} was closed as the AI Policy has not been accepted.
+Please open a new ${type} after confirming your contribution aligns with our AI Policy.`,
+ ...context.repo
+ });
+
+ await github.rest.issues.addLabels({
+ issue_number: item.number,
+ labels: ["invalid:slop"],
+ ...context.repo
+ });
+
+ await github.rest.issues.update({
+ issue_number: item.number,
+ state: "closed",
+ state_reason: "not_planned",
+ ...context.repo
+ });
+};
diff --git a/.github/scripts/ai_policy.cjs b/.github/scripts/ai_policy.cjs
deleted file mode 100644
index 5a5e49e71..000000000
--- a/.github/scripts/ai_policy.cjs
+++ /dev/null
@@ -1,39 +0,0 @@
-// Closes issues and prs whose authors/agents don't accept the ai policy
-// https://github.com/searxng/searxng/blob/master/AI_POLICY.rst
-
-module.exports = async ({ github, context }) => {
- const item = context.payload.pull_request || context.payload.issue;
- const body = item.body || '';
- const kind = context.payload.pull_request ? 'pull request' : 'issue';
-
- // https://github.com/searxng/searxng/pull/6476#discussion_r3683782481
- const hasBox = /\[[Xx]\].*AI Policy/.test(body);
- const hasRef = /\[AI Policy\](?::\s*|\()https:\/\/github\.com\/searxng\/searxng\/.*AI_POLICY/.test(body);
- if (hasBox && hasRef) {
- return;
- }
-
- const { owner, repo } = context.repo;
- await github.rest.issues.createComment({
- owner,
- repo,
- issue_number: item.number,
- body:
- 'Hello! Thank you for your contribution.\n\n' +
- `Unfortunately your ${kind} was closed as the AI Policy has not been accepted.\n\n` +
- `Please open a new ${kind} after confirming your contribution aligns with our AI Policy.`,
- });
- await github.rest.issues.addLabels({
- owner,
- repo,
- issue_number: item.number,
- labels: ['invalid:slop'],
- });
- await github.rest.issues.update({
- owner,
- repo,
- issue_number: item.number,
- state: 'closed',
- state_reason: 'not_planned',
- });
-};
diff --git a/.github/workflows/ai-policy.yml b/.github/workflows/ai-policy.yml
index 698ce4f9d..16bc4ac7d 100644
--- a/.github/workflows/ai-policy.yml
+++ b/.github/workflows/ai-policy.yml
@@ -18,7 +18,7 @@ permissions:
jobs:
check:
- name: Check AI Policy
+ name: Check
# for issues with an author who has not contributed before
if: >-
github.event.sender.type != 'Bot' &&
@@ -34,5 +34,5 @@ jobs:
- uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
- const script = require('./.github/scripts/ai_policy.cjs');
- await script({ github, context });
+ const script = await import("${{ github.workspace }}/.github/scripts/aiPolicy.mjs")
+ await script.default({ github, context });