Skip to content

Commit

Permalink
fix:json snake-case deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
cunla committed Nov 11, 2023
1 parent 39dbdd1 commit 2953451
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 46 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

## [Unreleased]

## [1.15.0]

### 🐛 Bug Fixes

- Using camel-case variable names in POJOs #99

## [1.14.0]

### 🚀 Features
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pluginGroup=com.dsoftware.ghmanager
pluginName=github-actions-manager

# SemVer format -> https://semver.org
pluginVersion=1.14.0
pluginVersion=1.15.0

# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild=231.8109.175
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,20 @@ abstract class PostUrlAction(
class CancelWorkflowAction : PostUrlAction("Cancel Workflow", null, AllIcons.Actions.Cancel) {
override fun update(e: AnActionEvent) {
val context = e.dataContext.getData(ActionKeys.SELECTED_WORKFLOW_RUN)
val url = context?.cancel_url
val url = context?.cancelUrl
val status = context?.status
e.presentation.isEnabledAndVisible = (url != null) && (status == "in_progress" || status == "queued")
}

override fun getUrl(dataContext: DataContext): String? {
dataContext.getData(CommonDataKeys.PROJECT) ?: return null
return dataContext.getData(ActionKeys.SELECTED_WORKFLOW_RUN)?.cancel_url
return dataContext.getData(ActionKeys.SELECTED_WORKFLOW_RUN)?.cancelUrl
}
}

class RerunWorkflowAction : PostUrlAction("Rerun Workflow", null, AllIcons.Actions.Rerun) {
override fun getUrl(dataContext: DataContext): String? {
dataContext.getData(CommonDataKeys.PROJECT) ?: return null
return dataContext.getData(ActionKeys.SELECTED_WORKFLOW_RUN)?.rerun_url
return dataContext.getData(ActionKeys.SELECTED_WORKFLOW_RUN)?.rerunUrl
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class WorkflowOpenInBrowserAction : OpenInBrowserAction("Open this workflow run

override fun getData(dataContext: DataContext): String? {
dataContext.getData(CommonDataKeys.PROJECT) ?: return null
return dataContext.getData(ActionKeys.SELECTED_WORKFLOW_RUN)?.html_url
return dataContext.getData(ActionKeys.SELECTED_WORKFLOW_RUN)?.htmlUrl
}
}

Expand All @@ -58,7 +58,7 @@ class PullRequestOpenInBrowserAction : OpenInBrowserAction("Open Pull-Request in
dataContext.getData(CommonDataKeys.PROJECT) ?: return null
LOG.info("${dataContext.getData(ActionKeys.SELECTED_WORKFLOW_RUN)?.url}")
val run = dataContext.getData(ActionKeys.SELECTED_WORKFLOW_RUN) ?: return null
val pullRequestNumber = run.pull_requests?.firstOrNull()?.number ?: return null
return "${run.repository.html_url}/pull/$pullRequestNumber"
val pullRequestNumber = run.pullRequests?.firstOrNull()?.number ?: return null
return "${run.repository.htmlUrl}/pull/$pullRequestNumber"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.fasterxml.jackson.annotation.JsonFormat
import java.util.Date

data class WorkflowRunJobsList(
val total_count: Int,
val totalCount: Int,
val jobs: List<Job>
)

Expand Down
50 changes: 25 additions & 25 deletions src/main/kotlin/com/dsoftware/ghmanager/api/model/RunModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import java.util.Date


data class WorkflowTypes(
val total_count: Int,
val totalCount: Int,
val workflows: List<WorkflowType> = emptyList()
)

Expand All @@ -25,55 +25,55 @@ data class PullRequest(
)

data class WorkflowRuns(
val total_count: Int,
val workflow_runs: List<WorkflowRun> = emptyList()
val totalCount: Int,
val workflowRuns: List<WorkflowRun> = emptyList()
)

data class WorkflowRun(
val id: Long,
val path: String?,
val node_id: String,
val head_branch: String?,
val head_sha: String?,
val run_number: Int,
val nodeId: String,
val headBranch: String?,
val headSha: String?,
val runNumber: Int,
val event: String,
val status: String,
val conclusion: String?,
val url: String,
val html_url: String,
val htmlUrl: String,
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'", timezone = "UTC")
val created_at: Date?,
val createdAt: Date?,
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'", timezone = "UTC")
val updated_at: Date?,
val jobs_url: String,
val logs_url: String,
val check_suite_url: String,
val artifacts_url: String,
val cancel_url: String,
val rerun_url: String,
val workflow_id: Long,
val workflow_url: String,
val updatedAt: Date?,
val jobsUrl: String,
val logsUrl: String,
val checkSuiteUrl: String,
val artifactsUrl: String,
val cancelUrl: String,
val rerunUrl: String,
val workflowId: Long,
val workflowUrl: String,
val name: String,
val head_commit: GitHubHeadCommit,
val headCommit: GitHubHeadCommit,
val repository: GitHubRepository,
val pull_requests: List<PullRequest>? = emptyList(),
val pullRequests: List<PullRequest>? = emptyList(),
) : Comparable<WorkflowRun> {

/**
* Compare workflows by their updated_at, or created_at (the newest first), or by id run_number both dates are null
* @param other The other workflow to compare to
*/
override fun compareTo(other: WorkflowRun): Int {
return other.updated_at?.compareTo(this.updated_at)
?: other.created_at?.compareTo(this.created_at)
?: other.run_number.compareTo(this.run_number)
return other.updatedAt?.compareTo(this.updatedAt)
?: other.createdAt?.compareTo(this.createdAt)
?: other.runNumber.compareTo(this.runNumber)
}
}

data class GitHubRepository(
val id: Int,
val pulls_url: String,
val html_url: String,
val pullsUrl: String,
val htmlUrl: String,
)

data class GitHubHeadCommit(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ class SingleRunDataLoader(


fun getLogsDataProvider(workflowRun: WorkflowRun): WorkflowRunLogsDataProvider {
return cache.get(workflowRun.logs_url) {
WorkflowRunLogsDataProvider(progressManager, requestExecutor, workflowRun.logs_url)
return cache.get(workflowRun.logsUrl) {
WorkflowRunLogsDataProvider(progressManager, requestExecutor, workflowRun.logsUrl)
} as WorkflowRunLogsDataProvider
}

fun getJobsDataProvider(workflowRun: WorkflowRun): WorkflowRunJobsDataProvider {
return cache.get(workflowRun.jobs_url) {
WorkflowRunJobsDataProvider(progressManager, requestExecutor, workflowRun.jobs_url)
return cache.get(workflowRun.jobsUrl) {
WorkflowRunJobsDataProvider(progressManager, requestExecutor, workflowRun.jobsUrl)
} as WorkflowRunJobsDataProvider
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class WorkflowRunListLoader(
LOG.info("Calling ${request.url}")
val response = requestExecutor.execute(indicator, request)
workflowTypesSet.addAll(response.workflows)
} while (nextPage * 100 < response.total_count)
} while (nextPage * 100 < response.totalCount)
workflowTypes.clear()
workflowTypes.addAll(workflowTypesSet)
}
Expand Down Expand Up @@ -204,8 +204,8 @@ class WorkflowRunListLoader(
)
LOG.info("Calling ${request.url}")
val wfRunsResponse = requestExecutor.execute(indicator, request)
totalCount = wfRunsResponse.total_count
val workflowRuns = wfRunsResponse.workflow_runs
totalCount = wfRunsResponse.totalCount
val workflowRuns = wfRunsResponse.workflowRuns
if (update) {
val existingRunIds = listModel.items.mapIndexed { idx, it -> it.id to idx }.toMap()
val newRuns = workflowRuns.filter { !existingRunIds.contains(it.id) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class JobListComponent(
infoPanel.setInfo("")
it?.let {
list.add(it.jobs)
infoPanel.setInfo("${it.total_count} jobs loaded")
infoPanel.setInfo("${it.totalCount} jobs loaded")
}
}
val listComponent = JobListComponent(list, infoInNewLine).apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,21 +143,21 @@ class WorkflowRunList(model: ListModel<WorkflowRun>) :

stateIcon.icon = ToolbarUtil.statusIcon(ghWorkflowRun.status, ghWorkflowRun.conclusion)
title.apply {
text = ghWorkflowRun.head_commit.message.split("\n")[0]
text = ghWorkflowRun.headCommit.message.split("\n")[0]
foreground = primaryTextColor
}

info.apply {
val updatedAtLabel = ToolbarUtil.makeTimePretty(ghWorkflowRun.updated_at)
val updatedAtLabel = ToolbarUtil.makeTimePretty(ghWorkflowRun.updatedAt)
val action = if (ghWorkflowRun.event == "release") "created by" else "pushed by"

text = "${ghWorkflowRun.name} #${ghWorkflowRun.run_number}: " +
"$action ${ghWorkflowRun.head_commit.author.name} started $updatedAtLabel"
text = "${ghWorkflowRun.name} #${ghWorkflowRun.runNumber}: " +
"$action ${ghWorkflowRun.headCommit.author.name} started $updatedAtLabel"
foreground = secondaryTextColor
}
labels.apply {
removeAll()
add(JBLabel(" ${ghWorkflowRun.head_branch} ", UIUtil.ComponentStyle.SMALL).apply {
add(JBLabel(" ${ghWorkflowRun.headBranch} ", UIUtil.ComponentStyle.SMALL).apply {
foreground = JBColor(ColorUtil.softer(secondaryTextColor), ColorUtil.softer(secondaryTextColor))
})
add(Box.createRigidArea(JBDimension(4, 0)))
Expand Down

0 comments on commit 2953451

Please sign in to comment.