Merge pull request #864 from v-y-a-s/pr

Updated the git pull-request command to use personal access token instead of basic auth.
This commit is contained in:
罗泽轩 2020-08-11 09:14:11 +08:00 committed by GitHub
commit 73cc666030
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 45 deletions

View file

@ -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
@ -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"

View file

@ -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
@ -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>

View file

@ -1,8 +1,8 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='content-type' value='text/html;charset=utf8'>
<meta name='generator' value='Ronn/v0.7.3 (http://github.com/rtomayko/ronn/tree/0.7.3)'>
<meta http-equiv='content-type' content='text/html;charset=utf8'>
<meta name='generator' content='Ronn-NG/v0.8.0 (http://github.com/apjanke/ronn-ng/tree/0.8.0)'>
<title>git-pull-request(1) - Create pull request for GitHub project</title>
<style type='text/css' media='all'>
/* style: man */
@ -69,11 +69,12 @@
<li class='tr'>git-pull-request(1)</li>
</ol>
<h2 id="NAME">NAME</h2>
<h2 id="NAME">NAME</h2>
<p class="man-name">
<code>git-pull-request</code> - <span class="man-whatis">Create pull request for GitHub project</span>
</p>
<h2 id="SYNOPSIS">SYNOPSIS</h2>
<p><code>git-pull-request</code> [&lt;target branch&gt;]</p>
@ -82,7 +83,13 @@
<p>Create pull request for a project on GitHub via command line.</p>
<p>Uses the email from <code>git config user.email</code> to open the pull request.</p>
<p>A personal access token is required for making the API call to open the pull request(s) in GitHub. <a href="https://docs.github.com/en/rest/reference/pulls#create-a-pull-request">API Documentation here</a></p>
<p>Make sure the personal access token has the right <code>OAuth</code> scopes for the repo(s)</p>
<p>Use <code>git config --global --add git-extras.github-personal-access-token &lt;your-personal-access-token&gt;</code></p>
<p>If using mutiple accounts, override the global value in the specific repo using <code>git config git-extras.github-personal-access-token &lt;other-acc-personal-access-token&gt;</code></p>
<h2 id="OPTIONS">OPTIONS</h2>
@ -102,13 +109,12 @@ 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':
...
</code></pre>
<h2 id="AUTHOR">AUTHOR</h2>
<p>Written by Tj Holowaychuk &lt;<a href="&#109;&#x61;&#105;&#x6c;&#x74;&#111;&#58;&#x74;&#x6a;&#x40;&#118;&#105;&#115;&#105;&#111;&#110;&#x2d;&#x6d;&#x65;&#x64;&#x69;&#x61;&#46;&#99;&#x61;" data-bare-link="true">&#116;&#106;&#64;&#x76;&#105;&#x73;&#x69;&#x6f;&#110;&#x2d;&#109;&#101;&#x64;&#x69;&#97;&#46;&#99;&#97;</a>&gt;</p>
<p>Written by Tj Holowaychuk &lt;<a href="mailto:tj@vision-media.ca" data-bare-link="true">tj@vision-media.ca</a>&gt;</p>
<h2 id="REPORTING-BUGS">REPORTING BUGS</h2>
@ -118,10 +124,9 @@ Enter host password for user 'spacewanderlzx@gmail.com':
<p>&lt;<a href="https://github.com/tj/git-extras" data-bare-link="true">https://github.com/tj/git-extras</a>&gt;</p>
<ol class='man-decor man-foot man foot'>
<li class='tl'></li>
<li class='tc'>November 2017</li>
<li class='tc'>August 2020</li>
<li class='tr'>git-pull-request(1)</li>
</ol>

View file

@ -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
@ -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 'spacewanderlzx@gmail.com':
...
```