fivetran / dbt_package_automations

Project used by the Fivetran dbt package team to help automate package development and maintenance efforts.
3 stars 1 forks source link

2nd Reviewer GitHub Action does not take into account upstream or downstream sibling PRs. #13

Open fivetran-joemarkiewicz opened 10 months ago

fivetran-joemarkiewicz commented 10 months ago

Issue Description

The latest automation update to add a 2nd reviewer which takes the place of the release reviewer and leverages a carousel is fantastic! However, this solution assumes each repo/pr are handled in isolation. However, this is not entirely true. For example, if I have a PR out for Facebook Ads Source and a separate PR for Facebook Ads Transform, this 2nd reviewer automation may possibly select two separate reviewers for each of these PRs. When ideally I would prefer we have the same 2nd reviewer for both PRs.

Requirements

A single reviewer is automatically assigned for any "related" PRs. For example:

snapchat_ads_source = X 2nd reviewer
snapchat_ads = X 2nd reviewer
ad_reporting = X 2nd reviewer

This logic should persist from source -> last dependent repo. For example:

linkedin_pages = X 2nd reviewer
social_media_reporting = 2 2nd reviewer

Based on the above requirements I think we can get the repo relations sorted out by adding a requirement to the PR templates that asks what the downstream related PR is (if applicable). We could then do some sort of regex matching to determine if that is populated. If it is then we can search the downstream repo for that PR number. Once the action finds that repo and pr combination it will assign the same reviewer.

Additional Notes

When searching around I found that we could add variables to the action which will allow us to specify the relevant downstream repos in the action per each package. The pr number could then be a variable generated via the regex matching. Here is some sample code I thought up (note this is just me jotting down notes and have not tested).

# The source repo where the original PR is located
source_repo = g.get_repo(os.getenv('GITHUB_REPOSITORY'))
source_pr_number = os.getenv('PR_NUMBER')

# The target repo where you want to copy the reviewer
target_repo = g.get_repo(os.getenv('SECOND_REPO'))
target_pr_number = <123>  # This would be the variable obtained via the regex match on the PR template

# Fetch the list of review requests for the source PR
source_pr = source_repo.get_pull(source_pr_number)
review_requests = source_pr.get_review_requests()

if review_requests:
    reviewers = review_requests[1]  # Assuming the second entry is the second reviewer
    second_reviewer = reviewers[0]  # You would add your logic to ensure you're getting the right reviewer

    # Add the second reviewer to the target PR
    target_pr = target_repo.get_pull(target_pr_number)
    target_pr.create_review_request(reviewers=[second_reviewer.login])
fivetran-joemarkiewicz commented 10 months ago

FYI @fivetran-catfritz

fivetran-catfritz commented 10 months ago

Perfect. I actually ended up working on this last night and worked it out pretty quickly. Here is my PR! @fivetran-joemarkiewicz