alibaba / git-repo-go

git-repo is a command-line tool for centralized workflow, can work with Gerrit, AGit-Flow compatible servers. It is written in Golang, and it can be installed easily without further dependency. It provides an easy-to-use solution for multiple repositories which is introduced by Android repo first, and it can also work with a single repository.
https://git-repo.info/
Apache License 2.0
272 stars 60 forks source link

Feature request: Add github api create merge request #47

Closed ghost closed 2 years ago

ghost commented 2 years ago

Ref: https://docs.github.com/en/rest/reference/pulls#create-a-pull-request

after local code change, we type git pr

this action will look for if the origin URL was github

If github ,then make API call to create new pull request

we can using .netrc to let git auto know the token to access the github api

Amazing way.

ghost commented 2 years ago

For example:

  1. know the origin URL , for me , like https://github.com/cnmade/bsmi-kb.git
  2. detect if the URL start with https://github.com and end with .git
  3. if match the rules, we know how to get the full repo : substr(0, 19), then substr(-4,4)
  4. we now get cnmade/bsmi-kb
  5. POST https://api.github.com/repos/{owner}/{repo}/pulls, for this repo, we know: https://api.github.com/repos/cnmade/bsmi-kb/pulls
    curl \
    -X POST \
    -H "Accept: application/vnd.github.v3+json" \
    https://api.github.com/repos/cnmade/bsmi-kb/pulls \
    -d '{"head":"for/master","base":"master"}'
  6. job finished.
jiangxin commented 2 years ago

When I contributed "proc-receive" and "report-status-v2" to Git, Peff (Jeff King from GitHub) told me github has a tailored version of git-receive-pack, so it's not possible for github to support "proc-receive" quickly.

If you want to create pull request using github API, it's better to use github CLI tool. When creating pull request this way, you have to create a real topic branch, and cannot do like agit-flow or gerrit, which are built-in in this tool.

jiangxin commented 2 years ago

See what we discussed in git mailing list: https://lore.kernel.org/git/20200507172713.GA3645853@coredump.intra.peff.net/

ghost commented 2 years ago

@jiangxin all works can be implement at client side .no more need to hack into git core.

I made some rush code to implement it.

see: https://github.com/cnmade/git-cpr/blob/for/dev/main.go

It works for me