A Day in the Life of an Engineer: Dealing with Pull Requests

Most of the services we write usually involves checking code into two repositories: the first repository is where actual code changes are done which goes through CI/CD to be assigned a new release version upon successful Jenkins workflow; the second is where you assign the release version to have it deployed to another CI/CD workflow via Kubernetes.

In both repositories, pull requests are created and goes to the review process before it gets merged to their respective main branches. For the first repo, it's paramount to have the PRs thoroughly reviewed and vetted. The second? Not so much. Getting two separate PR review requests for essentially one work gets a bit cumbersome where one would just approve the PR for the second PR without even looking. When I'm doing the work it gets equally cumbersome as well as I need to annoy co-workers to approve the second PR and it sometimes ruin your velocity when they choose to ignore you out of spite...especially when you're trying to troubleshoot something and want it deployed in a container environment ASAP.

One would argue that the workflow should be better, but that doesn't give me an opportunity to up my karma on LinkedIn.

So to be a good teammate, I wrote a simple Python script to auto-approve for any PR for the 2nd repo, and run it as a cron job (poor man's GitHub bot)

from github import Github

# https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token
token = "your-token"

# your login
me = "dlegaspi"

# add your list of repos
repos = ["my-day-job/annoying-repo-1",
         "my-day-job/annoying-repo-2"]

g = Github(token)

for repo in repos:
  r = g.get_repo(repo)
  print(f"checking repo {repo}...{r.get_pulls().totalCount} active PRs")
  for pr in r.get_pulls():
    print(pr)

    if pr.user.login != me:
      if len([r.user for r in pr.get_reviews() if r.state == "APPROVED"]) == 0:
        pr.create_issue_comment(f'auto-approved by {me}')
        pr.create_review(event="APPROVE")
      else:
        print(f"[{pr.id}: {pr.title}] is already approved.")        

At least I don't have to manually approve PRs for the repo where we usually only update release versions.

Of course, this script can be WAAAY better (right now this script will just approve ANY PR in the repos array and it shouldn't) and one should wield this power carefully. You can't just assign all your repo to auto-approve PRs because that would be too awesome...er, i mean, irresponsible.

Tyler Plass

Developer Experience at Integral Ad Science

1 年

The joys of partially migrating to polling/GitOps based CD tools. It's nice for admins who only deploy apps, but dev teams expect build and deploy logs to be in the same spot! And why should k8s deploy logs be somewhere else than cdk or cf deploy logs? We've definitely noticed the negative impact of our FluxCD implementation...

要查看或添加评论,请登录

Dexter Legaspi, MSc的更多文章

社区洞察

其他会员也浏览了