|
1 | 1 | package com.codacy.client.bitbucket.service
|
2 | 2 |
|
3 |
| -import com.codacy.client.bitbucket.Service |
| 3 | +import com.codacy.client.bitbucket.{Webhook, Service} |
4 | 4 | import com.codacy.client.bitbucket.client.{BitbucketClient, Request, RequestResponse}
|
5 | 5 | import play.api.libs.json.Json
|
6 | 6 |
|
7 | 7 | class HookServices(client: BitbucketClient) {
|
8 | 8 |
|
9 |
| - def list(author: String, repo: String): RequestResponse[Seq[Service]] = { |
| 9 | + def list(author: String, repo: String): RequestResponse[Seq[Webhook]] = { |
10 | 10 | val servicesUrl = getServicesUrl(author, repo)
|
11 |
| - client.execute(Request(servicesUrl, classOf[Seq[Service]])) |
| 11 | + client.executePaginated(Request(servicesUrl, classOf[Seq[Webhook]])) |
12 | 12 | }
|
13 | 13 |
|
14 |
| - def create(author: String, repo: String, hookType: String, hookUrl: String): RequestResponse[Service] = { |
| 14 | + def create(author: String, repo: String, description: String, hookUrl: String, events:Set[String]): RequestResponse[Webhook] = { |
15 | 15 | val servicesUrl = getServicesUrl(author, repo)
|
16 | 16 | val payload = Json.obj(
|
17 |
| - "type" -> hookType, |
18 |
| - "URL" -> hookUrl |
| 17 | + "active" -> true, |
| 18 | + "description" -> description, |
| 19 | + "url" -> hookUrl, |
| 20 | + "events" -> events |
19 | 21 | )
|
20 |
| - client.post(Request(servicesUrl, classOf[Service]), payload) |
| 22 | + client.post(Request(servicesUrl, classOf[Webhook]), payload) |
21 | 23 | }
|
22 | 24 |
|
23 |
| - def delete(author: String, repo: String, id: Long): RequestResponse[Boolean] = { |
| 25 | + def delete(author: String, repo: String, uuid: String): RequestResponse[Boolean] = { |
24 | 26 | val servicesUrl = getServicesUrl(author, repo)
|
25 |
| - client.delete(s"$servicesUrl/$id") |
| 27 | + client.delete(s"$servicesUrl/$uuid") |
26 | 28 | }
|
27 | 29 |
|
28 |
| - private lazy val BASE_URL: String = "https://bitbucket.org/!api/1.0/repositories" |
| 30 | + private[this] lazy val BASE_URL: String = "https://api.bitbucket.org/2.0/repositories" |
29 | 31 |
|
30 |
| - private def getServicesUrl(author: String, repo: String) = s"$BASE_URL/$author/$repo/services" |
| 32 | + private[this] def getServicesUrl(owner: String, repo: String) = s"$BASE_URL/$owner/$repo/hooks" |
31 | 33 |
|
32 | 34 | }
|
0 commit comments