Need some quick help. Novice terminal user here. Trying to use these instructions: https://developer.github.com/v3/repos/statistics/#commit-activity to get commit history for a specific user.
However, I don't know what to do with this:
GET /repos/:owner/:repo/stats/contributors
When I replace the owner and repo with the specific names i'm using, nothing happens because I get this error in my terminal:
-bash: GET: command not found
This is a very time sensitive issue, help! Thanks!
You can follow this curl tutorial using GitHub's API to see how you would translate
GET /repos/:owner/:repo/stats/contributors
As you notice in the comments, the ":" shouldn't be included.
curl --include https://api.github.com/users/caspyin
Pass user credential to basic auth to access protected resources like a users starred gists, or private info associated with their profile
curl --user "caspyin:PASSWD" https://api.github.com/gists/starred
curl --user "caspyin:PASSWD" https://api.github.com/users/caspyin
Passing just the username without the colon (:) will cause you to be prompted for your account password.
This avoids having your password in your command line history
curl --user "caspyin" https://api.github.com/users/caspyin
In your case, replacing <owner> and <reponame> by the right owner and repo names:
curl https://api.github.com/repos/<owner>/<reponame>/stats/contributors
Related
I'm wanting to write a bash script that verifies a user has created their SSH key on a gitlab server before the user clones or pushes any projects. Is there a git command that returns a true/false (0 or 1) that says "This person has their keys"?
I've tried a simple ssh gitlab.server.url and that seems to work, but I'm not sure if this is the best solution as I'm not wanting to verify they can ssh to the server, but rather their gitlab account has their SSH key(s) created to have the ability to clone/push projects. I was wondering if there was a specific git command.
You can make a cURL request to GitLab Users API and get the info on SSH keys for any user, given that you know their userId
curl --header "Private-Token: <your_PAT_here>" -X GET <your_GitLab_URL>/api/v4/users/<userId>/keys
In theory it works also with username, instead of userId, but I couldn't make it work. In order to get userId, I made an additional API call
curl --header "Private-Token: <your_PAT_here>" -X GET <your_GitLab_URL>/api/v4/users?username=<username_here>
I am trying to write an automation script for configuring git, but since its for an organisation account and two factor authentication, I need to generate personal access token for authorisation.
I have already tried the below code but it doesnt return anything.
token=$(curl -u $uname:$passwd --silent -d '{"scopes":["user"]}' "https://api.github.organisation.com/authorizations" | grep -o '[0-9A-Fa-f]\{40\}')
I want to get the token value into a variable like above.
I have a script written in bash and tested working in Linux (CentOS 7) and on MacOS. The script uses cURL to interact with a REST API compliant data platform (XNAT).
I was hoping that Windows users could use the same script within git-bash that comes packaged with Git for Windows. Unfortunately there seems to be an issue when using cURL in git-bash.
The first use I make of cURL is to retrieve a JSESSION cookie:
COOKIE=`curl -k -u $USERNAME https://theaddress/JSESSION`
On Linux, this asks the user for password and stores the cookie in COOKIE.
In git-bash, issuing the command hangs, until using a "ctrl + C" to interrupt it. Strangely at that point the query message for the password is displayed, but too late, the script has terminated.
I have a suspicion that this may have to do with CR or LF issues, but cannot find some info I understand regarding this.
Any pointers would be welcome !
Thank you
EDIT:
It appears the above command works fine if I pass the password in the command like this:
COOKIE=`curl -k -u $USERNAME:$PASSWORD https://theaddress/JSESSION`
However, as pointed here:
Using cURL with a username and password?
I would rather avoid having the user typing their password as a command argument.
So the question is now "why is cURL not prompting for a password when I use the first command?" when in git-bash on Windows, while that command behaves as expected in Linux or MacOS:
COOKIE=`curl -k -u $USERNAME https://theaddress/JSESSION`
Ending up replying to my own question, hope this may be useful to someone else.
It appears this issue is a known problem when running cURL from within git-bash, according to this thread:
https://github.com/curl/curl/issues/573
In particular, see the answer of dscho on 30 Dec 2015:
The problem is the terminal emulator we use with Git Bash since Git for Windows 2.5, MinTTY.
This terminal emulator is not associated with a Win32 Console, therefore the user does not see anything when cURL wants to interact with the user via said Console.
This issue has a workaround, which is documented here:
https://github.com/git-for-windows/build-extra/blob/master/ReleaseNotes.md#known-issues
The workaround is to run curl via winpty as follows:
winpty curl [arguments]
Not an issue with CR or LF after all.
Soooo, git-bash may not be the magic-bullet (tm) to run my bash scripts in Windows with zero effort. Sigh...
So I want to call a REST API from Bamboo after a deployment has completed.
This API needs a username and password but it can't be stored in Bamboo as it seems it can be viewed in the Bash History of the Build agent.
I intended to use a script task and execute something like
curl -f -v -k --user "${bamboo.user}":"${bamboo.password}" -X POST https://bamboo.url/builds/rest/api/latest/queue/project_name"/
This would make the REST call. But the username and password is a problem.
I do have the option, however of using a PEM file. It can be provided so does anyone know if this can be used in conjunction with the cURL?
--OR--
One other thought- could I encrypt a password within a file in my source control, and somehow decrypt it on the build agent, and then have curl use the file instead of reading the password from the command line? How would this look in cURL?
Any ideas how this could be achieved?
Your command seems to have an extra quote at the end of your command
Using a pem file to authenticate with curl:
curl -E /path/to/user-cert.pem -X POST https://bamboo.url/builds/rest/api/latest/queue/project_name
The file should have both private key and public key inside.
I need to be able to create github repositories via bash scripts that run from a php page, so I need to be able to pass the password in the curl command or the API Key.
However I can not seem to find the API key as I believe this may be redundant now with V3 of the github API
I followed Is it possible to create a remote repo on GitHub from the CLI without opening browser? and it got me as far as being prompted for the password
Bash file looks like this:
#! /bin/bash
a=$1
curl="-u 'USERNAME' -p 'PASSWORD' https://api.github.com/user/repos -d '{\"name\":\""$a"\"}'"
curl $curl
This does not work as it is not liking the -p parameter it seems, tried -u 'USERNAME:PASSWORD' and it did not like that either and I can not seem to find the answer on github pages. Ideally I would use the API key as this would not leave my repo password exposed in my bash file correct?
Many thanks
curl -u 'dmalikov:my_password' https://api.github.com/user/repos -d '{"name":"HI"}' works fine for me, now I have this HI repo.