How to get patchset "Author" out of Gerrit? - gerrit

When using "gerrit query" with the option "--patch-sets" the output includes the patchset "committer" (called "uploader"). But the patchset "author" is not included in the output.
Query:
ssh gerrit gerrit query --format=JSON --patch-sets --all-approvals -- status:merged project:demo-project-2 -age:1week
As "committer" and "author" can be different (as "forge author" has been enabled) I need to know also the "author" in order to create a metric which reveals if anyone reviewed their own code (giving their own commit code-review +2).
According to Shawn it is not possible to get patchset "author" using "gerrit query".
So, question is, is it possible to get patchset "author" in another way? It must be stored in Gerrit somewhere, right, but where?

In the latest version of Gerrit it's possible to include the author and committer of patch sets in the results returned by the REST API query.
For example:
curl -n --digest "https://review.example.com/a/changes/?q=owner:self&o=CURRENT_REVISION&o=CURRENT_COMMIT"
will fetch all changes owned by the current user. The results will include the patch sets as RevisionInfo entity with the committer and author included in the CommitInfo entity.

I guess the only way to do it is to ssh into the server:
ssh user#gerrit git --git-dir=/home/gerrit2/review_site/git/Project.git/ rev-list --pretty=\"format:Author Name:%an Author Email:%ae\" refs/changes/02/2/1

Another answer to my question is: Use REST API instead of Gerrit Query.
It seems that Gerrit is moving away from "Gerrit Query" and instead focuses more on "REST API".

Related

How to match any issue with jql in Bitbucket JIRA pre hook

