Skip to content

Commit cf2f55f

Browse files
author
Peter Jaros
authored
Merge pull request #1240 from circleci/revert-1226-move-users-endpoint-to-v1.1
Revert "Move users endpoint to v1.1"
2 parents af76a82 + 68f1167 commit cf2f55f

File tree

5 files changed

+31
-77
lines changed

5 files changed

+31
-77
lines changed

src-cljs/frontend/api/path.cljs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
(ns frontend.api.path
22
(:require [goog.string :as gstring]))
33

4-
(defn- base-project-url-path [vcs-type]
4+
(defn base-project-url-path [vcs-type]
55
(case vcs-type
66
"bitbucket" (gstring/format
77
"/api/dangerzone/project/%s"
88
vcs-type)
99
"github" "/api/v1/project"))
1010

11-
(defn- base-organization-url-path [vcs-type org-name]
12-
(gstring/format "/api/v1.1/%s/%s"
13-
(or vcs-type "github")))
14-
1511
(defn branch-path [vcs-type org-name repo-name branch]
1612
(gstring/format
1713
"%s/%s/%s/tree/%s"
@@ -68,20 +64,6 @@
6864
"%s/%s/enable"
6965
(base-project-url-path vcs-type) project))
7066

71-
(defn project-users [vcs-type project-name]
72-
(gstring/format "%s/%s/users"
73-
(base-project-url-path vcs-type)
74-
project-name))
75-
76-
(defn project-users-invite [vcs-type project-name]
77-
(gstring/format "%s/%s/users/invite"
78-
(base-project-url-path vcs-type)
79-
project-name))
80-
81-
(defn organization-invite [vcs-type org-name]
82-
(gstring/format "%s/invite"
83-
(base-organization-url-path vcs-type org-name)))
84-
8567
(defn build-retry [vcs-type org-name repo-name build-num]
8668
(gstring/format
8769
"%s/%s/%s/%s/retry"

src-cljs/frontend/components/build.cljs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,7 @@
143143
(when (build-model/display-build-invite build)
144144
(om/build invites/build-invites
145145
(:invite-data data)
146-
{:opts {:vcs-type (vcs-url/vcs-type (:vcs_url build))
147-
:project-name (vcs-url/project-name (:vcs_url build))}}))]]])))))
146+
{:opts {:project-name (vcs-url/project-name (:vcs_url build))}}))]]])))))
148147

149148
(defn container-result-icon [{:keys [name]} owner]
150149
(reify

src-cljs/frontend/components/invites.cljs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@
7171
:on-click #(raise! owner [:invited-github-users
7272
(merge {:invitees users-to-invite}
7373
(if (:project-name opts)
74-
{:project-name (:project-name opts)
75-
:vcs-type (:vcs-type opts)}
74+
{:project-name (:project-name opts)}
7675
{:org-name (:org-name opts)}))])})
7776

