You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ko...@apache.org on 2023/03/15 23:47:38 UTC

[arrow] branch main updated: GH-34381: [Dev] Retrieve committers from arrow-site committers.yml instead of relying on author_association (#34557)

This is an automated email from the ASF dual-hosted git repository.

kou pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/main by this push:
     new fe88d9ad5c GH-34381: [Dev] Retrieve committers from arrow-site committers.yml instead of relying on author_association (#34557)
fe88d9ad5c is described below

commit fe88d9ad5c346786842913c8d2a369db099b5406
Author: Raúl Cumplido <ra...@gmail.com>
AuthorDate: Thu Mar 16 00:47:27 2023 +0100

    GH-34381: [Dev] Retrieve committers from arrow-site committers.yml instead of relying on author_association (#34557)
    
    ### Rationale for this change
    
    If a committer has their ASF role on GitHub as private the GitHub PR bot author_association is not correctly assigned.
    
    ### What changes are included in this PR?
    
     This change uses the committers list on the arrow_site repository to retrieve the list of committers.
    
    ### Are these changes tested?
    
    There is a unit test and have tested the different steps of the workflow individually but haven't tested the full workflow.
    
    ### Are there any user-facing changes?
    
    No
    * Closes: #34381
    
    Lead-authored-by: Raúl Cumplido <ra...@gmail.com>
    Co-authored-by: Sutou Kouhei <ko...@cozmixng.org>
    Signed-off-by: Sutou Kouhei <ko...@clear-code.com>
---
 .github/workflows/pr_bot.yml          | 12 ++++++++++--
 dev/archery/archery/bot.py            | 22 +++++++++++++++------
 dev/archery/archery/cli.py            | 15 ++++++++++----
 dev/archery/archery/tests/test_bot.py | 37 +++++++++++++++++++++++++++++++++++
 4 files changed, 74 insertions(+), 12 deletions(-)

diff --git a/.github/workflows/pr_bot.yml b/.github/workflows/pr_bot.yml
index d9a3d10e6b..9d0d7ec88b 100644
--- a/.github/workflows/pr_bot.yml
+++ b/.github/workflows/pr_bot.yml
@@ -66,6 +66,12 @@ jobs:
         run: |
           unzip pr_review.zip
           echo "pr_review_path=$(pwd)/event.json" >> $GITHUB_OUTPUT
+      - name: Download committers file
+        id: committers
+        run: |
+          url="https://raw.githubusercontent.com/apache/arrow-site/main/_data/committers.yml"
+          curl -sL -o committers.yml $url
+          echo "committers_path=$(pwd)/committers.yml" >> $GITHUB_OUTPUT
       - name: Checkout Arrow
         uses: actions/checkout@v3
         with:
@@ -89,9 +95,11 @@ jobs:
             # workflow_run is executed on PR review. Update to original event.
             archery trigger-bot \
               --event-name "pull_request_review" \
-              --event-payload "${{ steps.extract.outputs.pr_review_path }}"
+              --event-payload "${{ steps.extract.outputs.pr_review_path }}" \
+              --committers-file "${{ steps.committers.outputs.committers_path }}"
           else
             archery trigger-bot \
               --event-name "${{ github.event_name }}" \
-              --event-payload "${{ github.event_path }}"
+              --event-payload "${{ github.event_path }}" \
+              --committers-file "${{ steps.committers.outputs.committers_path }}"
           fi
diff --git a/dev/archery/archery/bot.py b/dev/archery/archery/bot.py
index 3e394b982a..a1387a6005 100644
--- a/dev/archery/archery/bot.py
+++ b/dev/archery/archery/bot.py
@@ -106,10 +106,11 @@ COMMITTER_ROLES = {'OWNER', 'MEMBER'}
 
 class PullRequestWorkflowBot:
 
-    def __init__(self, event_name, event_payload, token=None):
+    def __init__(self, event_name, event_payload, token=None, committers=None):
         self.github = github.Github(token)
         self.event_name = event_name
         self.event_payload = event_payload
+        self.committers = committers
 
     @cached_property
     def pull(self):
@@ -122,6 +123,18 @@ class PullRequestWorkflowBot:
     def repo(self):
         return self.github.get_repo(self.event_payload['repository']['id'], lazy=True)
 
+    def is_committer(self, action):
+        """
+        Returns whether the author of the action is a committer or not.
+        If the list of committer usernames is not available it will use the
+        author_association as a fallback mechanism.
+        """
+        if self.committers:
+            return (self.event_payload[action]['user']['login'] in
+                    self.committers)
+        return (self.event_payload[action]['author_association'] in
+                COMMITTER_ROLES)
+
     def handle(self):
         current_state = None
         try:
@@ -165,17 +178,14 @@ class PullRequestWorkflowBot:
         """
         if (self.event_name == "pull_request_target" and
                 self.event_payload['action'] == 'opened'):
-            if (self.event_payload['pull_request']['author_association'] in
-                    COMMITTER_ROLES):
+            if self.is_committer('pull_request'):
                 return PullRequestState.committer_review
             else:
                 return PullRequestState.review
         elif (self.event_name == "pull_request_review" and
                 self.event_payload["action"] == "submitted"):
             review_state = self.event_payload["review"]["state"].lower()
-            is_committer_review = (self.event_payload['review']['author_association']
-                                   in COMMITTER_ROLES)
-            if not is_committer_review:
+            if not self.is_committer('review'):
                 # Non-committer reviews cannot change state once committer has already
                 # reviewed, requested changes or approved
                 if current_state in (
diff --git a/dev/archery/archery/cli.py b/dev/archery/archery/cli.py
index 146b3babdc..5ebf140bb5 100644
--- a/dev/archery/archery/cli.py
+++ b/dev/archery/archery/cli.py
@@ -775,20 +775,27 @@ def integration(with_all=False, random_seed=12345, **args):
 
 
 @archery.command()
+@click.option('--arrow-token', envvar='ARROW_GITHUB_TOKEN',
+              help='OAuth token for responding comment in the arrow repo')
+@click.option('--committers-file', '-c', type=click.File('r', encoding='utf8'))
 @click.option('--event-name', '-n', required=True)
 @click.option('--event-payload', '-p', type=click.File('r', encoding='utf8'),
               default='-', required=True)
-@click.option('--arrow-token', envvar='ARROW_GITHUB_TOKEN',
-              help='OAuth token for responding comment in the arrow repo')
-def trigger_bot(event_name, event_payload, arrow_token):
+def trigger_bot(arrow_token, committers_file, event_name, event_payload):
     from .bot import CommentBot, PullRequestWorkflowBot, actions
+    from ruamel.yaml import YAML
 
     event_payload = json.loads(event_payload.read())
     if 'comment' in event_name:
         bot = CommentBot(name='github-actions', handler=actions, token=arrow_token)
         bot.handle(event_name, event_payload)
     else:
-        bot = PullRequestWorkflowBot(event_name, event_payload, token=arrow_token)
+        committers = None
+        if committers_file:
+            committers = [committer['alias']
+                          for committer in YAML().load(committers_file)]
+        bot = PullRequestWorkflowBot(event_name, event_payload, token=arrow_token,
+                                     committers=committers)
         bot.handle()
 
 
diff --git a/dev/archery/archery/tests/test_bot.py b/dev/archery/archery/tests/test_bot.py
index 17f6633ca5..6be90e7e21 100644
--- a/dev/archery/archery/tests/test_bot.py
+++ b/dev/archery/archery/tests/test_bot.py
@@ -383,6 +383,43 @@ def test_open_pull_request(load_fixture, responses, fixture_name, expected_label
     assert json.loads(post.request.body) == [expected_label]
 
 
+@pytest.mark.parametrize(('fixture_name', 'expected_label'), [
+    ('event-pull-request-target-opened-non-committer.json',
+     PullRequestState.committer_review.value),
+])
+def test_open_pull_request_with_committer_list(load_fixture, responses, fixture_name,
+                                               expected_label):
+    responses.add(
+        responses.GET,
+        github_url('/repositories/169101701/pulls/26'),
+        json=load_fixture('pull-request-26.json'),
+        status=200
+    )
+    responses.add(
+        responses.GET,
+        github_url('/repos/ursa-labs/ursabot/issues/26/labels'),
+        json=[],
+        status=200
+    )
+    responses.add(
+        responses.POST,
+        github_url(
+            '/repos/ursa-labs/ursabot/issues/26/labels'
+        ),
+        status=201
+    )
+    payload = load_fixture(fixture_name)
+
+    # Even though the author_association is not committer the list overrides.
+    bot = PullRequestWorkflowBot(
+        'pull_request_target', payload, token='', committers=['kszucs'])
+    bot.handle()
+
+    # Setting awaiting committer review or awaiting review label
+    post = responses.calls[-1]
+    assert json.loads(post.request.body) == [expected_label]
+
+
 @pytest.mark.parametrize(('fixture_name', 'expected_label'), [
     ('event-pull-request-target-opened-committer.json',
      PullRequestState.committer_review.value),