Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class CogboardConstants {
const val JQL_QUERY = "jqlQuery"
const val BUCKET_QUERIES = "bucketQueries"
const val BUCKET_NAME = "bucketName"
const val PULL_REQUESTS = "pullRequests"
const val REPOSITORY_HUB = "repositoryHub"
Copy link
Contributor

@szymon-owczarzak szymon-owczarzak Jul 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after the introduction of apiType dropdown this will not be required.

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.cognifide.cogboard.widget.type.WorldClockWidget
import com.cognifide.cogboard.widget.type.randompicker.RandomPickerWidget
import com.cognifide.cogboard.widget.type.sonarqube.SonarQubeWidget
import com.cognifide.cogboard.widget.type.zabbix.ZabbixWidget
import com.cognifide.cogboard.widget.type.PullRequestReminderWidget
import io.vertx.core.Vertx
import io.vertx.core.json.JsonArray
import io.vertx.core.json.JsonObject
Expand Down Expand Up @@ -48,7 +49,8 @@ class WidgetIndex {
"Jira Buckets" to JiraBucketsWidget::class.java,
"Service Check" to ServiceCheckWidget::class.java,
"SonarQube" to SonarQubeWidget::class.java,
"White Space" to WhiteSpaceWidget::class.java
"White Space" to WhiteSpaceWidget::class.java,
"Pull Request Reminder" to PullRequestReminderWidget::class.java,
)

fun availableWidgets(): JsonArray {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.cognifide.cogboard.widget.type

import com.cognifide.cogboard.CogboardConstants.Props
import com.cognifide.cogboard.config.service.BoardsConfigService
import com.cognifide.cogboard.widget.AsyncWidget
import io.vertx.core.Vertx
import io.vertx.core.json.JsonObject

class PullRequestReminderWidget(vertx: Vertx, config: JsonObject, serv: BoardsConfigService) :
AsyncWidget(vertx, config, serv) {

private var path: String = config.getString("path", "")

override fun handleResponse(responseBody: JsonObject) {
var pullRequests = responseBody

if (url.contains("github")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use switch-case on apiType instead

pullRequests =
pullRequests
.put(Props.PULL_REQUESTS, responseBody.remove("array"))
.put(Props.REPOSITORY_HUB, "github")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to send this property

} else {
pullRequests =
pullRequests
.put(Props.PULL_REQUESTS, responseBody.remove("values"))
.put(Props.REPOSITORY_HUB, "bitbucket")
}

send(pullRequests)
}

override fun updateState() {

if (url.isBlank() || path.isBlank()) {
sendConfigurationError("Endpoint URL or Path is blank.")
}

if (url.contains("github")) {
var (_, owner, repo) = path.split("/")
var apiUrl = url.replace("://", "://api.").replace("com/", "com")
httpGet("$apiUrl/repos/$owner/$repo/pulls")
} else if (url.contains("bitbucket") && path.contains("dashboard")) {
httpGet("$url/rest/api/1.0/dashboard/pull-requests")
return
} else {
var (_, project, repo) = path.split("/")
httpGet(url = "$url/rest/api/1.0/projects/$project/repos/$repo/pull-requests")
}
Comment on lines +38 to +48
Copy link
Contributor

@szymon-owczarzak szymon-owczarzak Jul 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this logic to a seprate class so we can just:

httpGet(UrlUtil.getApiUrl(apiType, url, project, repository))

You can do this as an extension method on string class also.
httpGet(url.getApiUrl(apiType, project, repository))
https://kotlinlang.org/docs/extensions.html#extension-functions
write Unit tests for supported examples

}
}
21 changes: 20 additions & 1 deletion cogboard-app/src/main/resources/initData/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@
"widget90",
"widget93",
"widget94",
"widget74"
"widget74",
"widget95"
],
"autoSwitch": true,
"columns": 8,
Expand Down Expand Up @@ -1938,6 +1939,24 @@
"installedThreshold": 2,
"excludedBundles": "",
"expandContent": false
},
"widget95": {
"id": "widget95",
"title": "Pull Requests Cogboard",
"config": {
"columns": 2,
"goNewLine": false,
"rows": 1
},
"type": "PullRequestReminderWidget",
"disabled": false,
"content": {},
"isUpdating": false,
"boardId": "board-9ebbc895-41e7-45b3-b6be-2e88b8dd4e5b",
"endpoint": "endpoint4",
"schedulePeriod": 1800,
"path": "/wttech/cogboard",
"expandContent": false
}
}
}
Expand Down
16 changes: 15 additions & 1 deletion cogboard-app/src/main/resources/initData/endpoints.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@
"publicUrl": "http://api-mocks:8080/zabbix/api_jsonrpc.php",
"credentials": "credential1",
"id": "endpoint3"
},
{
"id": "endpoint4",
"label": "Github",
"publicUrl": "https://github.com/",
"url": "https://github.com/",
"credentials": ""
},
{
"id": "endpoint5",
"label": "Bitbucket Cognifide",
"publicUrl": "https://bitbucket.cognifide.com/",
"url": "https://bitbucket.cognifide.com/",
"credentials": ""
Comment on lines +24 to +29
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this and instead add support to our Api Mocks - and mimic a response there. Please make sure you are not providing any sensitiva data.

}
]
}
}
4 changes: 2 additions & 2 deletions cogboard-local-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ services:
- "./mnt:/data"
networks:
- cognet
# ports:
# - "18092:18092"
# ports:
# - "18092:18092"

frontend:
image: "cogboard/cogboard-web:${COGBOARD_VERSION}"
Expand Down
Loading