3

How can I create a github pull request for a project that I haven't checked out using the github api. I want to automate simple changes to repositories, that I need not check out first. I simply want to pull a file from raw.githubusercontent.com modify it and create said pull request.

EDIT The github web user interface allows to edit foreign files by cloning and creating a pull request in the back ground.

3 Answers 3

10

2015:

I haven't checked out using the github api.

You should at least have forked the repo first (see GitHub API create a fork)

Then "Create a Pull Request" supposes you have pushed a commit to a dedicated branch (API "Create a commit" first, which supposes to create a tree first, based on creating a blob).

For all those operations, I would suggest using a wrapper to the GitHub API like go-github, which might make the all series of operation easier to chain.


2023:

The GitHub CLI allows for:

  • gh repo fork to create a fork of a repository (without cloning it locally).
  • gh pr create --web to create a pull request on GitHub, from the web interface (so no local checkout required, assuming you have a branch ready to be merged).
Sign up to request clarification or add additional context in comments.

2 Comments

I need to do the same thing as OP: checkout a single file from a repo, make changes to it, commit them to a new branch, and open a PR from it. Haven't tested it yet, but maybe the "contents" add/update file endpoints could help with this. Looks like you can specify a path of exactly what to change. It also looks like you could check out a specific path, presumably meaning you wouldn't have to clone the whole repo just to get one file.
@V.Rubinetti Why not just edit the file directly on github.com? As illustrated in this article: "You’re editing a file in a project you don’t have write access to. Submitting a change to this file will write it to a new branch in your fork flaviocopes/web.dev, so you can send a pull request."
2

You had to have checked it out, but you can use scripted command line to do it.

A pull request asks that a particular git commit be merged into the main repository, not that a set of edits be made to files. You can only merge in commits if you have a writable copy of the github repo, which you can only get by cloning or forking the project.

Comments

1

The api supports cloning remotly

https://developer.github.com/v3/repos/forks/#create-a-fork

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.