Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated the git pull-request command to use personal access token instead of basic auth. #864

Merged
merged 7 commits into from
Aug 11, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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\.
.
Personal access token is required for making API call to open the pull request in Github\.
.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.
Personal access token is required for making API call to open the pull request in Github.
v-y-a-s marked this conversation as resolved.
Show resolved Hide resolved

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