Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#259 | New Widget - Jira Buckets #261

Merged
merged 25 commits into from
Jun 5, 2020
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
9fda9fa
Widget index updated.
Apr 20, 2020
3a09040
Working backend (work in progress)
Apr 22, 2020
a955420
Widget is now usable, some styling and bug fixing still in progress.
Apr 24, 2020
74da9f1
Merge remote-tracking branch 'origin/master' into Jira-buckets-widget
Apr 27, 2020
0f9e93b
Dialog styling, some bugfixes, and issue limit raised from 50 to 500.
Apr 28, 2020
cb45d3b
Issue limit is not configurable in dialog
Apr 30, 2020
cd71eed
Issue limit is not configurable in dialog.
Apr 30, 2020
df65848
Question mark deleted from the widget header.
Apr 30, 2020
6dc5daa
Renaming variables, fixing overflow and small bucket saving bug.
Apr 30, 2020
c7e6b4d
Constants added, console.logs deleted, minor refactor in JiraBucketWi…
May 4, 2020
5e9823c
Widget back-end refactor
May 5, 2020
456f340
Saving with the button fixed
May 5, 2020
4c88fc6
Mocked endpoint added.
May 13, 2020
b7fd57e
Jira bucket widget -> jira buckets widget
May 13, 2020
7dee913
Cypress tests implemented.
May 13, 2020
1ef0f3d
tests deleted tmp
May 13, 2020
d54d674
Cypress test refactor.
May 13, 2020
7528d40
Small refactor
May 14, 2020
bf2c736
Unnecessary variable deleted.
May 14, 2020
fc2a39b
One mocked issue added so there is different amount in every bucket.
May 14, 2020
5031c98
Buckets input refactor
May 20, 2020
4ef37c2
Added some error handling for bucket error
May 20, 2020
1df54d0
Widget now links to Jira
May 25, 2020
70adccf
Merge branch 'Jira-buckets-widget' of https://github.com/Cognifide/co…
May 25, 2020
0921973
Buckets widget added to default board.
Jun 2, 2020
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 @@ -28,6 +28,7 @@ class CogboardConstants {
const val PROP_SCHEDULE_PERIOD_DEFAULT = 120L // 120 seconds
const val PROP_SCHEDULE_DELAY_DEFAULT = 10L // 10 seconds
const val PROP_URL = "url"
const val PROP_REQUEST_ID = "requestId"
const val PROP_PUBLIC_URL = "publicUrl"
const val PROP_USER = "user"
const val PROP_PASSWORD = "password"
Expand All @@ -46,7 +47,12 @@ class CogboardConstants {
const val PROP_TEXT_SIZE = "textSize"
const val PROP_BOARD_COLUMN_MAX = 20
const val PROP_BOARD_COLUMN_MIN = 4
const val PROP_NAME = "name"
const val PROP_RELEASE_NAME = "releaseName"
const val PROP_JQL_QUERY = "jqlQuery"
const val PROP_ISSUE_LIMIT = "issueLimit"
const val PROP_BUCKET_QUERIES = "bucketQueries"
const val PROP_BUCKET_NAME = "bucketName"

const val EVENT_SEND_MESSAGE_TO_WEBSOCKET = "cogboard.websocket.message"
const val EVENT_VERSION_CONFIG = "cogboard.config.handler.version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,12 @@ class HttpClient : AbstractVerticle() {
val request = initRequest(httpRequest, config)
val address = config.getString(CogboardConstants.PROP_EVENT_ADDRESS)
val body = config.getJsonObject(CogboardConstants.PROP_BODY)
val requestId = config.getString(CogboardConstants.PROP_REQUEST_ID) ?: ""

body?.let {
executeCheckRequest(request, address, body)
} ?: run {
executeRequest(request, address)
executeRequest(request, address, requestId)
}
}

Expand Down Expand Up @@ -111,17 +112,19 @@ class HttpClient : AbstractVerticle() {
}
}

