-
Notifications
You must be signed in to change notification settings - Fork 2
Feature/cid 2745/get list of repositories and manifest files and send data to backend #8
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
Merged
mohamedlajmileanix
merged 15 commits into
main
from
feature/CID-2745/get-list-of-repositories-and-manifest-files-and-send-data-to-backend
Jul 25, 2024
Merged
Changes from 3 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
8e1be09
CID-2744: fetch and broadcast repositories
mohamedlajmileanix dfe956f
CID-2744: add nodeId for organisations
mohamedlajmileanix f50762f
CID-2744: update README.md
mohamedlajmileanix 99bfb85
CID-2744: change manifestFilePath to manifestFileDirectory
mohamedlajmileanix 927ec58
CID-2744: add test for getting ghe repositories
mohamedlajmileanix 238d9bd
Update README.md
mohamedlajmileanix 894c080
CID-2744: update page count
mohamedlajmileanix 1c2d43a
Merge remote-tracking branch 'origin/feature/CID-2745/get-list-of-rep…
mohamedlajmileanix 1ef6b49
CID-2744: refactor function labels
mohamedlajmileanix 9dfedf6
CID-2744: remove println statement and add logging statements
mohamedlajmileanix 68f0dbc
CID-2744: addressing PR comments, add runId in calls to backend, and …
mohamedlajmileanix 2579b27
CID-2744: refine tests for backend calls that include runId
mohamedlajmileanix 1c880c1
CID-2744: update ws url and remove nodeId for organization
mohamedlajmileanix e47de92
CID-2744: addressing PR comments using organisation name instead of n…
mohamedlajmileanix d562bf1
CID-2744: remove unused organisation nodeId
mohamedlajmileanix File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/net/leanix/githubagent/dto/PagedRepositories.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package net.leanix.githubagent.dto | ||
|
|
||
| data class PagedRepositories( | ||
| val repositories: List<RepositoryDto>, | ||
| val hasNextPage: Boolean, | ||
| val cursor: String? = null | ||
| ) |
17 changes: 17 additions & 0 deletions
17
src/main/kotlin/net/leanix/githubagent/dto/RepositoryDto.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package net.leanix.githubagent.dto | ||
|
|
||
| data class RepositoryDto( | ||
| val id: String, | ||
| val name: String, | ||
| val description: String?, | ||
| val url: String, | ||
| val organization: RepositoryOrganizationDto, | ||
| val languages: List<String>, | ||
| val topics: List<String>, | ||
| val manifest: String?, | ||
| ) | ||
|
|
||
| class RepositoryOrganizationDto( | ||
mohamedlajmileanix marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| val id: String, | ||
| val name: String | ||
| ) | ||
4 changes: 4 additions & 0 deletions
4
src/main/kotlin/net/leanix/githubagent/exceptions/Exceptions.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,13 @@ | ||
| package net.leanix.githubagent.exceptions | ||
|
|
||
| import com.expediagroup.graphql.client.types.GraphQLClientError | ||
|
|
||
| class GitHubEnterpriseConfigurationMissingException(properties: String) : RuntimeException( | ||
| "Github Enterprise properties '$properties' are not set" | ||
| ) | ||
| class GitHubAppInsufficientPermissionsException(message: String) : RuntimeException(message) | ||
| class FailedToCreateJWTException(message: String) : RuntimeException(message) | ||
| class UnableToConnectToGitHubEnterpriseException(message: String) : RuntimeException(message) | ||
| class JwtTokenNotFound : RuntimeException("JWT token not found") | ||
| class GraphQLApiException(errors: List<GraphQLClientError>) : | ||
| RuntimeException("Errors: ${errors.joinToString(separator = "\n") { it.message }}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/main/kotlin/net/leanix/githubagent/services/GitHubGraphQLService.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| package net.leanix.githubagent.services | ||
|
|
||
| import com.expediagroup.graphql.client.spring.GraphQLWebClient | ||
| import kotlinx.coroutines.runBlocking | ||
| import net.leanix.githubagent.config.GitHubEnterpriseProperties | ||
| import net.leanix.githubagent.dto.PagedRepositories | ||
| import net.leanix.githubagent.dto.RepositoryDto | ||
| import net.leanix.githubagent.dto.RepositoryOrganizationDto | ||
| import net.leanix.githubagent.exceptions.GraphQLApiException | ||
| import net.leanix.githubbroker.connector.adapter.graphql.data.GetRepositories | ||
| import net.leanix.githubbroker.connector.adapter.graphql.data.getrepositories.Blob | ||
| import org.slf4j.LoggerFactory | ||
| import org.springframework.stereotype.Component | ||
| import org.springframework.web.reactive.function.client.WebClient | ||
|
|
||
| @Component | ||
| class GitHubGraphQLService( | ||
| private val cachingService: CachingService, | ||
| private val gitHubEnterpriseProperties: GitHubEnterpriseProperties | ||
| ) { | ||
| companion object { | ||
| private val logger = LoggerFactory.getLogger(GitHubGraphQLService::class.java) | ||
| private const val PAGE_COUNT = 100 | ||
| private const val MANIFEST_FILE_NAME = "leanix.yaml" | ||
mohamedlajmileanix marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| fun getRepositories( | ||
| token: String, | ||
| cursor: String? = null | ||
| ): PagedRepositories { | ||
| val client = buildGitHubGraphQLClient(token) | ||
|
|
||
| val query = GetRepositories( | ||
| GetRepositories.Variables( | ||
| pageCount = PAGE_COUNT, | ||
| cursor = cursor, | ||
| expression = "HEAD:${gitHubEnterpriseProperties.manifestFilePath}$MANIFEST_FILE_NAME" | ||
| ) | ||
| ) | ||
|
|
||
| val result = runBlocking { | ||
| client.execute(query) | ||
| } | ||
|
|
||
| return if (result.errors != null && result.errors!!.isNotEmpty()) { | ||
| logger.error("Error getting repositories: ${result.errors}") | ||
| throw GraphQLApiException(result.errors!!) | ||
mohamedlajmileanix marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } else { | ||
| PagedRepositories( | ||
| hasNextPage = result.data!!.viewer.repositories.pageInfo.hasNextPage, | ||
| cursor = result.data!!.viewer.repositories.pageInfo.endCursor, | ||
| repositories = result.data!!.viewer.repositories.nodes!!.map { | ||
| RepositoryDto( | ||
| id = it!!.id, | ||
| name = it.name, | ||
| description = it.description, | ||
| url = it.url, | ||
| organization = RepositoryOrganizationDto( | ||
| id = it.owner.id, | ||
| name = it.owner.login | ||
| ), | ||
| languages = it.languages!!.nodes!!.map { language -> language!!.name }, | ||
| topics = it.repositoryTopics.nodes!!.map { topic -> topic!!.topic.name }, | ||
| manifest = (it.`object` as Blob?)?.text | ||
| ) | ||
| } | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| private fun buildGitHubGraphQLClient( | ||
| token: String | ||
| ) = | ||
| GraphQLWebClient( | ||
| url = "${cachingService.get("baseUrl")}/api/graphql", | ||
| builder = WebClient.builder().defaultHeaders { it.setBearerAuth(token) } | ||
| ) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| query GetRepositories($pageCount: Int!, $cursor: String, $expression: String!) { | ||
| viewer { | ||
| repositories(first: $pageCount, after: $cursor) { | ||
| pageInfo { | ||
| endCursor | ||
| hasNextPage | ||
| } | ||
| nodes { | ||
| id | ||
| name | ||
| description | ||
| url | ||
| owner{ | ||
| id | ||
| login | ||
| } | ||
| languages(first: 10) { | ||
| nodes { | ||
| name | ||
| } | ||
| } | ||
| repositoryTopics(first:10) { | ||
| nodes { | ||
| topic { | ||
| name | ||
| } | ||
| } | ||
| } | ||
| object(expression: $expression) { | ||
| __typename | ||
| ... on Blob { | ||
| text | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.