0

I’m using a lambda function to deploy code to GitHub to a forked repository with the use of Pygithub. The forked repo will create a pr to the upstream repo where changes will be reviewed. Is there a way to make git fetch upstream from the fork to make sure that it is even with the main repo before pushing changes to the fork? I would like to automate this process instead of manually going in to update the fork. Pygithub docs don’t seem to have anything helpful on this issue.

Things I’ve tried:

  1. Create pr from main repo to forked repo but lack permissions to write from main repo.
Michael S.
  • 3,050
  • 4
  • 19
  • 34
papaya
  • 1
  • 1

1 Answers1

0

If it was me I'd use PyGitHub where possible because the abstraction is nice. However, in a recent project where I had to write lots of "git stuff" using PyGitHub, there were some missing pieces. Admittedly I was in a bit of a hurry so some of these commands may be covered by PyGitHub but anyways it was a hack day prototype so meh.

In those cases I used a Docker container to deploy to lambda so I could configure and install git. From there I could run a subprocess to do "real" git commands.

p1 = subprocess.Popen([f'git checkout -b {git_branch}'], stderr=sys.stderr, stdout=subprocess.PIPE, cwd=f"{current_dir}/", shell=True)
p1.wait()

The docker setup included

# Install git so we can use it within lambda
RUN yum update -y && \
  yum install -y git && \
  rm -Rf /var/cache/yum

And then:

# Git configuration
RUN git config --system user.email "test@test.com"
RUN git config --system user.name "test-username"

Forks can be a headache, could be a good call to say nah let's go full Trunk based development ;-) If you have any questions regarding the answer please let me know!

Leslie Alldridge
  • 1,427
  • 1
  • 10
  • 26