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



##########
File path: scripts/ci/pr-bot/processPrUpdate.ts
##########
@@ -0,0 +1,198 @@
+/*
+ * 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("@actions/github");
+const commentStrings = require("./shared/commentStrings");
+const { processCommand } = require("./shared/userCommand");
+const { addPrComment, nextActionReviewers } = require("./shared/githubUtils");
+const { PersistentState } = require("./shared/persistentState");
+const { ReviewerConfig } = require("./shared/reviewerConfig");
+const { PATH_TO_CONFIG_FILE } = require("./shared/constants");
+
+async function areReviewersAssigned(
+  pullNumber: number,
+  stateClient: typeof PersistentState
+): Promise<boolean> {
+  const prState = await stateClient.getPrState(pullNumber);
+  return Object.values(prState.reviewersAssignedForLabels).length > 0;
+}
+
+async function processPrComment(
+  payload,
+  stateClient: typeof PersistentState,
+  reviewerConfig: typeof ReviewerConfig
+) {
+  const commentContents = payload.comment.body;
+  const commentAuthor = payload.sender.login;
+  console.log(commentContents);
+  if (
+    await processCommand(
+      payload,
+      commentAuthor,
+      commentContents,
+      stateClient,
+      reviewerConfig
+    )
+  ) {
+    // If we've processed a command, don't worry about trying to change the 
attention set.
+    // This is not a meaningful push or comment from the author.
+    console.log("Processed command");
+    return;
+  }
+
+  // If comment was from the author, we should shift attention back to the 
reviewers.
+  console.log(
+    "No command to be processed, checking if we should shift attention to 
reviewers"
+  );
+  const pullAuthor =
+    payload.issue?.user?.login || payload.pull_request?.user?.login;
+  if (pullAuthor == commentAuthor) {
+    await setNextActionReviewers(payload, stateClient);
+  } else {
+    console.log(
+      `Comment was from ${commentAuthor}, not author: ${pullAuthor}. No action 
to take.`
+    );
+  }
+}
+
+// On approval from a reviewer we have assigned, assign committer if one not 
already assigned
+async function processPrReview(
+  payload,
+  stateClient: typeof PersistentState,
+  reviewerConfig: typeof ReviewerConfig
+) {
+  if (payload.review.state != "approved") {
+    return;
+  }
+
+  const pullNumber = payload.issue?.number || payload.pull_request?.number;
+  if (!(await areReviewersAssigned(pullNumber, stateClient))) {
+    return;
+  }
+
+  let prState = await stateClient.getPrState(pullNumber);

Review comment:
       This is modified later on




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