I want to setup a simple pre hook in bitbucket that simply checks that there's a JIRA number in commit message. When I attempt to save it, I get a message that I should enter a valid JQL query to match the desired issues. How can I write this query to match ANY issue?
Can you please provide the JQL Query you are providing? If you want to get "All" Issues you can simply give a created > 0 or project = "Proj", either of which would catch all of your tickets. You could then use this to loop through your commit message and check your Jira Key (i.e. Proj-####) as a loop. I might also recommend on the Bitbucket you have a regex check whick looks for that specific pattern on your prehook, depending on how you write it.
Although, if you have configured it correctly it might actually be able to do it automatically. Check the documents here: https://support.atlassian.com/jira-software-cloud/docs/reference-issues-in-your-development-work/

Use the public GitHub API to get all merged pull requests in a JSON format

I am trying to get all the closed and merged commits on a certain repository using the github API (https://api.github.com/), and the only way I have found to do this is to check for commits that are closed (api.github.com/repos/user/repo/pulls?state=closed), then make sure the merged_at is not equal to null, but this is a slow way to do it. Is there a way to make github check if the PR is closed and has been merged at the same time directly in the url? Something like api.github.com/repos/user/repo/pulls?state=closed?is_merged=true? And return all the PRs matching the criteria?
NOTE: this has nothing to do with the /repos/user/repo/pulls/pr_id/merge, because that only tells you if a single pull request is merged, and does not search everywhere in the list of PRs.
You can use the “is:merged” operator in your search query
Check this out: https://docs.github.com/en/github/searching-for-information-on-github/searching-issues-and-pull-requests#search-based-on-the-state-of-an-issue-or-pull-request
Request template
curl \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/search/issues\?q\=repo:{repo_owner}/{repo}+is:pr+is:merged
Explanation:
You can't get merged pull requests by std Github API /pulls route. But you can do this using Search API.
More info in docs:
Use Search API: https://docs.github.com/en/rest/search#about-the-search-api
More tricks for search issues and prs: https://docs.github.com/en/search-github/searching-on-github/searching-issues-and-pull-requests

Filter mlflow runs by commit ID

When using the UI of MlFlow, is it possible to filter/search the runs using the (git) commit ID? I manage to search by parameters but it doesn't seem like there's a way to filter by the commit ID.
In the latest version (1.21.0) you can filter by commit hash with this search string tags.mlflow.source.git.commit LIKE "truncated-commit-hash%". Probably this feature was introduced after you've originally posted that question.
The search in the ui is translated to a rest api call to the mlflow tracking server:
https://mlflow.org/docs/latest/rest-api.html#search-runs
You can see that you can search over 3 things: parameters, metrics and tags.
You can set the git commit id as a tag while training your model and then search for it, you can see how to set tags in the following link

some existing users cant be found in TFS2018 workitem 'assigned to' field. even they are added to team project

My customer are using TFS2018 update2 version. and AD is used to manager TFS user.
there are about 1000 users right now. and about 10 to 20 users reported that their user account can't be found in TFS workitem "Assigned to" field. so strange and confused!
1) we did check the 'AssignedTo' field of the workitem setting, is is of default setting, which allows existing user and valid users.
2) the users are even added to the team project, however, they can't be found when using search in 'assigned to 'field.
3) tried other type of workitems, any projects. same issues.
Generally speaking, such users can be added to team project successfully.and they can't be found in 'assigned to' filed of all workitems in all projects. so we doubt it is some kind of user account sync issues?
and we did do more investigation and debugging. and we found a para named operationScopes,and its value is 'ims';and if we add value 'ad' to this array. the users can be found! and we noticed the returned value bdifference between such 'bad users' and 'good users' are of the 'Local directory'and 'localId' field. the value is null here, for good user, neither local directory nor LocalID is null.
hope this clue works.
http://TFS2018server:8080/tfs/TFSCollection/_apis/IdentityPicker/Identities
and add more clues, we updated the Web Services_static\tfs\Dev16.M122.5_script\TFS\debug\VSS\Identities\Picker\Services.js; by adding queryScopes.push("ims") in the OperationScope.IMS switch, then the users can be found. and I know, it is not a good way to update TFS code, it is just to do debugging. hope it is useful.
Based on the investigation and testing, seems it's the AD sync issue. That means the missed users may not be synced to TFS.
So when you query the missed user in AD you can find it (Add value 'ad' to operationScopes), but in TFS you can not find them.
TFS use a background synchronization job, scheduled every hour, to look for changes in Active Directory (or the local machine workgroup if the server is not domain joined). You can force the job to run using any of these techniques: How to synchronize TFS users with AD
It could be that you still do not see the user or name listed in the UI even if synchronization is working. The synchronization job does not automatically creates a user profile in the database for every user or group in the database, to avoid useless growth in big enterprises.
In such a case, the first time you use a new AD account (user or group), you must refer to it using DOMAIN\account syntax so that TFS look up in AD on the fly and insert a profile record in the database for the account.
Further Troubleshooting
Mr. Hinsh has a good troubleshooting guide if you still have troubles. It's still apply to TFS 2018 Update2
I have the same issue in Azure DevOps Server 2019 (Version Dev17.M153.3)
when I tried to add a user to a security group it shows the user but it cannot retrieve the scopeName such that if there is any other user in other domains with the same username it raises the following error
Multiple identities found matching 'theusername'. Use the unique name
to specify one of the following identities:
fullname1 (unique name: domain1\theusername)
fullname2 (unique name: domain2\theusername)
but the same user in other collection is working.
in C:\Program Files\Azure DevOps Server 2019\Application Tier\Web Services_static\tfs\Dev17.M153.3_scripts\TFS\debug\VSS\Identities\Picker\Services.js queryScopes.push("ims") was already there.
after some investigation i could reduce the problem to the following powershell code
$url1 = "https://tfsserver/CB/_apis/IdentityPicker/Identities?api-version=5.1-preview.1"
$Body = '{"query":"mydomainname\\myusername","identityTypes":["user","group"],"operationScopes":["ims","ad","wmd"],"properties":["DisplayName","IsMru","ScopeName","SamAccountName","Active","SubjectDescriptor","Department","JobTitle","Mail","MailNickname","PhysicalDeliveryOfficeName","SignInAddress","Surname","Guest","TelephoneNumber","Description"],"filterByAncestorEntityIds":[],"filterByEntityIds":[],"options":{"MinResults":40,"MaxResults":40,"ExtensionId":"F12CA7AD-00EE-424F-B6D7-9123A60F424F","ProjectScopeName":"ateamprojectname","CollectionScopeName":"badcollection","Constraints":[]}}'
$x= Invoke-Webrequest $url1 -Method POST -ContentType application/json -UseDefaultCredentials -Body $Body
$y = $x.Content | ConvertFrom-Json
Write-Host "badcollection->", $y.results.identities.scopeName
$url1 = "https://tfsserver/CB_TestCollection/_apis/IdentityPicker/Identities?api-version=5.1-preview.1"
$Body = '{"query":"mydomainname\\myusername","identityTypes":["user","group"],"operationScopes":["ims","ad","wmd"],"properties":["DisplayName","IsMru","ScopeName","SamAccountName","Active","SubjectDescriptor","Department","JobTitle","Mail","MailNickname","PhysicalDeliveryOfficeName","SignInAddress","Surname","Guest","TelephoneNumber","Description"],"filterByAncestorEntityIds":[],"filterByEntityIds":[],"options":{"MinResults":40,"MaxResults":40,"ExtensionId":"F12CA7AD-00EE-424F-B6D7-9123A60F424F","ProjectScopeName":"ateamprojectname","CollectionScopeName":"goodCollection","Constraints":[]}}'
$x= Invoke-Webrequest $url1 -Method POST -ContentType application/json -UseDefaultCredentials -Body $Body
$y = $x.Content | ConvertFrom-Json
Write-Host "goodcollection->", $y.results.identities.scopeName
the output result for the first write-host is "badcollection->"
but the output result for the second write-host is "goodcollection->mydomainname"
the questions are:
Why does it depend on collection?
How can i force tfs to sychronize that user account for the badcollection as well as the good collection.

JIRA: pair old/new IssueKey after changing project

we used to have three different JIRA projects, and merged them all into one new project, resulting in new IssueKeys for all issues involved.
Unfortunately, test automation uses the IssueKey to update the issue about test results (via SQL INSERT statement), and I try to avoid updating the list of IssueKeys in the suite.
I can think of two ways:
Addressing the issues by the old IssueKey. This seems to work in JIRA JQl search (issuekey=ISSUE-OLD finds the same issue as issuekey=ISSUE-NEW ), but not for the SQL INSERT statement.
Getting a list of pairs old-new IssueKey. For example, in JIRA under "activity" and "all", I can see entries that log the changes. Exporting tose worklogs might be a great help, but there might be other ways.
Thanks in advance,
Florian
I assume you're updating a test management db, not the Jira db (which would not be good)
You might also be interested in the moved_issue_key table which is where Jira stores the previous issue keys (e.g. ABC-123) and maps them to an issue id (the id in the jiraissue table)
you can use the curl api:
curl -D- -u user:password -X GET -H "Content-Type: application/json" https://url.com/rest/api/2/issue/ISSUE-OLD
The response will contain the key value as ISSUE-NEW with other details.

Resources