This curl command works as expected and shows when the repository was first created.
curl https://api.github.com/repos/RaRe-Technologies/gensim | grep created
"created_at": "2011-02-10T07:43:04Z",
But this does not show when a file in that repo was created.
curl
https://api.github.com/repos/RaRe-Technologies/gensim/blob/develop/gensim/scripts/make_wikicorpus.py
| grep created
Is there any way to find the date on which the file was introduced?
You can use https://api.github.com/repos/OWNER/REPO/commits?path=<path/to/file>, as described here.
The results of this request can then be parsed by jq, with the following options .[-1].commit.author.date.
This tells jq to get the last item of the array ([-1]), and then parse the value of commit, then author and then the date, which is the date of the commit.
So using the follwing command
curl "https://api.github.com/repos/RaRe-Technologies/gensim/commits?path=gensim/scripts/make_wikicor
pus.py" | jq -r ".[-1].commit.author.date"
will result in
2012-07-21T20:00:29Z
The alternative, using GitHub CLI gh, and its gh api command:
# Windows
gh api -X GET repos/RaRe-Technologies/gensim/commits \
-f path="gensim/scripts/make_wikicorpus.py" \
--jq ".[-1].commit.author.date"
# Linux
gh api -X GET repos/RaRe-Technologies/gensim/commits \
-f path='gensim/scripts/make_wikicorpus.py' \
--jq '.[-1].commit.author.date'
2012-07-21T20:00:29Z
You don't even need jq if you have gh installed.
Related
After I switched to the new Github Token format, I am not able anymore to perform a call for this github API:
https://docs.github.com/en/rest/issues/comments#list-issue-comments
My script does the following:
[[ -z "$GITHUB_REPO_SLUG" ]] && export GITHUB_REPO_SLUG="$TRAVIS_REPO_SLUG"
GITHUB_API_BASE_URL="https://api.github.com/repos/${GITHUB_REPO_SLUG}"
GITHUB_AUTH_HEADER="Authorization: token $GITHUB_TOKEN"
comment_ids=$(curl -s -H "$GITHUB_AUTH_HEADER" "$GITHUB_API_BASE_URL/issues/$pull_request_id/comments" \
| jq --arg USER "$GITHUB_USER" -r '. | map(select(.user.login==$USER)) | map(.id) | .[]')
for comment_id in $(echo $comment_ids); do
jq -n -r --arg message "$message" '{ body: $message }' \
| curl -s -H "$GITHUB_AUTH_HEADER" "$GITHUB_API_BASE_URL/issues/comments/$comment_id" -X PATCH --data #- > /dev/null
echo "Edited comment with id $comment_id of PR $pull_request_id"
done
The api call that list comments ids responds:
{
"message": "Not Found",
"documentation_url": "https://docs.github.com/rest/reference/issues#list-issue-comments"
}
This still works using tokens in the old format, but doesn't with tokens in the new format.
Is there any way to use the GHP to call that api?
The github user associated with the github token must be provided writing access to the repository.
Since this was missing API responded 404 (default behaviour set for Github APIs).
i need some equivalent command to the following command:
git log --pretty="* %s%n%b" BRANCH2...TAGNAME1
i tried already the compare feature of the api but sadly without the result i expected:
curl -s --header "PRIVATE-TOKEN: XXXXXXX" "https://gitlab.localhost/api/v4/projects/3/repository/compare?from=BRANCH2&to=TAGNAME1&straight=true" | jq .
what i get is:
"commit": null,
"commits": [],
but git log gives me the following:
* commit 1 description
* commit 2 description
so what i search and need is to compare BRANCH2 with TAGNAME1 and list the different commits.
this is later on needed in order to generate a changelog file which is pushed to a new tag.
This would be the compare API
Using the gitlab-org/gitlab repo as an example, to compare the tags/branches v14.8.0-ee to v14.9.0-ee:
curl https://gitlab.com/api/v4/projects/278964/repository/compare?from=v14.8.0-ee&to=v14.9.0-ee
If you're not getting the response you're expecting, try swapping the from and to arguments and/or omitting the straight argument.
thank you!
the solution in the end was change the from and to so in the end it works like that:
curl -s --header "PRIVATE-TOKEN: XXXXXXX" "https://gitlab.localhost/api/v4/projects/3/repository/compare?from=TAGNAME1&to=BRANCH2&straight=true" | jq .
I'm looking for a way to get both the version number and license details from a repo providing I have the URL for the Repo. I have a way at the moment that doesn't work for all repos I am reviewing but it's basically html scraping.
I assume there is an API example somewhere that pulls these details?
some random examples
https://github.com/Microsoft/Terminal
https://github.com/leoasis/redux-immutable-state-invariant
https://github.com/zeroclipboard/zeroclipboard
What version do you need ? If a package.json file is present, you can use it and get the version in it:
curl -sL https://raw.githubusercontent.com/leoasis/redux-immutable-state-invariant/master/package.json | jq -r '.version'
For the latest release tag name (aka version), use
curl -sL https://api.github.com/repos/Microsoft/Terminal/releases/latest | jq -r '.tag_name'
To retreive the license, use the Github API and go to https://api.github.com/repos/zeroclipboard/zeroclipboard/license, e.g.
curl -sL https://api.github.com/repos/zeroclipboard/zeroclipboard/license | jq -r '.license.name'
`
From the answer to a related question I know it's possible to batch clone repositories based on a GitHub search result:
# cheating knowing we currently have 9 pages
for i in {1..9}
do
curl "https://api.github.com/search/repositories?q=blazor+language:C%23&per_page=100&page=$i" \
| jq -r '.items[].ssh_url' >> urls.txt
done
cat urls.txt | xargs -P8 -L1 git clone
I also know that the Hub client allows me to make API calls.
hub api [-it] [-X METHOD] [-H HEADER] [--cache TTL] ENDPOINT [-F FIELD|--input FILE]
I guess the last step is, how do I archive a repository with Hub?
You can update a repository using the Update a Repository API call.
I put all my repositories in a TMP variable in the following way, and ran the following:
echo $TMP | xargs -P8 -L1 hub api -X PATCH -F archived=true
Here is a sample of what the $TMP variable looked like:
echo $TMP
/repos/amingilani/9bot
/repos/amingilani/advent-of-code-2019
/repos/amingilani/alan
/repos/amingilani/annotate_models
i have a Jenkins build that work with gerrit.
i can re-trigger this job very easily throw Jenkins ui.
i wanted to re-trigger a specific build from the Linux terminal.
i manage to do it with a curl command when i input all the GERRIT parameters.
curl command:
curl "url/job/job_name/buildWithParameters?token=token&GERRIT_CHANGE_ID=id_numberb&GERRIT_PATCHSET_REVISION=gerrit_patchset...
parameters:
GERRIT_PATCHSET_UPLOADER
GERRIT_PATCHSET_REVISION
GERRIT_CHANGE_ID
GERRIT_PATCHSET_NUMBER
GERRIT_EVENT_ACCOUNT_EMAIL
GERRIT_CHANGE_NUMBER
GERRIT_CHANGE_OWNER
GERRIT_REFSPEC1
GERRIT_EVENT_TYPE
GERRIT_EVENT_ACCOUNT
GERRIT_CHANGE_SUBJECT
GERRIT_CHANGE_OWNER_NAME
GERRIT_PROJECT
GERRIT_EVENT_HASH
GERRIT_BRANCH
GERRIT_CHANGE_OWNER_EMAIL
GERRIT_PATCHSET_UPLOADER_EMAIL
GERRIT_CHANGE_URL
GERRIT_PATCHSET_UPLOADER_NAME
GERRIT_EVENT_ACCOUNT_NAME
i only need a way to send 1 parameter from the above list and get all the rest.
i tried to curl the Jenkins/gerrit_manual_trigger/ , but i don't get this parameters.
how can i get all those parameters for a specific build via terminal?
I was able to retrieve all Gerrit parameters with the following command:
curl -s -u USER:PASS --request GET "https://JENKINS-SERVER/JOB-PATHNAME/BUILD-NUMBER/api/json" | jq --raw-output '.actions[].parameters | select(length > 0) | .[] | .name + " " + .value'
GERRIT_EVENT_TYPE patchset-created
GERRIT_EVENT_HASH -1187252333
GERRIT_BRANCH master
...
GERRIT_PORT 29418
GERRIT_SCHEME ssh
GERRIT_VERSION 2.14.3