[ 
https://issues.apache.org/jira/browse/BEAM-13925?focusedWorklogId=731785&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-731785
 ]

ASF GitHub Bot logged work on BEAM-13925:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 23/Feb/22 18:39
            Start Date: 23/Feb/22 18:39
    Worklog Time Spent: 10m 
      Work Description: KonradJanica commented on a change in pull request 
#16898:
URL: https://github.com/apache/beam/pull/16898#discussion_r813199389



##########
File path: scripts/ci/pr-bot/shared/githubUtils.ts
##########
@@ -0,0 +1,96 @@
+/*
+ * 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 { Octokit } = require("@octokit/rest");
+const { REPO_OWNER, REPO } = require("./constants");
+
+export function getGitHubClient() {
+  let githubToken = process.env["GITHUB_TOKEN"];
+  if (!githubToken) {
+    throw new Error(
+      "No github token provided - process.env['GITHUB_TOKEN'] must be set."
+    );
+  }
+  return new Octokit({ auth: githubToken });
+}
+
+export async function addPrComment(pullNumber: number, body: string) {
+  const githubClient = getGitHubClient();
+  await githubClient.rest.issues.createComment({
+    owner: REPO_OWNER,
+    repo: REPO,
+    issue_number: pullNumber,
+    body: body,
+  });
+}
+
+export async function nextActionReviewers(
+  pullNumber: number,
+  existingLabels: any[]
+) {
+  const client = getGitHubClient();
+  let newLabels = removeNextActionLabel(existingLabels);
+  newLabels.push("Next Action: Reviewers");
+  await client.rest.issues.setLabels({
+    owner: REPO_OWNER,
+    repo: REPO,
+    issue_number: pullNumber,
+    labels: newLabels,
+  });
+}
+
+export async function nextActionAuthor(
+  pullNumber: number,
+  existingLabels: any[]
+) {
+  const client = getGitHubClient();
+  let newLabels = removeNextActionLabel(existingLabels);
+  newLabels.push("Next Action: Author");
+  await client.rest.issues.setLabels({
+    owner: REPO_OWNER,
+    repo: REPO,
+    issue_number: pullNumber,
+    labels: newLabels,
+  });
+}
+
+export async function checkIfCommitter(username: string): Promise<boolean> {
+  const client = getGitHubClient();
+  const permissions = (
+    await client.rest.repos.getCollaboratorPermissionLevel({
+      owner: REPO_OWNER,
+      repo: REPO,
+      username: username,
+    })
+  ).data.permission;
+
+  return permissions == "write" || permissions == "admin";
+}
+
+function removeNextActionLabel(existingLabels: any[]): string[] {
+  let newLabels: string[] = [];
+  existingLabels.forEach((label) => {
+    if (
+      label.name != "Next Action: Reviewers" &&
+      label.name != "Next Action: Author"
+    ) {
+      newLabels.push(label.name);
+    }
+  });
+  return newLabels;

Review comment:
       Can be rewritten as:
   ```
   return existingLabels.filter(label => label.name != "..." && label.name != 
"...").map(label => label.name)
   ```




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


Issue Time Tracking
-------------------

    Worklog Id:     (was: 731785)
    Time Spent: 3h  (was: 2h 50m)

> Automate Reviewer Assignment
> ----------------------------
>
>                 Key: BEAM-13925
>                 URL: https://issues.apache.org/jira/browse/BEAM-13925
>             Project: Beam
>          Issue Type: Improvement
>          Components: beam-community
>            Reporter: Danny McCormick
>            Assignee: Danny McCormick
>            Priority: P2
>          Time Spent: 3h
>  Remaining Estimate: 0h
>
> 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. We should add automation driven by GitHub Actions to 
> automatically round robin new PR reviews to a set of contributors, thus 
> balancing the load.
>  
> Design doc here - 
> https://docs.google.com/document/d/1FhRPRD6VXkYlLAPhNfZB7y2Yese2FCWBzjx67d3TjBo/edit#



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to