pitrou commented on code in PR #55361:
URL: https://github.com/apache/arrow/pull/55361#discussion_r4468806492


##########
.github/workflows/ai_disclosure/check.js:
##########
@@ -0,0 +1,203 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+const fs = require("fs");
+
+const AUTHORSHIP_HEADING = "PR code and description written by:";
+const REVIEW_HEADING = "Reviewed before submission by:";
+
+function parseSection(lines, start, end, options) {
+  const found = new Set();
+  const selected = [];
+
+  for (const line of lines.slice(start + 1, end)) {
+    const match = line.match(/^\s*-\s+\[([ xX])\]\s*(.*?)\s*$/);
+
+    if (!match) {
+      if (/^\s*-\s+\[/.test(line)) return null;
+      continue;
+    }
+
+    const option = match[2];
+
+    if (!options.includes(option) || found.has(option)) return null;
+
+    found.add(option);
+
+    if (match[1].toLowerCase() === "x") {
+      selected.push(option);
+    }
+  }
+
+  if (
+    found.size !== options.length ||
+    selected.length === 0 ||
+    (selected.includes("Not reviewed") && selected.length > 1)
+  ) {
+    return null;
+  }
+
+  return selected;
+}
+
+function normalizeHeading(line) {
+  return line.trim().replace(/^\*\*(.*?)\*\*$/, "$1");
+}
+
+function isHeading(line) {
+  const trimmed = line.trim();
+  return /^#{1,6}\s/.test(trimmed) || /^\*\*.+\*\*$/.test(trimmed);

Review Comment:
   Same.



##########
.github/workflows/ai_disclosure/check.js:
##########
@@ -0,0 +1,203 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+const fs = require("fs");
+
+const AUTHORSHIP_HEADING = "PR code and description written by:";
+const REVIEW_HEADING = "Reviewed before submission by:";
+
+function parseSection(lines, start, end, options) {
+  const found = new Set();
+  const selected = [];
+
+  for (const line of lines.slice(start + 1, end)) {
+    const match = line.match(/^\s*-\s+\[([ xX])\]\s*(.*?)\s*$/);

Review Comment:
   Can you please add comments so that we understand what this is doing?



##########
.github/workflows/ai_disclosure/check.js:
##########
@@ -0,0 +1,203 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+const fs = require("fs");
+
+const AUTHORSHIP_HEADING = "PR code and description written by:";
+const REVIEW_HEADING = "Reviewed before submission by:";
+
+function parseSection(lines, start, end, options) {
+  const found = new Set();
+  const selected = [];
+
+  for (const line of lines.slice(start + 1, end)) {
+    const match = line.match(/^\s*-\s+\[([ xX])\]\s*(.*?)\s*$/);
+
+    if (!match) {
+      if (/^\s*-\s+\[/.test(line)) return null;

Review Comment:
   What is this testing?



##########
.github/workflows/ai_disclosure/check.js:
##########
@@ -0,0 +1,203 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+const fs = require("fs");
+
+const AUTHORSHIP_HEADING = "PR code and description written by:";
+const REVIEW_HEADING = "Reviewed before submission by:";
+
+function parseSection(lines, start, end, options) {
+  const found = new Set();
+  const selected = [];
+
+  for (const line of lines.slice(start + 1, end)) {
+    const match = line.match(/^\s*-\s+\[([ xX])\]\s*(.*?)\s*$/);
+
+    if (!match) {
+      if (/^\s*-\s+\[/.test(line)) return null;
+      continue;
+    }
+
+    const option = match[2];
+
+    if (!options.includes(option) || found.has(option)) return null;
+
+    found.add(option);
+
+    if (match[1].toLowerCase() === "x") {
+      selected.push(option);
+    }
+  }
+
+  if (
+    found.size !== options.length ||
+    selected.length === 0 ||
+    (selected.includes("Not reviewed") && selected.length > 1)
+  ) {
+    return null;
+  }
+
+  return selected;
+}
+
+function normalizeHeading(line) {
+  return line.trim().replace(/^\*\*(.*?)\*\*$/, "$1");

Review Comment:
   Please explain what this does.



##########
.github/workflows/ai_disclosure/check.js:
##########
@@ -0,0 +1,203 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+const fs = require("fs");
+
+const AUTHORSHIP_HEADING = "PR code and description written by:";
+const REVIEW_HEADING = "Reviewed before submission by:";
+
+function parseSection(lines, start, end, options) {
+  const found = new Set();
+  const selected = [];
+
+  for (const line of lines.slice(start + 1, end)) {
+    const match = line.match(/^\s*-\s+\[([ xX])\]\s*(.*?)\s*$/);
+
+    if (!match) {
+      if (/^\s*-\s+\[/.test(line)) return null;
+      continue;
+    }
+
+    const option = match[2];
+
+    if (!options.includes(option) || found.has(option)) return null;
+
+    found.add(option);
+
+    if (match[1].toLowerCase() === "x") {
+      selected.push(option);
+    }
+  }
+
+  if (
+    found.size !== options.length ||
+    selected.length === 0 ||
+    (selected.includes("Not reviewed") && selected.length > 1)
+  ) {
+    return null;
+  }
+
+  return selected;
+}
+
+function normalizeHeading(line) {
+  return line.trim().replace(/^\*\*(.*?)\*\*$/, "$1");
+}
+
+function isHeading(line) {
+  const trimmed = line.trim();
+  return /^#{1,6}\s/.test(trimmed) || /^\*\*.+\*\*$/.test(trimmed);
+}
+
+function parseDisclosure(body) {
+  const lines = body.split(/\r?\n/);
+  const headings = lines.map(normalizeHeading);
+  const authorshipStart = headings.indexOf(AUTHORSHIP_HEADING);
+  const reviewStart = headings.indexOf(REVIEW_HEADING);
+
+  if (
+    authorshipStart === -1 ||
+    reviewStart <= authorshipStart ||
+    headings.lastIndexOf(AUTHORSHIP_HEADING) !== authorshipStart ||
+    headings.lastIndexOf(REVIEW_HEADING) !== reviewStart
+  ) {
+    return {status: "incomplete"};
+  }
+
+  const reviewEnd = lines.findIndex(
+    (line, index) => index > reviewStart && isHeading(line)
+  );
+
+  const authorship = parseSection(
+    lines, authorshipStart, reviewStart, ["Human", "AI"]
+  );
+
+  const review = parseSection(
+    lines,
+    reviewStart,
+    reviewEnd === -1 ? lines.length : reviewEnd,
+    ["Human", "AI", "Not reviewed"]
+  );
+
+  if (!authorship || !review) {
+    return {status: "incomplete"};
+  }
+
+  if (review.includes("Human")) {
+    return {status: "complete"};
+  }
+
+  if (authorship.length === 1 && authorship[0] === "AI") {
+    return {status: "ai-unreviewed"};
+  }
+
+  return {status: "needs-human-review"};
+}
+
+/**
+ * Adds a comment to the pull request.
+ */
+async function createDisclosureComment(
+  github, context, pullRequestNumber, body
+) {
+  await github.rest.issues.createComment({
+    owner: context.repo.owner,
+    repo: context.repo.repo,
+    issue_number: pullRequestNumber,
+    body
+  });
+}
+
+/**
+ * Converts the pull request to Draft unless it is already a draft.
+ *
+ * @param {Object} github
+ * @param {Object} context
+ */
+async function convertToDraft(github, context) {
+  if (context.payload.pull_request.draft) return;
+
+  await github.graphql(
+    `
+      mutation ($pullRequestId: ID!) {
+        convertPullRequestToDraft(
+          input: {pullRequestId: $pullRequestId}
+        ) {
+          pullRequest {
+            id
+          }
+        }
+      }
+    `,
+    {pullRequestId: context.payload.pull_request.node_id}
+  );
+}
+
+module.exports = async ({github, context, core}) => {
+  const pullRequest = context.payload.pull_request;
+  const pullRequestNumber = pullRequest.number;
+
+  if (
+    pullRequest.state !== "open" ||
+    (pullRequest.draft && context.payload.action !== "ready_for_review") ||
+    pullRequest.user?.type === "Bot"
+  ) {
+    core.info(`Skipping #${pullRequestNumber}: not an eligible pull request.`);
+    return;
+  }
+
+  const result = parseDisclosure(pullRequest.body || "");
+
+  core.info(`Disclosure status for #${pullRequestNumber}: ${result.status}.`);
+
+  if (result.status === "complete") {
+    return;
+  }
+
+  if (result.status === "ai-unreviewed") {
+    await createDisclosureComment(
+      github,
+      context,
+      pullRequestNumber,
+      `This pull request has been automatically closed because its authorship 
is AI-only and it has no human review.

Review Comment:
   I'm not sure why we're closing here but we're converting to draft below.



##########
.github/workflows/ai_disclosure/incomplete.md:
##########
@@ -0,0 +1,43 @@
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+
+<!-- arrow-ai-disclosure-check -->
+
+The AI disclosure in this pull request is missing or incomplete.
+
+Please complete both disclosure sections in the pull request description by 
selecting the applicable checkboxes.
+
+If the disclosure is not present, add the following to your pull request 
description:
+
+```markdown

Review Comment:
   Can we consider linking to the PR template instead of duplicating its text 
here? We don't want to end up with two desynchronized versions of the same text.



##########
.github/workflows/ai_disclosure.yml:
##########
@@ -0,0 +1,55 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+name: AI Disclosure
+
+on:
+  pull_request_target:

Review Comment:
   According to 
https://lists.apache.org/thread.html/dmdc8n8oyonyxhw0fjc13zxqx90rfq1m, we need 
to migrate away from `pull_request_target`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to