how to use filter parameters and Grep command together for listing all GITHUB pull request from a repository - github

I am looking for an option to get all pull requests with ID, Name, Date, and count of files committed from GitHub.
I managed to get all pull requests using API, but listing only the required parameter is not working. Can anyone help?
curl -X GET -u :https://api.github.com/repos/XXXX/XXXX/pulls?state=all&page=1&per_page=100| egrep -w 'title|number|state|created_at|updated_at'
Grep is working if the query is like below, without multiple filter parameters (state=all&page=1&per_page=100)
curl -X GET -u :https://api.github.com/repos/XXXX/XXXX/pulls?state=all| egrep -w 'title|number|state|created_at|updated_at'
Can anyone help how to list only the required data with multipe filter parameter.

try grep with something like this:
grep -Pa 'state'

Related

How to get the current Nodes where the Job is running

I'm developing a job and the user can choose in which nodes can run, so the Node Filter is open to the convenient of the user.
When the job is starting I need to do a calculation based in the number of nodes chosed by the user, exist a way to get this number?
Regards,
Alejandro L
By design, that information is only available after the execution, so, a good approach is to call the job via API (in a script step) and with the execution ID number (available in the API call output) you can list and count the nodes, e.g:
#!/bin/bash
nodes=$(curl -s -X GET "http://localhost:4440/api/41/execution/16" \
--header "Accept: application/json" \
--header "X-Rundeck-Auth-Token: your_user_token" \
| jq -r '.successfulNodes | . []')
number_of_nodes=$(echo $nodes | wc -w)
echo "Number of nodes: $number_of_nodes"
This example needs jq to extract the nodes from the API response.
Anyway, your request sounds good for an enhancement request, please suggest that here.
a workaround to take would be using job.filter variable
so if you do #job.filter#
it returns a string with the list of nodes like us-east-1-0,us-east-1-1,us-east-1-2
if you save it as a string, and then split the string on ',' then you get an array of nodes:
IFS=',' read -r -a array <<< "$string"
and then you can get the number of nodes by
echo ${#array[#]}
Note
as #MegaDrive68k mentioned this won't work if use select all node with the use of filter .*

finding when a file was introduced on github

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.

gitlab api equivalent to git log (compare branch with tag) and list commit message json

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 .

Filtering on labels in Docker API not working (possible bug?)

I'm using the Docker API to get info on containers in JSON format. Basically, I want to do a filter based on label values, but it is not working (just returns all containers). This filter query DOES work if you just use the command line docker, i.e.:
docker ps -a -f label=owner=fred -f label=speccont=true
However, if I try to do the equivalent filter query using the API, it just returns ALL containers (no filtering done), i.e.:
curl -s --unix-socket /var/run/docker.sock http:/containers/json?all=true&filters={"label":["speccont=true","owner=fred"]}
Note that I do uri escape the filters param when I execute it, but am just showing it here unescaped for readability.
Am I doing something wrong here? Or does this seem to be a bug in the Docker API? Thanks for any help you can give!
The correct syntax for filtering containers by label as of Docker API v1.41 is
curl -s -G -X GET --unix-socket /var/run/docker.sock http://localhost/containers/json" \
--data 'all=true' \
--data-urlencode 'filters={"label":["speccont=true","owner=fred"]}'
Note the automatic URL encoding as mentioned in this stackexchange post.
I felt there was a bug with API too. But turns out there is none. I am on API version 1.30.
I get desired results with this call:
curl -sS localhost:4243/containers/json?filters=%7B%22ancestor%22%3A%20%5B%222bab985010c3%22%5D%7D
I got the url escaped string using used above with:
python -c 'import urllib; print urllib.quote("""{"ancestor": ["2bab985010c3"]}""")'

How do I retrieve an artifact checksum from Nexus using their rest api via curl?

I am trying to verify the checksum of the artifacts I am downloading from Nexus. I can grab the artifact and download them and check their md5sum or sha1sum, but I need to check this against the actual sum from Nexus so I can verify they are correct.
This is the command I'm using to grab files from Nexus:
curl -v -L -o /mylocation/artifact.war -u 'myuser:mypass' --get 'http://ournexus.com/service/local/artifact/maven/content?g=com.ours.stuff&a=our-service-war&v=LATEST&r=snapshots&p=war'
Via http://nexus.xwiki.org/nexus/nexus-indexer-lucene-plugin/default/docs/path__lucene_search.html, it would appear that I can also search for the sha1 sum, but when I do &sha1 I get nothing extra or sha1=(sum), nothing is pulled up, even if I omit all the above options.
This works, but it goes to a specific war, and we need the latest (obviously):
http://ournexus.com/service/local/repositories/snapshots/content/com/ours/stuff/ourapp/1.0.0-SNAPSHOT/ourapp-1.0.0-20140730.173704-88.war.sha1
Is this possible, am I on the right track?
You can either fetch the file directly or use the Nexus API to retrieve it programmatically.
The following URL:
http://localhost:8081/nexus/service/local/artifact/maven/resolve?g=log4j&a=log4j&v=1.2.9&r=central
Returns the following result:
<artifact-resolution>
<data>
<presentLocally>true</presentLocally>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.9</version>
<extension>jar</extension>
<snapshot>false</snapshot>
<snapshotBuildNumber>0</snapshotBuildNumber>
<snapshotTimeStamp>0</snapshotTimeStamp>
<sha1>55856d711ab8b88f8c7b04fd85ff1643ffbfde7c</sha1>
<repositoryPath>/log4j/log4j/1.2.9/log4j-1.2.9.jar</repositoryPath>
</data>
</artifact-resolution>
The xmllint command can be used to parse out the sha1 checksum value as follows:
$ curl -s "http://localhost:8081/nexus/service/local/artifact/maven/resolve?g=log4j&a=log4j&v=1.2.9&r=central" | xmllint --xpath "///sha1/text()" -
55856d711ab8b88f8c7b04fd85ff1643ffbfde7c
Nexus 2
Use the artifact content API to directly get the MD5/SHA1 checksum file by specifying the p (packaging) or e (extension) parameter as jar.md5 or jar.sha1 (or other relevant for your actual packaging).
Example:
$ curl -s 'http://mynexus/service/local/artifact/maven/content?g=com.example&a=example&v=1.2.3&r=my-repo&e=jar.sha1'
55856d711ab8b88f8c7b04fd85ff1643ffbfde7c
Nexus 3
Use the Search API to find and download the asset.
$ curl -sL 'https://mynexus/service/rest/v1/search/assets/download?repository=my-repo&sort=version&maven.groupId=com.example&maven.artifactId=example&maven.baseVersion=LATEST-SNAPSHOT&maven.extension=jar.sha1&maven.classifier='
7ff1ca9fb889c73d095b69a52d5c8609482b63ab
The query below works for me
curl -u USER:PASS -X GET 'https://nexus.example.com:8443/service/rest/v1/search?repository=REPO_NAME&name=FILE_NAME' | jq '.items[0].assets[0].checksum'
Always good to check the API doc.
ps: username and password might be not needed for GET