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

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/

Related

ServiceNow Rest API (using PowerBI)

I'm on a project in which I need to get data from a ServiceNow instance and treat all data with PowerBI. I'm able to retrieve a big amount of data (Snow collect a lot of data), but I still need a way to filter data correctly. I'm calling to this URL:
Besides, I want also to apply a filter to retrieve just some specific registries from the table Requested Items. For that, I use the sysparm_query parameter to filter the field "cmdb_ci" and more specifically it's "name", something like:
&sysparm_query=cmdb_ci=What I need to Filter
Apart from this, I have also tried:
&sysparm_query=cmdb_ci.value=What I need to Filter
&sysparm_query=cmdb_ci.display_value=What I need to Filter
&sysparm_query=cmdb_ci.sys_id=What I need to Filter
&sysparm_query=cmdb_ci.name=What I need to Filter
But still not found the solution... as all these does not respond the solution needed.
Does someone know how I can manage this?
Thanks!!
JLG
There are two "Configuration item" fields in sc_req_item: cmdb_ci and configuration_item. Make sure that you are using the correct one. Either cmdb_ci.name=value or configuration_item.name=value should work, depending on which of the two fields you are using. cmdb_ci.value and cmdb_ci.display_value will not work as there are no fields on the record with these names. cmdb_ci.sys_id should work if you are supplying a sys_id (although it is redundant to type .sys_id for a reference field).
You should first verify your query through the ServiceNow UI before attempting to use it in an API call.
Type sc_req_item.list in the Filter navigator
On the filter list select "Show related fields"
Get your filter to work correctly
Right-click on the filter and select "Copy query"
The next step is to test it using the REST API Explorer.
Final step is to configure your client tool (PowerBI).

Jira Rest API JQL query

I'm making use of the Jira API with the following call:
https://site.url/rest/api/2/search?jql=project=PROJECT&updated>=startOfWeek(-1w)
When I run this, I'm getting over 6000 results. But when I run the jql query of project = PROJECT AND updated >= startOfWeek(-1w) inside of my Jira sites search bar, I only get around 60 results.
Is there something I'm missing in my api call that would limit the returned to the data to the above query?
Edit
Looking further it appears my call is only bringing back results from my project space and not using the updated query. What should I do so it picks up both?
There is a typo in your query. You have used an ampersand instead of the word 'and'. The ampersand is the character used to add query parameters, so you effectively did this query
https://site.url/rest/api/2/search?jql=project=PROJECT
then Jira just ignored what came after the ampersand, as it didn't know what the parameter 'updated>' was, or how to make it equal 'startOfWeek(-1)'
Within the JQL, you must use the word 'and' with spaces before and after, like this:
https://site.url/rest/api/2/search?jql=project=PROJECT and updated>=startOfWeek(-1w)
Only use ampersands to add other query parameters afterwards, like this:
https://site.url/rest/api/2/search?jql=project=PROJECT and updated>=startOfWeek(-1w)&startAt=0&maxResults=500
Please send the API as POST method:
API: https://url/rest/api/2/search
Body:
{
"jql": "project='project name'&updated>=startOfWeek(-1)"
}

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/

Retrieving More columns as Part of VSTS query

I'm trying to fetch details from VSTS using VSTS query API. So to get all Portfolio Epics I created a custom query and used its ID to get that in JSON format. the query looks like this
https://dev.azure.com/{organization}/{project}/{team}/_apis/wit/wiql/{id}?api-version=5.0-preview.2
But the issue is its not giving me many details about each of the work items in JSON. It only lists the ID and URL. Like this
WorkItems:[
{ID:234,URL:"workitemurl"},
{ID:235,URL:"workitemurl"},
{ID:236,URL:"workitemurl"},
...
]
So if I need more details about an item I need to execute those individual URl for each PE and thus I can get its details. instead of I am just checking is there is any way of getting an ID (keyedinID of each work item along with the ID and URL) like this. Please note KID is a field if we execute the URL separately. So to avoid that extra process, I would like to get that along with the WorkItems.
WorkItems:[
{ID:234,URL:"workitemurl",KID:002},
{ID:235,URL:"workitemurl",KID:023},
{ID:236,URL:"workitemurl",KID:033},
...
]
So how can we make this possible?
The Web UI uses a different API to get query results (/_api/_wit/_query), which allows query+data in a single pass. This is an old __v5 type call, which means it's considered internal.
The proper way to do this now is to first do the query as you're doing it right now and then call /_api/wit/workitems?ids=1,2,3,4 using the IDs from the references you got from the first call. That will also allow you to load the details dynamically and in small batches which will result in a more responsive UI.
See:
https://learn.microsoft.com/en-us/rest/api/azure/devops/wit/work%20items/list?view=azure-devops-rest-4.1

Nested Jira Search on two independent projects

I need to get a nested Jira search. I am okay with JQL query but I have a usecase that I don't know how to solve
Company uses project=XTBOW for reporting purpose for executives (Epic)
The company also uses project=XTA for underling development work (Task)
The XTA task are linked to the XTBOW Epic for a subset of task, but not all. (There is a large body of XTA task that are not linked to XTBOW)
I need to get a filter going for all XTA projects that are linked to XTBOW Epics only. I would like to use a filter like this:
project = XTA and "Epic Link" in (<project = XTBOW.key>)
I can manually prove this filter works. But need a way to automate this filter, because the number of tickets being created/tracked in growing exponentially, and if someone deletes a key for XTBOW that is in the "Epic Link" field, the JQL search throws and error because the "Key" is missing.
Example - FYI cf[10231] is the "Epic Link" field:
project in (XTA,XTWOF) and cf[10231] in (XTBOW-42,XTBOW-59)
The overall objective is to download the data to a dataframe. So if there is a better suggestion to even avoid JQL and do it through python. I am all ears. Just need so pointers to start. I am just going this route because I have already built a JIRA-Downloader/Parser using Python.
The easiest way to get subsets of issues is with:
search_issues(jql_str, startAt=0, maxResults=50, validate_query=True, fields=None, expand=None, json_result=None)
You should be able to just pull the issue sets using the queries you already created, just make them into strings.
DOC

Resources