-
Notifications
You must be signed in to change notification settings - Fork 9
#353 | Pull request reminder widget (github / bitbucket) #403
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
base: master
Are you sure you want to change the base?
Changes from all commits
3ec904f
13f9028
aa3ec40
78867d8
53ffcf5
53f7cc8
fe5980b
1d44b5a
f03e91e
791ba63
572ddb4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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")) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use switch-case on |
||
| pullRequests = | ||
| pullRequests | ||
| .put(Props.PULL_REQUESTS, responseBody.remove("array")) | ||
| .put(Props.REPOSITORY_HUB, "github") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move this logic to a seprate class so we can just:
You can do this as an extension method on string class also. |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| } | ||
| ] | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
after the introduction of
apiTypedropdown this will not be required.