Skip to content

Commit

Permalink
change find-links function logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushgaud committed Sep 4, 2024
1 parent 331b3a5 commit d190e7a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 21 deletions.
20 changes: 1 addition & 19 deletions src/wrike_ist/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,9 @@
[wrike-ist.wrike :as wrike]
[wrike-ist.azure :as azure]))

;; (defn find-links
;; [text]
;; (not-empty (re-seq #"\bhttps://dev\.azure\.com/[^/]+/[^/]+/_workitems/edit/\d+\b" text)))

(defn find-links
[text]
(let [wrike-pattern #"\bhttps://www\.wrike\.com/open\.htm\?id=\d+\b"
azure-pattern #"\bhttps://dev\.azure\.com/[^/]+/[^/]+/_workitems/edit/\d+\b"
wrike-matches (re-seq wrike-pattern text)
azure-matches (re-seq azure-pattern text)]
(do
;; Print debug information
(js/console.log "Wrike Matches Found:" (first wrike-matches))
(js/console.log "Azure Matches Found:" (first azure-matches))

;; Combine results
(let [all-matches (concat (or wrike-matches []) (or azure-matches []))]
(if (seq all-matches)
(js/console.log "Matching links found:" all-matches)
all-matches
(js/console.log "No matching links found"))))))
(not-empty (re-seq #"\bhttps://www\.wrike\.com/open\.htm\?id=\d+\b|\bhttps://dev\.azure\.com/[^/]+/[^/]+/_workitems/edit/\d+\b" text)))

(defn extract-details
[pr-obj]
Expand Down
4 changes: 2 additions & 2 deletions test/wrike_ist/core_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
(is (= (list url) (find-links (str "a\n" url "\nb"))))))
(testing "Multiple links in text"
(let [url-1 "https://dev.azure.com/organization/project/_workitems/edit/1"
url-2 "https://dev.azure.com/organization/project/_workitems/edit/2"]
url-2 "https://www.wrike.com/open.htm?id=2"]
(is (= (list url-1 url-2) (find-links (str url-1 "\nfoo: " url-2 "\n"))))))
(testing "No separator around the link"
;; anything \b matches will do
Expand All @@ -36,7 +36,7 @@
(is (= url (:permalink (first (extract-details payload)))))))
(testing "Multiple links"
(let [url-1 "https://dev.azure.com/organization/project/_workitems/edit/1"
url-2 "https://dev.azure.com/organization/project/_workitems/edit/2"
url-2 "https://www.wrike.com/open.htm?id=2"
payload (clj->js {:body (str "a\n" url-1 "\nb " url-2)
:base (clj->js {:ref "feature-branch"})
:head (clj->js {:repo (clj->js {:name "your-repo-name"})})})]
Expand Down

0 comments on commit d190e7a

Please sign in to comment.