damccorm commented on a change in pull request #17001:
URL: https://github.com/apache/beam/pull/17001#discussion_r821119491



##########
File path: scripts/ci/pr-bot/findPrsNeedingAttention.ts
##########
@@ -0,0 +1,228 @@
+/*
+ * 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 github = require("./shared/githubUtils");
+const commentStrings = require("./shared/commentStrings");
+const { ReviewerConfig } = require("./shared/reviewerConfig");
+const { PersistentState } = require("./shared/persistentState");
+const {
+  BOT_NAME,
+  REPO_OWNER,
+  REPO,
+  PATH_TO_CONFIG_FILE,
+  SLOW_REVIEW_LABEL,
+} = require("./shared/constants");
+
+function hasLabel(pull: any, labelName: string): boolean {
+  const labels = pull.labels;
+  for (const label of labels) {
+    if (label.name.toLowerCase() === labelName.toLowerCase()) {
+      return true;
+    }
+  }
+  return false;
+}
+
+function getTwoWeekdaysAgo(): Date {
+  let twoWeekDaysAgo = new Date(Date.now() - 2 * 24 * 60 * 60 * 1000);
+  const currentDay = new Date(Date.now()).getDay();
+  // If Saturday, sunday, monday, or tuesday, add extra time to account for 
weekend.
+  if (currentDay === 6) {
+    twoWeekDaysAgo.setDate(twoWeekDaysAgo.getDate() - 1);
+  }
+  if (currentDay <= 2) {
+    twoWeekDaysAgo.setDate(twoWeekDaysAgo.getDate() - 2);
+  }
+
+  return twoWeekDaysAgo;
+}
+
+async function isSlowReview(pull: any): Promise<boolean> {
+  if (!hasLabel(pull, "Next Action: Reviewers")) {
+    return false;
+  }
+  const lastModified = new Date(pull.updated_at);
+  const sevenDaysAgo = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000);
+  if (lastModified.getTime() < sevenDaysAgo.getTime()) {
+    return true;
+  }
+
+  // If it has no comments from a non-bot/author in the last 2 weekdays, 
return true
+  const twoWeekDaysAgo = getTwoWeekdaysAgo();
+  if (lastModified.getTime() < twoWeekDaysAgo.getTime()) {
+    const pullAuthor = pull.user.login;
+    const githubClient = github.getGitHubClient();
+    const comments = (
+      await githubClient.rest.issues.listComments({
+        owner: REPO_OWNER,
+        repo: REPO,
+        issue_number: pull.number,
+      })
+    ).data;
+    for (let i = 0; i < comments.length; i++) {
+      const comment = comments[i];
+      if (
+        comment.user.login !== pullAuthor &&
+        comment.user.login !== BOT_NAME
+      ) {
+        return false;
+      }
+    }
+
+    const reviewComments = (
+      await githubClient.rest.pulls.listReviewComments({
+        owner: REPO_OWNER,
+        repo: REPO,
+        pull_number: pull.number,
+      })
+    ).data;
+    for (let i = 0; i < reviewComments.length; i++) {
+      const comment = reviewComments[i];
+      if (
+        comment.user.login !== pullAuthor &&
+        comment.user.login !== BOT_NAME
+      ) {
+        return false;
+      }
+    }
+
+    return true;
+  }
+
+  return false;
+}
+
+async function assignToNewReviewers(
+  pull: any,
+  reviewerConfig: typeof ReviewerConfig,

Review comment:
       Yeah, it is - if I remove it, `tsc` errors with `'ReviewerConfig' refers 
to a value, but is being used as a type here. Did you mean 'typeof 
ReviewerConfig'?`

##########
File path: scripts/ci/pr-bot/findPrsNeedingAttention.ts
##########
@@ -0,0 +1,228 @@
+/*
+ * 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 github = require("./shared/githubUtils");
+const commentStrings = require("./shared/commentStrings");
+const { ReviewerConfig } = require("./shared/reviewerConfig");
+const { PersistentState } = require("./shared/persistentState");
+const {
+  BOT_NAME,
+  REPO_OWNER,
+  REPO,
+  PATH_TO_CONFIG_FILE,
+  SLOW_REVIEW_LABEL,
+} = require("./shared/constants");
+
+function hasLabel(pull: any, labelName: string): boolean {
+  const labels = pull.labels;
+  for (const label of labels) {
+    if (label.name.toLowerCase() === labelName.toLowerCase()) {
+      return true;
+    }
+  }
+  return false;
+}
+
+function getTwoWeekdaysAgo(): Date {
+  let twoWeekDaysAgo = new Date(Date.now() - 2 * 24 * 60 * 60 * 1000);
+  const currentDay = new Date(Date.now()).getDay();
+  // If Saturday, sunday, monday, or tuesday, add extra time to account for 
weekend.
+  if (currentDay === 6) {
+    twoWeekDaysAgo.setDate(twoWeekDaysAgo.getDate() - 1);
+  }
+  if (currentDay <= 2) {
+    twoWeekDaysAgo.setDate(twoWeekDaysAgo.getDate() - 2);
+  }
+
+  return twoWeekDaysAgo;
+}
+
+async function isSlowReview(pull: any): Promise<boolean> {
+  if (!hasLabel(pull, "Next Action: Reviewers")) {
+    return false;
+  }
+  const lastModified = new Date(pull.updated_at);
+  const sevenDaysAgo = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000);
+  if (lastModified.getTime() < sevenDaysAgo.getTime()) {
+    return true;
+  }
+
+  // If it has no comments from a non-bot/author in the last 2 weekdays, 
return true
+  const twoWeekDaysAgo = getTwoWeekdaysAgo();
+  if (lastModified.getTime() < twoWeekDaysAgo.getTime()) {
+    const pullAuthor = pull.user.login;
+    const githubClient = github.getGitHubClient();
+    const comments = (
+      await githubClient.rest.issues.listComments({
+        owner: REPO_OWNER,
+        repo: REPO,
+        issue_number: pull.number,
+      })
+    ).data;
+    for (let i = 0; i < comments.length; i++) {
+      const comment = comments[i];
+      if (
+        comment.user.login !== pullAuthor &&
+        comment.user.login !== BOT_NAME
+      ) {
+        return false;
+      }
+    }
+
+    const reviewComments = (
+      await githubClient.rest.pulls.listReviewComments({
+        owner: REPO_OWNER,
+        repo: REPO,
+        pull_number: pull.number,
+      })
+    ).data;
+    for (let i = 0; i < reviewComments.length; i++) {
+      const comment = reviewComments[i];
+      if (
+        comment.user.login !== pullAuthor &&
+        comment.user.login !== BOT_NAME
+      ) {
+        return false;
+      }
+    }
+
+    return true;
+  }
+
+  return false;
+}
+
+async function assignToNewReviewers(
+  pull: any,
+  reviewerConfig: typeof ReviewerConfig,
+  stateClient: typeof PersistentState

Review comment:
       Same - `tsc` will throw if I don't do this




-- 
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