Skip to content

Commit

Permalink
CID-2086: Add logs
Browse files Browse the repository at this point in the history
  • Loading branch information
henriqamaral committed Nov 7, 2023
1 parent 6ee9db1 commit dba63e5
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import java.time.LocalDate
@Service
class DoraService(
private val githubRepositoryProvider: GithubRepositoryProvider,
private val doraProvider: DoraProvider
) {
private val doraProvider: DoraProvider,
) : BaseConnectorService() {

private val logger = LoggerFactory.getLogger(DoraService::class.java)

Expand All @@ -29,9 +29,14 @@ class DoraService(
if (it.isEmpty()) {
logger.info(
"Repository does not have any valid pull requests for DORA metrics. " +
"Repository: ${repository.name}"
"Repository: ${repository.name}",
)
} else {
logInfoMessages(
code = "vsm.dora.success",
arguments = arrayOf(repository.name),
assignment = assignment,
)
it.forEach { dora ->
doraProvider.saveDora(dora, assignment, repository)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ class RepositoriesService(
}

private fun getRepositoriesPaginated(assignment: Assignment) {
logInfoMessages("vsm.repos.started", arrayOf(assignment.organizationName), assignment)
var cursor: String? = null
var totalRepos = 0
var page = 1
do {
logInfoMessages("vsm.repos.page", arrayOf(page), assignment)
val repos = githubRepositoryProvider
.getAllRepositories(assignment.organizationName, cursor)
.getOrElse {
Expand All @@ -35,8 +38,10 @@ class RepositoriesService(
repositories
.forEach { repositoryService.save(it, assignment, STATE) }
cursor = repos.cursor
page++
} while (repos.hasNextPage)
logInfoMessages("vsm.repos.total", arrayOf(totalRepos), assignment)
logInfoMessages("vsm.repos.finished", arrayOf(assignment.organizationName), assignment)
}

private fun handleExceptions(exception: Throwable, assignment: Assignment) {
Expand Down
6 changes: 5 additions & 1 deletion src/main/resources/messages.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
vsm.repos.not_found=Zero repositories found in {0} GitHub organisation. Hint: In case organisation is valid, check if the inclusion list has at least one valid repository name.
vsm.repos.total=Fetched Org Repositories Ids. Result : {0} repos
vsm.repos.imported=Repository Imported
vsm.repos.imported=Repository Imported
vsm.repos.started=Started fetching repositories for organization: {0}
vsm.repos.finished=Finished fetching repositories for organization: {0}
vsm.repos.page=Fetching repositories page: {0}
vsm.dora.success=DORA generated successfully for repository {0}
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class GitHubWebhookControllerTest {

await.untilAsserted {
WireMock.verify(1, WireMock.postRequestedFor(WireMock.urlEqualTo("/services")))
WireMock.verify(1, WireMock.postRequestedFor(WireMock.urlEqualTo("/logs/admin")))
WireMock.verify(2, WireMock.postRequestedFor(WireMock.urlEqualTo("/logs/admin")))
}
}

Expand All @@ -148,7 +148,7 @@ class GitHubWebhookControllerTest {
)
WireMock.verify(0, WireMock.postRequestedFor(WireMock.urlEqualTo("/languages")))
WireMock.verify(0, WireMock.postRequestedFor(WireMock.urlEqualTo("/topics")))
WireMock.verify(1, WireMock.postRequestedFor(WireMock.urlEqualTo("/logs/admin")))
WireMock.verify(2, WireMock.postRequestedFor(WireMock.urlEqualTo("/logs/admin")))
}
}
}
Expand All @@ -173,7 +173,7 @@ class GitHubWebhookControllerTest {

await.untilAsserted {
WireMock.verify(1, WireMock.postRequestedFor(WireMock.urlEqualTo("/services")))
WireMock.verify(1, WireMock.postRequestedFor(WireMock.urlEqualTo("/logs/admin")))
WireMock.verify(2, WireMock.postRequestedFor(WireMock.urlEqualTo("/logs/admin")))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class InitialStateTest {
WireMock.verify(4, postRequestedFor(urlEqualTo("/services")))
WireMock.verify(0, postRequestedFor(urlEqualTo("/languages")))
WireMock.verify(0, postRequestedFor(urlEqualTo("/topics")))
WireMock.verify(8, postRequestedFor(urlEqualTo("/logs/admin")))
WireMock.verify(18, postRequestedFor(urlEqualTo("/logs/admin")))
WireMock.verify(4, postRequestedFor(urlEqualTo("/dora")))
}
}
Expand Down

0 comments on commit dba63e5

Please sign in to comment.