private fun executeRequest(request: HttpRequest<Buffer>, address: String?) {
private fun executeRequest(request: HttpRequest<Buffer>, address: String?, requestId: String) {
request.send {
if (!it.succeeded()) {
vertx.eventBus().send(address, JsonObject()
.put(CogboardConstants.PROP_ERROR_MESSAGE, "Http Error")
.put(CogboardConstants.PROP_ERROR_CAUSE, it.cause()?.message))
.put(CogboardConstants.PROP_ERROR_CAUSE, it.cause()?.message)
.put(CogboardConstants.PROP_REQUEST_ID, requestId))
LOGGER.error(it.cause()?.message)
} else {
toJson(it.result()).let { json ->
json.put(PROP_STATUS_CODE, it.result().statusCode())
json.put(PROP_STATUS_MESSAGE, it.result().statusMessage())
json.put(CogboardConstants.PROP_REQUEST_ID, requestId)
vertx.eventBus().send(address, json)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ abstract class AsyncWidget(
*/
abstract fun handleResponse(responseBody: JsonObject)

protected fun httpGet(url: String) {
protected fun httpGet(url: String, requestId: String = "") {
vertx.eventBus().send(CogboardConstants.EVENT_HTTP_GET,
JsonObject()
.put(CogboardConstants.PROP_URL, url)
.put(CogboardConstants.PROP_REQUEST_ID, requestId)
.put(CogboardConstants.PROP_EVENT_ADDRESS, eventBusAddress)
.put(CogboardConstants.PROP_USER, user)
.put(CogboardConstants.PROP_PASSWORD, password)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.cognifide.cogboard.widget.type.persondraw.PersonDrawWidget
import com.cognifide.cogboard.widget.type.ServiceCheckWidget
import com.cognifide.cogboard.widget.type.sonarqube.SonarQubeWidget
import com.cognifide.cogboard.widget.type.TextWidget
import com.cognifide.cogboard.widget.type.JiraBucketWidget
import com.cognifide.cogboard.widget.type.WorldClockWidget
import com.cognifide.cogboard.widget.type.AemBundleInfoWidget
import io.vertx.core.Vertx
Expand All @@ -33,6 +34,7 @@ class WidgetIndex {
BambooPlanWidget::class.java.simpleName -> BambooPlanWidget(vertx, config)
AemHealthcheckWidget::class.java.simpleName -> AemHealthcheckWidget(vertx, config)
TextWidget::class.java.simpleName -> TextWidget(vertx, config)
JiraBucketWidget::class.java.simpleName -> JiraBucketWidget(vertx, config)
IframeEmbedWidget::class.java.simpleName -> IframeEmbedWidget(vertx, config)
WorldClockWidget::class.java.simpleName -> WorldClockWidget(vertx, config)
CheckboxWidget::class.java.simpleName -> CheckboxWidget(vertx, config)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.cognifide.cogboard.widget.type

import com.cognifide.cogboard.widget.AsyncWidget
import io.vertx.core.Vertx
import io.vertx.core.json.JsonArray
import io.vertx.core.json.JsonObject
import com.cognifide.cogboard.CogboardConstants as CC

class JiraBucketWidget(vertx: Vertx, config: JsonObject) : AsyncWidget(vertx, config) {

private val bucketQueries: JsonArray = config.getJsonArray(CC.PROP_BUCKET_QUERIES)
private val buckets: JsonArray = prepareBuckets()

private fun prepareBuckets(): JsonArray {
szymon-owczarzak marked this conversation as resolved.
Show resolved Hide resolved
val preparedBuckets = JsonArray()
bucketQueries.forEach {
if (it is JsonObject) {
preparedBuckets.add(JsonObject()
.put(CC.PROP_ID, it.getString(CC.PROP_ID))
.put(CC.PROP_NAME, it.getString(CC.PROP_BUCKET_NAME)))
}
}
return preparedBuckets
}

override fun handleResponse(responseBody: JsonObject) {
val response = JsonObject()
val issues = responseBody.getJsonArray("issues").size()
val bucketId = responseBody.getString(CC.PROP_REQUEST_ID)

buckets.forEach {
val key = (it as JsonObject).getString(CC.PROP_ID)
if (bucketId == key) {
it.put("issueCounts", issues)
szymon-owczarzak marked this conversation as resolved.
Show resolved Hide resolved
}
}
response.put("buckets", buckets)
send(JsonObject()
.put(CC.PROP_CONTENT, response))
szymon-owczarzak marked this conversation as resolved.
Show resolved Hide resolved
}

override fun updateState() {
if (url.isNotBlank()) {
for (bucketQuery in bucketQueries.list) {
if (bucketQuery is JsonObject) {
val bucketId = bucketQuery.getString(CC.PROP_ID)
val jqlQuery = bucketQuery.getString(CC.PROP_JQL_QUERY)
val issueLimit = config.getInteger(CC.PROP_ISSUE_LIMIT)
httpGet(url = "$url/jira/rest/api/2/search?jql=$jqlQuery&maxResults=$issueLimit", requestId = bucketId)
}
}
} else {
sendConfigurationError("Endpoint URL is blank.")
}
}
}
Loading