'Login Github with Curl
I tried call this command
curl -l -u "my_user_name" https://my-enterprise-github.com
Then, I input my password manually.
But it returns this
<html><body>You are being <a href="https://my-enterprise-github.com/login?return_to=https%3A%2F%2Fmy-enterprise-github.com%2F">redirected</a>.</body></html>
Please explain what's wrong with my command. Thank you.
Solution 1:[1]
cURL should not be used for access to GitHub's (or most web) UI without specific reasons. GitHub provides an API to allow accessing data as a well-defined structure.
You mentioned wanting to get-a-single-pull-request. This relies on a URL pattern following GET /repos/:owner/:repo/pulls/:number
.
So if you had a GitHub account, facebook
, and wanted to look up a specific pull request 15947
in react-native
. The full URL would be
https://api.github.com/repos/facebook/react-native/pulls/15947
The cURL command would be
curl -u osowskit -X GET https://api.github.com/repos/facebook/react-native/pulls/15947
Note that:
- You will likely want to start using a PAT or OAuth token instead of username/password
- There are tools that make exploring the GitHub API easier. postman or octokit
Solution 2:[2]
To start with you may want the -L
flag. From the cURL Frequently Asked Questions
3.8 How do I tell curl to follow HTTP redirects?
Curl does not follow so-called redirects by default. The Location: header that informs the client about this is only interpreted if you're using the -L/--location option. As in:
curl -L http://redirector.com
Not all redirects are HTTP ones, see 4.14
Solution 3:[3]
There's also a CLI now that can be helpful for many similar use-cases:
$ gh pr list
Showing 2 of 2 open pull requests in Roblox/service-comms-nomad
#16 chi1 Traefik 1.7 GLB jobs chi1-glb-prep
#6 Cgt/t2 cgt/t2
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | osowskit |
Solution 2 | Community |
Solution 3 | Charles Thayer |