Skip to content

Commit

Permalink
Merge pull request #864 from v-y-a-s/pr
Browse files Browse the repository at this point in the history
Updated the git pull-request command to use personal access token instead of basic auth.
  • Loading branch information
spacewander authored Aug 11, 2020
2 parents 2f3772b + eaeeef3 commit 73cc666
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 45 deletions.
21 changes: 10 additions & 11 deletions bin/git-pull-request
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,12 @@ json() {
EOF
}

# user
# personal access token
# config name is github-personal-access-token '_' is not allowed in git config

user=$(git config user.email)
github_personal_access_token=$(git config git-extras.github-personal-access-token)

if [ -z "$user" ]; then
user="$EMAIL"
fi

test -z "$user" && abort "git config user.email required"
test -z "$github_personal_access_token" && abort "git config git-extras.github-personal-access-token required"

# branch

Expand Down Expand Up @@ -80,7 +77,9 @@ fi

body=$(json "$title" "$body" "$branch" "$base")

curl -u "$user" \
-H "X-GitHub-OTP: $mfa_code" \
"https://api.github.com/repos/$project/pulls" -d "$body"

curl \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token $github_personal_access_token" \
-H "X-GitHub-OTP: $mfa_code" \
"https://api.github.com/repos/$project/pulls" -d "$body"
37 changes: 14 additions & 23 deletions man/git-pull-request.1
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "GIT\-PULL\-REQUEST" "1" "November 2017" "" "Git Extras"
.
.\" generated with Ronn-NG/v0.8.0
.\" http://github.com/apjanke/ronn-ng/tree/0.8.0
.TH "GIT\-PULL\-REQUEST" "1" "August 2020" "" "Git Extras"
.SH "NAME"
\fBgit\-pull\-request\fR \- Create pull request for GitHub project
.
.SH "SYNOPSIS"
\fBgit\-pull\-request\fR [<target branch>]
.
.SH "DESCRIPTION"
Create pull request for a project on GitHub via command line\.
.
.P
Uses the email from \fBgit config user\.email\fR to open the pull request\.
.
A personal access token is required for making the API call to open the pull request(s) in GitHub\. API Documentation here \fI\%https://docs\.github\.com/en/rest/reference/pulls#create\-a\-pull\-request\fR
.P
Make sure the personal access token has the right \fBOAuth\fR scopes for the repo(s)
.P
Use \fBgit config \-\-global \-\-add git\-extras\.github\-personal\-access\-token <your\-personal\-access\-token>\fR
.P
If using mutiple accounts, override the global value in the specific repo using \fBgit config git\-extras\.github\-personal\-access\-token <other\-acc\-personal\-access\-token>\fR
.SH "OPTIONS"
<target branch>
.
.P
The target branch you want to send pull request to\.
.
.SH "EXAMPLES"
.
.nf

$ git pull\-request master
Everything up\-to\-date

Expand All @@ -35,16 +31,11 @@ Everything up\-to\-date
base [master]:
GitHub two\-factor authentication code (leave blank if not set up):

Enter host password for user \'spacewanderlzx@gmail\.com\':
\.\.\.
.
\|\.\|\.\|\.
.fi
.
.SH "AUTHOR"
Written by Tj Holowaychuk <\fItj@vision\-media\.ca\fR>
.
Written by Tj Holowaychuk <\fI\%mailto:tj@vision\-media\.ca\fR>
.SH "REPORTING BUGS"
<\fIhttps://github\.com/tj/git\-extras/issues\fR>
.
<\fI\%https://github\.com/tj/git\-extras/issues\fR>
.SH "SEE ALSO"
<\fIhttps://github\.com/tj/git\-extras\fR>
<\fI\%https://github\.com/tj/git\-extras\fR>
23 changes: 14 additions & 9 deletions man/git-pull-request.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions man/git-pull-request.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ git-pull-request(1) -- Create pull request for GitHub project

Create pull request for a project on GitHub via command line.

Uses the email from `git config user.email` to open the pull request.
A personal access token is required for making the API call to open the pull request(s) in GitHub. [API Documentation here](https://docs.github.com/en/rest/reference/pulls#create-a-pull-request)

Make sure the personal access token has the right `OAuth` scopes for the repo(s)

Use `git config --global --add git-extras.github-personal-access-token <your-personal-access-token>`

If using mutiple accounts, override the global value in the specific repo using `git config git-extras.github-personal-access-token <other-acc-personal-access-token>`

## OPTIONS

Expand All @@ -30,7 +36,6 @@ Everything up-to-date
base [master]:
GitHub two-factor authentication code (leave blank if not set up):
Enter host password for user '[email protected]':
...
```

Expand Down

0 comments on commit 73cc666

Please sign in to comment.