Searching Gerrit by Commit Message - gerrit

Our team uses a standard of prefixing all commit messages with "bz12345:" (where 12345 is replaced by the bug you're working on) and I'd like to be able to search for all commits that have that bug number.
I've read http://gerrit.googlecode.com/svn/documentation/2.1.6/user-search.html over and over and haven't figured out a way to search for commit message titles. Does anybody have a trick for searching the first line of a commit message for arbitrary text? None of message:, tr:, and bug: work.

Ah, I figured it out. You MUST have a status: query too. For example, this works:
status:merged message:bz12345
This does not:
message:bz12345
This could be because we're on an older version of Gerrit (2.2.1 I think).

message:bz12345 should work.
See the latest documentation
Note that it searches the whole message body though, not just the subject.
message:'MESSAGE'
Changes that match MESSAGE arbitrary string in the commit message body.

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/

How to enforce a format for a (pull request) merge commit message in BitBucket

Our team is migrating to BitBucket. Our workflow requires certain formatting for commit messages for code that is merged into the main origin repo.
Each developer has one (or more) fork(s). Our workflow is to push a feature/bug branch to the fork and create a pull request from that branch. Two other devs must review and +1 the pull request before it can be merged.
When someone clicks Merge, BitBucket displays a dialog with the title "Merge Pull Request". At that point, the dev can edit the text message that is logged for the merge before clicking the second Merge button. This is the message that needs to conform to a specific format.
I have read the documentation here: https://scriptrunner.adaptavist.com/latest/bitbucket/StashMergeChecks.html It has several very specific examples, but nothing that pertains to our use case. I have not been able to find a good, general-purpose reference for how to create merge checks.
I can write a condition that checks for a specific string value:
mergeRequest.message == "My Message"
But I need it to check against a regular expression.
How can I write a pre-merge hook to reject the merge if the message doesn't conform to a regex?
Addition
From the documentation, it seems like the condition check script code would be the right place to enforce this condition. The script can be added in Repository Settings > SCRIPTRUNNER > Script Merge Checks > Conditional merge check. There is a long list of examples shown for the conditional merge check, including things like:
Current user in a particular group
Changed files contains .XYZ files
Changed files in sensitive directory
Target branch is release
After some search & experiment I found I could block merges based on the commit message. But so far I have only found examples of comparing entire strings against constant string expressions. I haven't found how to use a regex in this comparison.
OP here after pushing this issue to the back burner for a few weeks. Issue is solved. You can check your merge commit messages against a regular expression without using a plugin. Solution is here for those who come searching with the same problem.
First, it was more challenging than it should have been to find the documentation for the objects that are most relevant to writing a Merge Check script. So here are a couple of links for the current 6.3.0 API:
PullRequest - In the end, my script didn't use this object, but the pull request is closely related to the merge request and others may need the documentation.
MergeRequest - This object has a method to determine the context (see below).
Second, the Merge Check script fires in two distinct contexts: (1) when bitbucket is trying to determine if it should enable/disable the Merge button on the Pull Request page, and (2) when someone clicks the Merge button on the Merge pull request dialog. In the first context the merge message is null, so it cannot match a regex. And anyway it doesn't make sense to disable the button in this case. I really only wanted the check to occur in the second context. So the script needs a way to distinguish the contexts.
Third, the message object is a Java String, so the script can call the matches() method to check if the message matches a regex.
After you have all the information at your fingertips, writing the script is pretty easy:
// the message regex
String pattern = "(PATTERN1|PATTERN2|etc)"
// reject if not dry-run and
// message doesn't match regex
! mergeRequest.isDryRun() &&
! mergeRequest.message.matches(pattern)
You could try some of the plugins for Bitbucket like YACC:
https://marketplace.atlassian.com/apps/1211854/yet-another-commit-checker?hosting=server&tab=overview
If that doesn't meet your requirements, you could write your own:
https://developer.atlassian.com/server/bitbucket/how-tos/hooks-merge-checks-guide/

Exchange 2010 strange behaviour on search UID SEARCH CHARSET US-ASCII FROM

I'm really spent a lot of time searching about, but no luck.
My issue is not directly related to Mailkit working or not, it is doing right but perhaps someone here have a clue.
I have to look for mails unseen mails from specific mail address on a Exchange 2010 using IMAP. All work fine (until now) for any server except this one.
When "from" mail address in format like John Doe <johndoe#pluto.com> a search for johndoe#pluto.com does not return any UIDs;
John Doe return UID collection;
On the other hand if "from" mail is in plain format all works fine.
Does anybody have any idea or know if is it an issue on Exch2010?
As a work around I'm thinking to make a simple search unseen to get UIDs then Fetch and look at Envelope
By the way here I have on log when message from = John Doe <johndoe#pluto.com>;
C: A00000006 UID SEARCH CHARSET US-ASCII FROM johndoe#pluto.com
S: * SEARCH
S: A00000006 OK SEARCH completed.
Almost 1 year later, seems I found why I canĀ“t get any result when searching From when mail address have Display Name.
Here Dmitry explain Exchange behaviour
https://blogs.technet.microsoft.com/dkhrebin/2013/10/04/how-exchange-imap-search-in-message-header/
A short quote say:
If you use SEARCH FROM (for CC, BCC, TO idea the same) Exchange will search in message's Property: PR_SENT_REPRESENTING_NAME, PR_SENT_REPRESENTING_NAME_A,
ptagSentRepresentingName
The PR_SENT_REPRESENTING_NAME property contains the display name for the messaging user represented by the sender.
So in addition to:SearchQuery.FromContains ("johndoe#pluto.com").Or (SearchQuery.FromContains ("John Doe"));
I can use SearchQuery.HeaderContains ("from", "johndoe#pluto.com");
Since Display Name can be anything and can be changed anytime, and mail address is always same. I can deal with both commands command lines above.
But I can't determine which has the best performance.
I've noticed that each IMAP server seems to behave differently with respect to searching for email addresses and/or Message-Id tokens.
What you may need to do is either do an OR search query:
SearchQuery.FromContains ("johndoe#pluto.com").Or (SearchQuery.FromContains ("John Doe"));
Perhaps that will work around the problem so it works with all IMAP servers?

Gerrit trackingid not working

According to this section, I have created the following entries in the gerrrit.config file:
[trackingid "jira-issue"]
footer = Issue:
match = "\\[PROJECT-\\d+\\]"
system = JIRA
When I commit a new patchset (or a new change) with the following commit message, the tracking id is not created.
[PROJECT-123] My commit message
Change-Id: Ia5b58dda57ef12632075738d1301f2e143066d45
I have checked the tracking_ids table in database and it's empty. Filtering changes with tr:PROJECT-123 have no results. What can be wrong?
I have restarted Gerrit after making the configuration change. Gerrit v2.8.
Currently the tracking ID needs to go in the footer of the commit message, using the footer argument as its name. In your case:
My commit message
Change-Id: Ia5b58dda57ef12632075738d1301f2e143066d45
Issue: [PROJECT-123]
The order of the name: value pairs in the footer doesn't matter - they just must all be in one paragraph (no blank lines between items).
If it does work in the body of the commit message, then it is probably this issue: Support TrackingIds in subject as well as footer.

IMAP search on header not working as expected

I am building library for IMAP my search command works file for the Inbox folder it returns me a number which I can use to fetch the mail. However when I try to search on Sent Items it does not work it does not give an error but just returns Search OK without any numbers. Can you please point out why this behavior. I am hitting Exchange 2010.
My search command is something like:
search all HEADER Message-ID "<cc6aed80-955b-4800-a3ac-6c3942ceecac>"
This is exactly how it is described in http://support.microsoft.com/kb/302965
Possibly of no use, but I ran into possibly the same problem.
In a mailbox with an email from "Bill Gates ", a search with the expression '(FROM "billy#microsoft.com")' returned nothing; a search for '(FROM gates)' return a hit.
I had to change my code to '(HEADER FROM "billy#microsoft.com")' to get it to work.
ALTERNATIVELY:
You may be able to use IMAP4.uid(command, arg[, ...])
See http://docs.python.org/2/library/imaplib.html#imaplib.IMAP4.uid

Resources