7877
"Send Invites "
@@ -82,10 +81,8 @@
8281
(reify
8382
om/IWillMount
8483
(will-mount [_]
85-
(let [project-name (:project-name opts)
86-
vcs-type (:vcs-type opts)]
87-
(raise! owner [:load-first-green-build-github-users {:vcs-type vcs-type
88-
:project-name project-name}])))
84+
(let [project-name (:project-name opts)]
85+
(raise! owner [:load-first-green-build-github-users {:project-name project-name}])))
8986
om/IRender
9087
(render [_]
9188
(let [project-name (:project-name opts)

src-cljs/frontend/controllers/controls.cljs

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -843,36 +843,33 @@
843843

844844

845845
(defmethod post-control-event! :load-first-green-build-github-users
846-
[target message {:keys [vcs-type project-name]} previous-state current-state]
847-
(if (or (nil? vcs-type) (= "github" vcs-type))
848-
(ajax/ajax :get
849-
(api-path/project-users vcs-type project-name)
850-
:first-green-build-github-users
851-
(get-in current-state [:comms :api])
852-
:context {:project-name project-name})))
846+
[target message {:keys [project-name]} previous-state current-state]
847+
(ajax/ajax :get
848+
(gstring/format "/api/v1/project/%s/users" project-name)
849+
:first-green-build-github-users
850+
(get-in current-state [:comms :api])
851+
:context {:project-name project-name}))
852+
853853

854854
(defmethod post-control-event! :invited-github-users
855-
[target message {:keys [vcs-type project-name org-name invitees]} previous-state current-state]
856-
(if (or (nil? vcs-type) (= "github" vcs-type))
857-
(let [project-vcs-type (or vcs-type "github")
858-
org-vcs-type "github"
859-
context (if project-name
860-
;; TODO: non-hackish way to indicate the type of invite
861-
{:project project-name :first_green_build true}
862-
{:org org-name})]
863-
(button-ajax :post
864-
(if project-name
865-
(api-path/project-users-invite project-vcs-type project-name)
866-
(api-path/organization-invite org-vcs-type org-name))
867-
:invite-github-users
868-
(get-in current-state [:comms :api])
869-
:context context
870-
:params invitees
871-
:events {:success #(analytics/track {:event-type :teammates-invited
872-
:current-state current-state
873-
:properties {:vcs-type :github
874-
:invitees invitees
875-
:invitee-count (count invitees)}})}))))
855+
[target message {:keys [project-name org-name invitees]} previous-state current-state]
856+
(let [context (if project-name
857+
;; TODO: non-hackish way to indicate the type of invite
858+
{:project project-name :first_green_build true}
859+
{:org org-name})]
860+
(button-ajax :post
861+
(if project-name
862+
(gstring/format "/api/v1/project/%s/users/invite" project-name)
863+
(gstring/format "/api/v1/organization/%s/invite" org-name))
864+
:invite-github-users
865+
(get-in current-state [:comms :api])
866+
:context context
867+
:params invitees
868+
:events {:success #(analytics/track {:event-type :teammates-invited
869+
:current-state current-state
870+
:properties {:vcs-type :github
871+
:invitees invitees
872+
:invitee-count (count invitees)}})})))
876873

877874
(defmethod post-control-event! :report-build-clicked
878875
[target message {:keys [build-url]} previous-state current-state]

test-cljs/frontend/controllers/controls_test.cljs

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
[frontend.state :as state]
55
[frontend.utils.ajax :as ajax]
66
[frontend.analytics.core :as analytics]
7-
[frontend.api.path :as api-path]
87
[frontend.controllers.controls :as controls]
98
[bond.james :as bond :include-macros true]
109
[goog.string :as gstring])
@@ -208,7 +207,6 @@
208207
(deftest post-control-event-invited-github-users-works
209208
(let [calls (atom [])
210209
project-name "proj"
211-
vcs-type "github"
212210
invitees ["me@foo.com", "you@bar.co"]
213211
control-data {:project-name project-name
214212
:org-name "org"
@@ -223,28 +221,9 @@
223221
args (-> calls first :args)]
224222
(is (= (count calls) 1))
225223
(is (= (nth args 0) :post))
226-
(is (= (nth args 1) (api-path/project-users-invite vcs-type project-name)))
224+
(is (= (nth args 1) (gstring/format "/api/v1/project/%s/users/invite" project-name)))
227225
(is (= (nth args 2) :invite-github-users))
228226
(is (= (nth args 3) api-ch))
229227
(is (= (->> (nth args 4) (apply hash-map) :context) {:project project-name
230228
:first_green_build true}))
231229
(is (= (->> (nth args 4) (apply hash-map) :params) invitees)))))))
232-
233-
(deftest post-control-event-invited-github-users-does-nothing-for-bb-projects
234-
(let [calls (atom [])
235-
project-name "proj"
236-
vcs-type "bitbucket"
237-
invitees ["me@foo.com", "you@bar.co"]
238-
control-data {:project-name project-name
239-
:vcs-type vcs-type
240-
:org-name "org"
241-
:invitees ["me@foo.com", "you@bar.co"]}
242-
api-ch "api-ch"
243-
current-state {:comms {:api api-ch}}]
244-
(testing "the post-control-event invite-github-users does nothing for bitbucket projects"
245-
(with-redefs [controls/button-ajax (fn [method url message channel & opts]
246-
(swap! calls conj {:args (list method url message channel opts)}))]
247-
(controls/post-control-event! {} :invited-github-users control-data {} current-state)
248-
(let [calls @calls
249-
args (-> calls first :args)]
250-
(is (= (count calls) 0)))))))

0 commit comments

Comments
 (0)