You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2022/03/03 16:42:49 UTC

[GitHub] [beam] damccorm opened a new pull request #17001: [BEAM-13925] Find and address prs that havent been reviewed in a week

damccorm opened a new pull request #17001:
URL: https://github.com/apache/beam/pull/17001


   Right now, we don't have a well defined automated system for staying on top of pull request reviews - we rely on contributors being able to find the correct OWNERS file and committers manually triaging/calling attention to old pull requests. This is the continuation of an effort to improve our automation around this. [Design doc for the full effort here](https://docs.google.com/document/d/1FhRPRD6VXkYlLAPhNfZB7y2Yese2FCWBzjx67d3TjBo/edit#).
   
   This specific change adds automation to flag prs that should be receiving attention but aren't. There are basically 3 parts:
   
   1) Find prs that are assigned to a reviewer and haven't had action in 7 days - tag the reviewers and add a slow-review label.
   2) Find prs with the slow-review label that haven't had action in 2 additional business days - assign a new set of **committers**
   3) Remove the slow-review label any time a reviewer performs a review or comments on the pr.
   
   This was tested in my test repo here - https://github.com/damccorm/beam-pr-bot-demo. I lowered the time thresholds so I didn't have to wait for a PR to sit for days to test it. The only eligible PR for the automation was initially https://github.com/damccorm/beam-pr-bot-demo/pull/4, so that's where most of the testing happened. There's a lot of junk in between the start and finish as I was getting things working, but the last couple comments show it working. The other prs show that they get excluded correctly (either because they've had notifications silenced or they have not had reviewers assigned by the bot for other reasons.
   
   ------------------------
   
   Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
   
    - [ ] [**Choose reviewer(s)**](https://beam.apache.org/contribute/#make-your-change) and mention them in a comment (`R: @username`).
    - [ ] Format the pull request title like `[BEAM-XXX] Fixes bug in ApproximateQuantiles`, where you replace `BEAM-XXX` with the appropriate JIRA issue, if applicable. This will automatically link the pull request to the issue.
    - [ ] Update `CHANGES.md` with noteworthy changes.
    - [ ] If this contribution is large, please file an Apache [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
   
   See the [Contributor Guide](https://beam.apache.org/contribute) for more tips on [how to make review process smoother](https://beam.apache.org/contribute/#make-reviewers-job-easier).
   
   To check the build health, please visit [https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md](https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md)
   
   GitHub Actions Tests Status (on master branch)
   ------------------------------------------------------------------------------------------------
   [![Build python source distribution and wheels](https://github.com/apache/beam/workflows/Build%20python%20source%20distribution%20and%20wheels/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Build+python+source+distribution+and+wheels%22+branch%3Amaster+event%3Aschedule)
   [![Python tests](https://github.com/apache/beam/workflows/Python%20tests/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Python+Tests%22+branch%3Amaster+event%3Aschedule)
   [![Java tests](https://github.com/apache/beam/workflows/Java%20Tests/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Java+Tests%22+branch%3Amaster+event%3Aschedule)
   
   See [CI.md](https://github.com/apache/beam/blob/master/CI.md) for more information about GitHub Actions CI.
   


-- 
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [beam] KonradJanica commented on a change in pull request #17001: [BEAM-13925] Find and address prs that havent been reviewed in a week

Posted by GitBox <gi...@apache.org>.
KonradJanica commented on a change in pull request #17001:
URL: https://github.com/apache/beam/pull/17001#discussion_r821072062



##########
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()) {

Review comment:
       ```
   return pull.labels.some(label => label.name.toLowerCase() === labelName.toLowerCase())
   ```

##########
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);

Review comment:
       Please store this duration in a constant with appropriate naming, e.g. `TWO_DAYS_MS`

##########
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);

Review comment:
       `let` => `const`

##########
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);

Review comment:
       Reuse constant mentioned in comment above.

##########
File path: scripts/ci/pr-bot/shared/commentStrings.ts
##########
@@ -70,3 +70,33 @@ export function reviewersAlreadyAssigned(reviewers: string[]): string {
 export function noLegalReviewers(): string {
   return "No reviewers could be found from any of the labels on the PR or in the fallback reviewers list. Check the config file to make sure reviewers are configured";
 }
+
+export function assignNewReviewer(labelToReviewerMapping: any): string {
+  let commentString =
+    "Assigning new set of reviewers because Pr has gone too long without review. If you would like to opt out of this review, comment `assign to next reviewer`:\n\n";
+
+  for (let label in labelToReviewerMapping) {
+    let reviewer = labelToReviewerMapping[label];
+    if (label == "no-matching-label") {

Review comment:
       Triple equals for string matching. Should `"no-matching-label"` be a reusable constant?

##########
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:
       Is `typeof` needed here?

##########
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) {

Review comment:
       These conditions are mutually exclusive, `if` => `else if`

##########
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:
       Is `typeof` needed here?

##########
File path: scripts/ci/pr-bot/processPrUpdate.ts
##########
@@ -46,6 +76,11 @@ async function processPrComment(
 ) {
   const commentContents = payload.comment.body;
   const commentAuthor = payload.sender.login;
+  const pullAuthor = getPullAuthorFromPayload(payload);
+  // If there's been a comment by a non-author, we can remove the slow review label
+  if (commentAuthor !== pullAuthor && commentAuthor !== BOT_NAME) {
+    payload = await removeSlowReviewLabel(payload);

Review comment:
       Don't override the input parameter, there is no benefit, the caller will still reference the existing object. I was expecting the `payload` to be returned but I didn't see that. On a side note, modifying the input parameter is okay for private/unexported methods, but it can be a code smell.

##########
File path: scripts/ci/pr-bot/processPrUpdate.ts
##########
@@ -84,6 +118,12 @@ async function processPrReview(
   stateClient: typeof PersistentState,
   reviewerConfig: typeof ReviewerConfig
 ) {
+  const reviewer = payload.sender.login;
+  const pullAuthor = getPullAuthorFromPayload(payload);
+  // If there's been a review by a non-author, we can remove the slow review label
+  if (reviewer !== pullAuthor) {
+    payload = await removeSlowReviewLabel(payload);

Review comment:
       Ditto, as above. Don't reassign `payload`.

##########
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
+) {
+  let prState = await stateClient.getPrState(pull.number);
+  let reviewerStateToUpdate = {};
+  const labelObjects = pull.labels;
+  let reviewersToExclude = Object.values(prState.reviewersAssignedForLabels);
+  reviewersToExclude.push(pull.user.login);
+  const reviewersForLabels: { [key: string]: string[] } =
+    reviewerConfig.getReviewersForLabels(labelObjects, reviewersToExclude);
+  for (const labelObject of labelObjects) {
+    const label = labelObject.name;
+    let availableReviewers = reviewersForLabels[label];
+    if (availableReviewers && availableReviewers.length > 0) {
+      let reviewersState = await stateClient.getReviewersForLabelState(label);
+      let chosenReviewer = await reviewersState.assignNextCommitter(
+        availableReviewers
+      );
+      reviewerStateToUpdate[label] = reviewersState;
+      prState.reviewersAssignedForLabels[label] = chosenReviewer;
+    }
+  }
+
+  console.log(`Assigning new reviewers for pr ${pull.number}`);
+  await github.addPrComment(
+    pull.number,
+    commentStrings.assignNewReviewer(prState.reviewersAssignedForLabels)
+  );
+
+  await stateClient.writePrState(pull.number, prState);
+  let labelsToUpdate = Object.keys(reviewerStateToUpdate);
+  for (const label of labelsToUpdate) {
+    await stateClient.writeReviewersForLabelState(
+      label,
+      reviewerStateToUpdate[label]
+    );
+  }
+}
+
+// Flag any prs that have been awaiting reviewer action at least 7 days,
+// or have been awaiting initial review for at least 2 days and ping the reviewers
+// If there's still no action after 2 more days, assign a new set of committers.
+async function processPull(
+  pull: any,
+  reviewerConfig: typeof ReviewerConfig,
+  stateClient: typeof PersistentState
+) {
+  const prState = await stateClient.getPrState(pull.number);
+  if (prState.stopReviewerNotifications) {
+    console.log(`Skipping PR ${pull.number} - notifications silenced`);
+    return;
+  }
+  if (hasLabel(pull, SLOW_REVIEW_LABEL)) {
+    const lastModified = new Date(pull.updated_at);
+    const twoWeekDaysAgo = getTwoWeekdaysAgo();
+    console.log(
+      `PR ${pull.number} has the slow review label. Last modified ${lastModified}`
+    );
+    if (lastModified.getTime() < twoWeekDaysAgo.getTime()) {
+      console.log(
+        `PR ${pull.number} still awaiting action - assigning new reviewers`
+      );
+      await assignToNewReviewers(pull, reviewerConfig, stateClient);
+      await github.getGitHubClient().rest.issues.removeLabel({
+        owner: REPO_OWNER,
+        repo: REPO,
+        issue_number: pull.number,
+        name: SLOW_REVIEW_LABEL,
+      });
+    }
+
+    return;
+  }
+
+  if (await isSlowReview(pull)) {
+    const client = github.getGitHubClient();
+    const currentReviewers = prState.reviewersAssignedForLabels;
+    if (currentReviewers && Object.values(currentReviewers).length > 0) {
+      console.log(
+        `Flagging pr ${pull.number} as slow. Tagging reviewers ${currentReviewers}`
+      );
+      await github.addPrComment(
+        pull.number,
+        commentStrings.slowReview(Object.values(currentReviewers))
+      );
+      await client.rest.issues.addLabels({
+        owner: REPO_OWNER,
+        repo: REPO,
+        issue_number: pull.number,
+        labels: [SLOW_REVIEW_LABEL],
+      });
+    }
+  }
+}
+
+async function processOldPrs() {
+  const githubClient = github.getGitHubClient();
+  let reviewerConfig = new ReviewerConfig(PATH_TO_CONFIG_FILE);
+  let stateClient = new PersistentState();
+
+  let openPulls = await githubClient.paginate(
+    "GET /repos/{owner}/{repo}/pulls",
+    {
+      owner: REPO_OWNER,
+      repo: REPO,
+    }
+  );
+
+  for (let i = 0; i < openPulls.length; i++) {

Review comment:
       Index unused => `for (const pull of openPulls)`

##########
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;
+      }

Review comment:
       ```
   if (reviewComments.some(({user: login}) => login !== pullAuthor && login !== BOT_NAME)) {
      return false;
   }
   ```
   
   After unnesting, this becomes the last return.

##########
File path: scripts/ci/pr-bot/shared/commentStrings.ts
##########
@@ -70,3 +70,33 @@ export function reviewersAlreadyAssigned(reviewers: string[]): string {
 export function noLegalReviewers(): string {
   return "No reviewers could be found from any of the labels on the PR or in the fallback reviewers list. Check the config file to make sure reviewers are configured";
 }
+
+export function assignNewReviewer(labelToReviewerMapping: any): string {

Review comment:
       `labelToReviewerMapping` shouldn't use `any`, is there a defined type?

##########
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()) {

Review comment:
       Perhaps unnest this block and directly return false. i.e.
   ```
   if (lastModified.getTime() >= twoWeekDaysAgo.getTime()) {
      return false;
   }
   ```

##########
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;
+      }

Review comment:
       ```
   if (comments.some(({user: login}) => login !== pullAuthor && login !== BOT_NAME)) {
      return false;
   }
   ```

##########
File path: scripts/ci/pr-bot/shared/commentStrings.ts
##########
@@ -70,3 +70,33 @@ export function reviewersAlreadyAssigned(reviewers: string[]): string {
 export function noLegalReviewers(): string {
   return "No reviewers could be found from any of the labels on the PR or in the fallback reviewers list. Check the config file to make sure reviewers are configured";
 }
+
+export function assignNewReviewer(labelToReviewerMapping: any): string {
+  let commentString =
+    "Assigning new set of reviewers because Pr has gone too long without review. If you would like to opt out of this review, comment `assign to next reviewer`:\n\n";
+
+  for (let label in labelToReviewerMapping) {
+    let reviewer = labelToReviewerMapping[label];
+    if (label == "no-matching-label") {
+      commentString += `R: @${reviewer} added as fallback since no labels match configuration\n`;
+    } else {
+      commentString += `R: @${reviewer} for label ${label}.\n`;
+    }
+  }
+
+  commentString += `
+Available commands:
+- \`stop reviewer notifications\` - opt out of the automated review tooling
+- \`remind me after tests pass\` - tag the comment author after tests pass
+- \`waiting on author\` - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)`;
+  return commentString;
+}
+
+export function slowReview(reviewers: string[]): string {
+  let commentString = `Reminder, please take a look at this pr: `;
+  reviewers.forEach((reviewer) => {

Review comment:
       `for (const reviewer of reviewers)` is the preferred syntax.




-- 
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [beam] damccorm commented on a change in pull request #17001: [BEAM-13925] Find and address prs that havent been reviewed in a week

Posted by GitBox <gi...@apache.org>.
damccorm commented on a change in pull request #17001:
URL: https://github.com/apache/beam/pull/17001#discussion_r820730728



##########
File path: .github/workflows/pr-bot-new-prs.yml
##########
@@ -18,7 +18,7 @@ name: pr-bot-new-prs
 # Run every 30 minutes
 on:
   schedule:
-  - cron: '30 * * * *'
+  - cron: '0,30 * * * *'

Review comment:
       This is technically not part of the goal of this pr, but I noticed that the cron schedule was running once an hour instead of twice an hour for the pr-bot-new-prs workflow




-- 
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [beam] damccorm commented on pull request #17001: [BEAM-13925] Find and address prs that havent been reviewed in a week

Posted by GitBox <gi...@apache.org>.
damccorm commented on pull request #17001:
URL: https://github.com/apache/beam/pull/17001#issuecomment-1061172737


   R: @youngoli for final review


-- 
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [beam] damccorm edited a comment on pull request #17001: [BEAM-13925] Find and address prs that havent been reviewed in a week

Posted by GitBox <gi...@apache.org>.
damccorm edited a comment on pull request #17001:
URL: https://github.com/apache/beam/pull/17001#issuecomment-1060716741


   R: @KonradJanica - would you mind taking a look at the TypeScript changes?


-- 
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [beam] damccorm commented on a change in pull request #17001: [BEAM-13925] Find and address prs that havent been reviewed in a week

Posted by GitBox <gi...@apache.org>.
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [beam] damccorm commented on pull request #17001: [BEAM-13925] Find and address prs that havent been reviewed in a week

Posted by GitBox <gi...@apache.org>.
damccorm commented on pull request #17001:
URL: https://github.com/apache/beam/pull/17001#issuecomment-1060716741


   R: @KonradJanica - would you mind taking a look?


-- 
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [beam] youngoli merged pull request #17001: [BEAM-13925] Find and address prs that havent been reviewed in a week

Posted by GitBox <gi...@apache.org>.
youngoli merged pull request #17001:
URL: https://github.com/apache/beam/pull/17001


   


-- 
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org