Skip to content

Commit

Permalink
update Jira search
Browse files Browse the repository at this point in the history
  • Loading branch information
Thierry Dalon committed Feb 28, 2024
1 parent 9934496 commit d48baae
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 99 deletions.
3 changes: 3 additions & 0 deletions Lib/Atlasy.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,9 @@ Atlasy_Help(sKeyword:=""){
Case "vl": ; View Linked Issues
PowerTools_OpenDoc("Jira_ViewLinkedIssues")
return
Case "j s": ; Jira Quick Search
PowerTools_OpenDoc("Jira_QuickSearch")
return
Case "2c","oc":
sUrl := ""
Case "f","fav","f+","of": ; favorites
Expand Down
182 changes: 84 additions & 98 deletions Lib/Jira.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,68 @@ If !(issueKey="") {
Jira_QuickSearch(searchString){

jiraRootUrl := Jira_GetRootUrl()
sJql := Query2Jql(searchString)
Jira_OpenJql(sJql,jiraRootUrl)
} ; eofun

; ----------------------------------------------------------------------
; Jira Search - Search within current Jira Project
; Called by: NWS.ahk Quick Search (Win+F Hotkey)
Jira_Search(sUrl){
static S_JiraSearch, S_ProjectKey

RegExMatch(sUrl,"https?://[^/]*",sRootUrl)
ReRootUrl := StrReplace(sRootUrl,".","\.")
; issue detailed view
If RegExMatch(sUrl,ReRootUrl . "/browse/([^/]*)",sNewProjectKey) {
sNewProjectKey := RegExReplace(sNewProjectKey1,"-.*","")
If (sNewProjectKey = %S_ProjectKey%) and (!S_JiraSearch)
sDefSearch := S_JiraSearch
Else {
S_ProjectKey := sNewProjectKey
sDefSearch := "project=" . S_ProjectKey . " AND summary ~"
}
; filter view
} Else If RegExMatch(sUrl,ReRootUrl . "/issues/\?jql=(.*)",sJql) { ; <root>/issues/?jql=project%20%3D%20TPI%20AND%20summary%20~%20reuse
sJql := StrReplace(sJql1,"%20"," ")
sJql := StrReplace(sJql,"%3D","=")
sDefSearch := sJql
}

InputBox, sQuery , Search string, Enter Query string:,,640,125,,,,,%sDefSearch%
if ErrorLevel
return
sJql := Query2Jql(sQuery)
S_JiraSearch := sJql
; Convert labels to Jql
sPat := "#([^#\s]*)"
Pos=1
While Pos := RegExMatch(sJql, sPat, label,Pos+StrLen(label)) {
sJqlLabels := sJqlLabels . " AND labels = " . label1
} ; end while

; remove labels from search string
sJql := RegExReplace(sJql, sPat , "")

sJql := Trim(sJql)
S_JiraSearch := sJql
sSearchUrl := sRootUrl . "/issues/?jql=" . sJql
If sJql ; not empty means update search
Send ^l
Else
Send ^n ; New Window
Sleep 500
Clip_Paste(sSearchUrl)
Send {Enter}

} ; eofun
; ----------------------------------------------------------------------
Query2Jql(searchString) {
; Convert labels to Jql
sPat := "#([^#\s]*)"
Pos=1
While Pos := RegExMatch(searchString, sPat, label,Pos+StrLen(label)) {
sJqlLabels := sJqlLabels . " and labels = " . label1
sJqlLabels := sJqlLabels . " AND labels = " . label1
} ; end while

; remove labels from search string
Expand All @@ -228,12 +284,9 @@ sJql := StrReplace(sJql," d~"," description~")
; Enclose summary~ description~ with "" if using wildcards ? or * see https://tdalon.blogspot.com/2022/02/jira-partial-text-search.html
sPat1 = [^(?:\s*AND\s*|\s*OR\s*|"\*\(\))]*
;sPat1 = [^"]*
sRep = summary~"$1"
sPat = summary\s?~\s*(%sPat1%\*%sPat1%)
sJql := RegExReplace(sJql,sPat,sRep)

sRep = description~"$1"
sPat = description\s?~\s*(%sPat1%\*%sPat1%)
sPat = (summary|description)\s?~\s*(%sPat1%\*%sPat1%)
sRep = $1~"$2"
sJql := RegExReplace(sJql,sPat,sRep)


Expand Down Expand Up @@ -272,110 +325,43 @@ If RegExMatch(sJql,needle)
sJql := RegExReplace(sJql, needle, " AND resolution = Unresolved")

; Default Project
needle := "\s\-?p\s([^\s]*)"
If RegExMatch(sJql,needle,sMatch) {
projectKey := sMatch1
sJql := RegExReplace(sJql, needle)
} Else {
defProjectKey := PowerTools_GetSetting("JiraProject")
If !(defProjectKey="")
projectKey := defProjectKey
}
If !(projectKey = "")
sDefJql = project = %projectKey%

sJql := RegExReplace(sJql,"^\s?AND ")
If !(sDefJql = "") {
If (sJql ="")
sJql := sDefJql
Else
sJql := sDefJql . " AND " . RegExReplace(sJql,"^\s?AND ")
If !RegExMatch(sJql,"project\s?=") {
needle := "\s\-?p\s([^\s]*)"
If RegExMatch(sJql,needle,sMatch) {
projectKey := sMatch1
sJql := RegExReplace(sJql, needle)
} Else {
defProjectKey := PowerTools_GetSetting("JiraProject")
If !(defProjectKey="")
projectKey := defProjectKey
}
If !(projectKey = "")
sDefJql = project = %projectKey%

sJql := RegExReplace(sJql,"^\sAND\s")
sJql := Trim(sJql)
If !(sDefJql = "") {
If (sJql ="")
sJql := sDefJql
Else
sJql := sDefJql . " AND " . RegExReplace(sJql,"^\sAND\s")
}
}

; Default Filter from ini file
JiraDefJql := PowerTools_IniRead("Jira","JiraDefJql")
If !(JiraDefJql="ERROR") {
If (sJql = "")
sJql := JiraDefJql
Else
sJql := JiraDefJql . " AND " . RegExReplace(sJql,"^\s?AND ")
sJql := JiraDefJql . " AND " . RegExReplace(sJql,"^\sAND\s")
}

sJql := RegExReplace(sJql,"^\s?AND ")
sJql := RegExReplace(sJql,"^\sAND\s")
If (sJql ="")
sJqlLabels := RegExReplace(sJqlLabels,"^\s?AND ")
Jira_OpenJql(sJql . sJqlLabels,jiraRootUrl)
} ; eofun

; ----------------------------------------------------------------------
; Jira Search - Search within current Jira Project
; Called by: NWS.ahk Quick Search (Win+F Hotkey)
Jira_Search(sUrl){
static S_JiraSearch, S_ProjectKey

RegExMatch(sUrl,"https?://[^/]*",sRootUrl)
ReRootUrl := StrReplace(sRootUrl,".","\.")
; issue detailed view
If RegExMatch(sUrl,ReRootUrl . "/browse/([^/]*)",sNewProjectKey) {
sNewProjectKey := RegExReplace(sNewProjectKey1,"-.*","")
If (sNewProjectKey = %S_ProjectKey%) and (!S_JiraSearch)
sDefSearch := S_JiraSearch
Else {
S_ProjectKey := sNewProjectKey
sDefSearch := "project=" . S_ProjectKey . " AND summary ~"
}
; filter view
} Else If RegExMatch(sUrl,ReRootUrl . "/issues/\?jql=(.*)",sJql) { ; <root>/issues/?jql=project%20%3D%20TPI%20AND%20summary%20~%20reuse
sJql := StrReplace(sJql1,"%20"," ")
sJql := StrReplace(sJql,"%3D","=")
sDefSearch := sJql
}

InputBox, sJql , Search string, Enter Jql string:,,640,125,,,,,%sDefSearch%
if ErrorLevel
return
S_JiraSearch := sJql
; Convert labels to Jql
sPat := "#([^#\s]*)"
Pos=1
While Pos := RegExMatch(sJql, sPat, label,Pos+StrLen(label)) {
sJqlLabels := sJqlLabels . " AND labels = " . label1
} ; end while

; remove labels from search string
sJql := RegExReplace(sJql, sPat , "")

sJql := Trim(sJql)
S_JiraSearch := sJql

; Enclose summary~ description~ with "" if using wildcards ? or * see https://tdalon.blogspot.com/2022/02/jira-partial-text-search.html
sPat1 = [^(?:\s*AND\s*|\s*OR\s*|"\*\(\))]*
;sPat1 = [^"]*
sRep = summary~"$1"
sPat = summary\s*~\s*(%sPat1%\*%sPat1%)
sJql := RegExReplace(sJql,sPat,sRep)

sRep = description~"$1"
sPat = description\s*~\s*(%sPat1%\*%sPat1%)
sJql := RegExReplace(sJql,sPat,sRep)

; Escape Html
sJql := StrReplace(sJql," ","%20")
sJql := StrReplace(sJql,"=","%3D")

sSearchUrl := sRootUrl . "/issues/?jql=" . sJql . sJqlLabels

If sJql ; not empty means update search
Send ^l
Else
Send ^n ; New Window
Sleep 500
Clip_Paste(sSearchUrl)
Send {Enter}
sJqlLabels := RegExReplace(sJqlLabels,"^\sAND\s")

return sJql . sJqlLabels
} ; eofun
; ----------------------------------------------------------------------


; ----------------------------------------------------------------------

Expand Down
3 changes: 2 additions & 1 deletion Lib/PowerTools.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ If !(DocMap="ERROR") {
sUrl :="https://tdalon.blogspot.com/2024/02/r4j-bulk-edit-folder.html"
Case "Jira_ViewLinkedIssues":
Case "Jira_OpenIssuesNav":
Case "Jira_CreateIssue":
Case "Jira_CreateIssue":
Case "Jira_QuickSearch":
Case "atlasy_openissue":
Case "r4j_CV" :
Case "r4j_CopyPathJql":
Expand Down

0 comments on commit d48baae

Please sign in to comment.