Skip to content

Commit

Permalink
Initial version for #17
Browse files Browse the repository at this point in the history
  • Loading branch information
skleinei committed Sep 6, 2022
1 parent 3d20600 commit c820a9e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ Alfred. Just hit type `c <search term>` to search for Confluence.

## Features

- Super simple configuration thanks to the new Workflow User Configuration in Alfred 5.
- Super simple configuration thanks to the new [Workflow User Configuration](https://www.alfredapp.com/alfred-5-whats-new/) in Alfred 5.
- Limit to search to single spaces by adding `-s <spacekey>` to the search terms
- Limit to search to content types by adding `-t <contentTypes>` to the search terms (<contenttypes> is a comma-separated list of `page`, `blogpost`, `attachment`, e.g. `page,attachment`)
- Directly edit pages when selecting a search result with `⌘Enter`
- Copy Confluence page URL with `⌘C`
- Displays page emojis 🥳
- Authentication via API token


Expand Down
15 changes: 10 additions & 5 deletions src/confluence-quicksearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import ast
import base64
import json
import re
import requests
import sys
import urllib
Expand Down Expand Up @@ -29,13 +30,17 @@ def parseArgs():
args = parser.parse_args()

args.textAsString = " ".join(args.text)
args.pathPrefix = ""
if re.search("atlassian.net", args.url) or re.search("jira.com", args.url):
args.pathPrefix = "/wiki"

return args


def searchConfluence(args):
response = requests.request(
"GET",
args.url + '/wiki/rest/api/search',
args.url + args.pathPrefix + '/rest/api/search',
headers = {
"Accept": "application/json",
"Authorization": createAuth(args)
Expand Down Expand Up @@ -98,7 +103,7 @@ def convertToAlfredItems(searchResults, args):
alfredItems.append({
"title": "No search results",
"subtitle": "Hit <enter> to do a full-text search for '" + args.textAsString + "' in Confluence",
"arg": args.url + "/wiki/search?text=" + urllib.parse.quote(args.textAsString),
"arg": args.url + args.pathPrefix + "/search?text=" + urllib.parse.quote(args.textAsString),
"icon": {
"path": "./assets/search-for.png"
},
Expand Down Expand Up @@ -145,7 +150,7 @@ def createSubtitle(result, args):


def createUrl(result, args):
return args.url + '/wiki' + result["url"]
return args.url + args.pathPrefix + result["url"]


def getIconPath(result, args):
Expand All @@ -162,7 +167,7 @@ def getMods(result, args):
if result["content"]["type"] == "blogpost" or result["content"]["type"] == "page":
mod["cmd"] = {
"valid": True,
"arg": args.url + '/wiki' + result["content"]["_links"]["editui"],
"arg": args.url + args.pathPrefix + result["content"]["_links"]["editui"],
"subtitle": "Open in editor"
}

Expand All @@ -175,7 +180,7 @@ def convertToTextResult(searchResults, args):
if len(searchResults) < 1:
textResult += "No search results found\n"
textResult += " Search Confluence for '" + args.textAsString + "':\n"
textResult += " " + args.url + "/wiki/search?text=" + urllib.parse.quote(args.textAsString)
textResult += " " + args.url + args.pathPrefix + "/search?text=" + urllib.parse.quote(args.textAsString)

for result in searchResults:
textResult += "· " + createTitle(result, args) + "\n"
Expand Down

0 comments on commit c820a9e

Please sign in to comment.