I have a task where I need to fetch number of code review comments made for a particular gerrit review commit. Then later I need to apply filters on EPIC ID, BUC ID and count review comments made on each EPIC/BUC etc.
Is there any way to know or fetch the review comments from gerrit? And then count the number of comments?
You can use REST to get the comments in a change:
curl -s --request GET https://GERRIT-SERVER/a/changes/CHANGE-NUMBER/comments
Or in a specific patchset:
curl -s --request GET https://GERRIT-SERVER/a/changes/CHANGE-NUMBER/revisions/PATCHSET-NUMBER/comments
Then you can process the output using jq.
For example, use this:
curl -s --request GET https://GERRIT-SERVER/a/changes/CHANGE-NUMBER/revisions/PATCHSET-NUMBER/comments | sed 1d | jq --raw-output ".[][] | {Updated: .updated, Message: .message}"
To get the following:
{
"Updated": "2016-10-17 16:27:54.000000000",
"Message": "COMMENT-1"
}
{
"Updated": "2016-10-17 16:30:22.000000000",
"Message": "COMMENT-2"
}
Or use this:
curl -s --request GET https://GERRIT-SERVER/a/changes/CHANGE-NUMBER/revisions/PATCHSET-NUMBER/comments | sed 1d | jq --raw-output ".[][].id" | wc -l
To get the number of comments:
2
Related
I am attempting to write a module where I cannot use the current ModuleClient.CreateFromEnvironmentAsync() and would like to get the module connection string (or SASKey) so I can generate a SAS token and authenticate.
I know that at one time (and in the IoTEdgeDev container) the environment variable EdgeHubConnectionString existed and was later removed. How can I derive the sasKey in code in a module? Imaging if I needed/wanted to use Paho in the module instead of the MSFT provided SDK.
Update
So I guess I have to sign the URI to create a connection string, similar to manually creating a connection string.
I have tried the code below, but the signature does not match what I get with Azure IoT Explorer. Any help would be appreciated. Reference: https://github.com/Azure/iotedge/blob/d2c331d605a846911019364a31a7d098e1e2fc45/edgelet/workload/docs/WorkloadApi.md
# expecting curl, base64 and jq to be installed
epoch=$(printf '%(%s)T\n' -1)
epoch=$(($epoch+86400))
dataToSign=$IOTEDGE_IOTHUBHOSTNAME"%2Fdevices%2F"$IOTEDGE_DEVICEID"%2Fmodules%2F"$IOTEDGE_MODULEID
signedData=$(echo -n $dataToSign'\n'$epoch | base64 -w 0)
signature=$(curl --unix-socket /var/run/iotedge/workload.sock http://127.0.0.1/modules/$IOTEDGE_MODULEID/genid/$IOTEDGE_MODULEGENERATIONID/sign?api-version=$IOTEDGE_APIVERSION \
--header "Content-Type: application/json" --request POST --data '{"data": "'$signedData'", "keyId": "", "algo": "HMAC-SHA256"}' \
| jq -r ".digest")
SASToken="SharedAccessSignature=SharedAccessSignature sr=$dataToSign&sig=$signature&se=$epoch"
ConnectionString="HostName=$IOTEDGE_IOTHUBHOSTNAME;DeviceId=$IOTEDGE_DEVICEID;ModuleId=$IOTEDGE_MODULEID;$SASToken"
I took a look at the implementation of ModuleClient.CreateFromEnvironmentAsync() in the C# SDK. It uses the following environment variables to create the connection string:
- IOTEDGE_WORKLOADURI URI for iotedged's workload API
- IOTEDGE_DEVICEID Device identifier
- IOTEDGE_MODULEID Module identifier
- IOTEDGE_MODULEGENERATIONID Module generation identifier
- IOTEDGE_IOTHUBHOSTNAME IoT Hub host name
- IOTEDGE_AUTHSCHEME Authentication scheme to use; must be "sasToken"
It seems the SAS token is created in the ModuleAuthenticationWithHsm class, you might be able to base your code on this?
So after hours of iteration, here is how to call the sign API to get a SAS Token:
# expecting curl, base64 and jq to be installed in the Linux OS
epoch=$(printf '%(%s)T\n' -1)
epoch=$(($epoch+86400))
WORKLOADURI=$(echo $IOTEDGE_WORKLOADURI | sed "s|unix://|""|g")
uri=$(echo $IOTEDGE_IOTHUBHOSTNAME"/devices/"$IOTEDGE_DEVICEID"/modules/"$IOTEDGE_MODULEID | sed "s|/|%2F|g")
signedData=$(echo -n $uri$'\n'$epoch | base64 -w 0)
signature=$(curl --unix-socket $WORKLOADURI http://127.0.0.1/modules/$IOTEDGE_MODULEID/genid/$IOTEDGE_MODULEGENERATIONID/sign?api-version=$IOTEDGE_APIVERSION \
--request POST --data '{"data": "'$signedData'", "keyId": "", "algo": "HMAC-SHA256"}' \
| jq -r ".digest" | sed "s|=|%3D|g" | sed "s|+|%2B|g" | sed "s|/|%2F|g")
# here is our SAS Token
SASToken="SharedAccessSignature=SharedAccessSignature sr=$uri&sig=$signature&se=$epoch"
# here is a connection string with the SAS Token
ConnectionString="HostName=$IOTEDGE_IOTHUBHOSTNAME;DeviceId=$IOTEDGE_DEVICEID;ModuleId=$IOTEDGE_MODULEID;$SASToken"
JIRA's REST API search doesn't honor maxResults parameter.
curl -o lambrusco.txt -k -D- -u admin:admin -X GET -H "Content-Type: application/json" https://jira.domain.com/rest/api/2/search?jql=assignee=blackpearl&startAt=0&maxResults=4
No matter what maxResults is, it always returns 50 results.
Output:
{"expand":"schema,names","startAt":0,"maxResults":50,"total":61,"issues":[{"expand":"operations,versionedRepresentations,editmeta,changelog,transitions,renderedFields","id":"15588","self": ...}
What am I missing here?
Your request looks fine. Here is example on official Atlassian JIRA, which works fine:
curl -X GET -H "Content-Type: application/json" "https://jira.atlassian.com/rest/api/2/search?jql=assignee=tlay&startAt=1&maxResults=1" | jq -r '.maxResults'
It looks like that it's related to REST API Bug!
You need to quote the request when using curl as shown by #grundic, otherwise the shell will interpred the ampersand. And note that the API is case sensitive.
I am new to parse and ios development.
I want to use Parse for User management of an IOS app. With the help of documentation (https://parse.com/docs/ios/guide#users-signing-up) I was able to signup some sample users and I have the following in Parse app.
Then I want to retrieve all users (or query for specific) with following documentation help.
var query = PFUser.query()
query.whereKey("gender", equalTo:"female")
var girls = query.findObjects()
I was expected to receive an array of size 3 but surprisingly didn't receive any.
Later I figured out I can user API console feature of Parse and tried use it to receive PFUser objects. I received zero results.
Later I tried with sample table and I was successfully add, retrieve Objects to the table.
Not sure If I need to anything special for me to use PFUser.
I have tested using API Console and its working on my side. I have one entry in User table having gender = male.
I fired following curl query to retry all the users
curl -X GET \
-H "X-Parse-Application-Id: <#your-application-key>" \
-H "X-Parse-REST-API-Key: <#your-rest-api-key>" \
-G \
https://api.parse.com/1/users
Result from the above query is:
{"results":[{"gender":"male","createdAt":"2015-12-10T06:00:40.368Z","email":"sam07it22#gmail.com","objectId":"1KbxpYgeUb","updatedAt":"2015-12-10T06:01:32.885Z","username":"sam07it22#gmail.com"}]}
Now, I'm going to add Condition in above query to fetch records having gender = female. As per data expected result should have zero records
For gender = female
curl -X GET \
-H "X-Parse-Application-Id: <#your-application-key>" \
-H "X-Parse-REST-API-Key: <#your-rest-api-key>" \
-G \
--data-urlencode 'where={"gender":"female"}' \
https://api.parse.com/1/users
Output:
{"results":[]}
For gender = male
curl -X GET \
-H "X-Parse-Application-Id: <#your-application-key>" \
-H "X-Parse-REST-API-Key: <#your-rest-api-key>" \
-G \
--data-urlencode 'where={"gender":"male"}' \
https://api.parse.com/1/users
Output:
{"results":[{"gender":"male","createdAt":"2015-12-10T06:00:40.368Z","email":"sam07it22#gmail.com","objectId":"1KbxpYgeUb","updatedAt":"2015-12-10T06:01:32.885Z","username":"sam07it22#gmail.com"}]}
NOTE:
Don't forget to replace your API KEY and REST API KEY
ACL permissions has done the trick. ACL permissions has to be "public read" for them to be accessible. Here is more info about ACL in parse https://parse.com/docs/ios/guide#security-object-level-access-control
I've tried various iterations of using either ", ' and ` to enclose a curl query to an instance of jira in order to get all issues for a particular fix Version.
curl -D- -u username:password -X POST -H "Content-Type: application/json" -d '{"jql":"project = PROJ AND fixVersion=Version-1.2.3"}' "https://thejirainstall.com/jira/rest/api/2/search"
However, using this and a couple of other change on fixVersion such as:
fixVersion="Version-1.2.3"
or
fixVersion=\"Version-1.2.3\"
or
fixVersion=Version-1\u002e2\u002e3
Add and remove quotes at will.
The ones that don't fail outright return:
{"errorMessages":["Error in the JQL Query: '\\.' is an illegal JQL escape sequence. The valid escape sequences are \\', \\\", \\t, \\n, \\r, \\\\, '\\ ' and \\uXXXX. (line 1, character 38)"],"errors":{}}
How do I either escape periods . or add another set of quotes?
Ok, so it turns out that Jira doesn't permit version names in jql syntax. The version id must be used instead.
And, in order to get the version id you must parse the result from https://thejirainstall.com/jira/rest/api/2/project/ON/versions?
This now means that I have to use a JSON parser anyway. So, now I'm using jq via homebrew install jq
My current solution is to write a bash script as below:
JIRA_FIXVERSION
fixVersionQuery='https://thejirainstall.com/jira/rest/api/2/project/ON/versions?';
myJSONResponse=`curl -u username:password -X GET -H "Content-Type: application/json" --insecure --silent $fixVersionQuery |jq '.[] | {id,name} | select(.name=="Version-1.2.3" | .["id"]'`;
echo $myJSONResponse;
I have a script with which I POST data to a server using cURL. When I use an HTML form to POST the same data, the POST looks something like this and all is well:
description=Something&name=aName&xml=wholeBiunchOfData&xslt=moreData
The XML and XSLT are large and change; I would prefer to maintain them in external files. However, the following does not work as I expect;
curl --cookie cjar --cookie-jar cjar --location --output NUL ^
--data "name=aName&description=Something" ^
--data "xml=#localFile.xml" ^
--data "xslt=#localFile.xslt" ^
http://someUrl.html
I have tried various combinations of the # and local files without success. How do I POST the contents of a file?
Looking at the man page it looks like the --data #file syntax does not permit for a variable name, it must be in the file. http://paulstimesink.com/2005/06/29/http-post-with-curl/. You could also try using a backtick
curl --cookie cjar --cookie-jar cjar --location --output NUL ^
--data "name=aName&description=Something" ^
--data "xml=`cat localFile.xml`" ^
--data "xslt=`cat someFile.xml`" ^
http://someUrl.html
I'd recommend trying the following:
curl --cookie cjar --cookie-jar cjar --location --output NUL ^
--data "name=aName&description=Something" ^
--data-urlencode "xml#localFile.xml" ^
--data-urlencode "xslt#localFile.xslt" ^
http://someUrl.html
XML (including stylesheets) will need to be URL-encoded before being made part of a URL.
You can also use --trace-ascii - as an additional parameter to dump the input and output to standard out for further debugging, and you can find more information on the main man page.
Hope this helps!