Skip to content

Commit eb3836d

Browse files
committed
Change to CLI app
1 parent 44e8c24 commit eb3836d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1105
-2046
lines changed

build.gradle.kts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,33 +33,26 @@ tasks.withType<KotlinCompile> {
3333
}
3434
}
3535

36+
tasks.withType<Test> {
37+
useJUnitPlatform()
38+
}
39+
3640
repositories {
3741
mavenCentral()
3842
}
3943

4044

4145
dependencies {
42-
implementation("org.springframework.boot:spring-boot-starter-security")
43-
implementation("org.springframework.boot:spring-boot-starter-oauth2-client")
44-
implementation("org.springframework.boot:spring-boot-starter-thymeleaf")
45-
implementation("org.springframework.boot:spring-boot-starter-actuator")
46-
implementation("org.springframework.boot:spring-boot-devtools")
47-
implementation("nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect")
48-
implementation("org.springframework.boot:spring-boot-starter-web")
4946
implementation("org.springframework.boot:spring-boot-starter-webflux")
5047
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
5148
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
5249
implementation("org.jetbrains.kotlin:kotlin-reflect")
5350

54-
implementation("org.webjars:webjars-locator-core")
55-
implementation("org.webjars:bootstrap:3.3.6")
56-
implementation("org.webjars:jquery:1.11.3")
51+
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
5752

5853
testImplementation("com.squareup.okhttp3:mockwebserver")
5954
testImplementation("org.springframework.boot:spring-boot-starter-test")
60-
testImplementation("org.springframework.security:spring-security-test")
6155
testImplementation("io.projectreactor:reactor-test")
6256
testImplementation("org.mockito.kotlin:mockito-kotlin:4.0.0")
6357
testImplementation("org.skyscreamer:jsonassert")
64-
implementation("org.seleniumhq.selenium:htmlunit-driver")
6558
}

src/main/kotlin/io/spring/github/BackportBotApplication.kt

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,41 +19,19 @@ package io.spring.github
1919
import io.spring.github.api.WebClientGitHubApi
2020
import org.springframework.boot.autoconfigure.SpringBootApplication
2121
import org.springframework.boot.runApplication
22-
import org.springframework.boot.web.servlet.FilterRegistrationBean
2322
import org.springframework.context.annotation.Bean
24-
import org.springframework.core.Ordered
25-
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository
26-
import org.springframework.security.oauth2.client.web.HttpSessionOAuth2AuthorizedClientRepository
27-
import org.springframework.security.oauth2.client.web.OAuth2AuthorizedClientRepository
28-
import org.springframework.security.oauth2.client.web.reactive.function.client.ServletOAuth2AuthorizedClientExchangeFilterFunction
29-
import org.springframework.web.filter.ForwardedHeaderFilter
3023
import org.springframework.web.reactive.function.client.WebClient
3124

3225
@SpringBootApplication
33-
class BackportBotApplication(val personalAccessToken: GitHubPersonalAccessToken) {
34-
35-
@Bean
36-
fun authorizedClientRepository() : OAuth2AuthorizedClientRepository {
37-
return HttpSessionOAuth2AuthorizedClientRepository()
38-
}
39-
26+
class BackportBotApplication {
4027
@Bean
41-
fun githubApi(clientRegistrationRepository: ClientRegistrationRepository,
42-
authorizedClientRepository: OAuth2AuthorizedClientRepository) : WebClientGitHubApi {
28+
internal fun webClientGitHubApi(gitHubAccessToken: GitHubAccessToken) : WebClientGitHubApi {
4329
val webClient = WebClient.builder()
44-
.defaultHeaders { h -> h.setBearerAuth(personalAccessToken.personalAccessToken) }
45-
.apply(ServletOAuth2AuthorizedClientExchangeFilterFunction(clientRegistrationRepository, authorizedClientRepository).oauth2Configuration())
46-
.build()
47-
30+
.defaultHeaders { headers -> headers.setBearerAuth(gitHubAccessToken.accessToken) }
31+
.build()
4832
return WebClientGitHubApi(webClient)
4933
}
5034

51-
@Bean
52-
fun forwardedHeaderFilter() : FilterRegistrationBean<ForwardedHeaderFilter> {
53-
val result = FilterRegistrationBean(ForwardedHeaderFilter())
54-
result.order = Ordered.HIGHEST_PRECEDENCE
55-
return result
56-
}
5735
}
5836

5937
fun main(args: Array<String>) {
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package io.spring.github
2+
3+
import com.fasterxml.jackson.databind.ObjectMapper
4+
import io.spring.github.event.GitHubHooksController
5+
import io.spring.github.event.IssueEvent
6+
import io.spring.github.event.PullRequestEvent
7+
import io.spring.github.event.PushEvent
8+
import org.springframework.boot.CommandLineRunner
9+
import org.springframework.stereotype.Component
10+
11+
@Component
12+
class BackportBotCommandLineRunner(val controller : GitHubHooksController, val objectMapper : ObjectMapper) : CommandLineRunner {
13+
var created : GitHubHooksController.Result = GitHubHooksController.Result.UNDEFINED
14+
override fun run(vararg args: String?) {
15+
if (args.size < 2) {
16+
usage(args);
17+
}
18+
val command = args[0]
19+
val json = args[1]
20+
when(command) {
21+
"--pull-request" -> {
22+
val pullRequest = this.objectMapper.readValue(json, PullRequestEvent::class.java)
23+
this.created = controller.githubPullRequestEvent(pullRequest)
24+
}
25+
"--issues" -> {
26+
val issues = this.objectMapper.readValue(json, IssueEvent::class.java)
27+
this.created = controller.githubEvent(issues)
28+
}
29+
"--push" -> {
30+
val push = this.objectMapper.readValue(json, PushEvent::class.java)
31+
this.created = controller.githubEventPush(push)
32+
}
33+
else -> {
34+
usage(args)
35+
}
36+
}
37+
}
38+
39+
private fun usage(args: Array<out String?>) {
40+
throw java.lang.IllegalArgumentException("Invalid usage. Got " + args)
41+
}
42+
}

src/main/kotlin/io/spring/github/ContentCachingFilter.kt

Lines changed: 0 additions & 76 deletions
This file was deleted.

src/main/kotlin/io/spring/github/GitHubWebHookSecret.kt renamed to src/main/kotlin/io/spring/github/GitHubAccessToken.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
1716
package io.spring.github
1817

1918
import org.springframework.boot.context.properties.ConfigurationProperties
@@ -24,6 +23,6 @@ import org.springframework.context.annotation.Configuration
2423
*/
2524
@Configuration
2625
@ConfigurationProperties(prefix = "github")
27-
class GitHubWebHookSecret {
28-
lateinit var webhookSecret: String
26+
internal class GitHubAccessToken {
27+
lateinit var accessToken : String
2928
}

src/main/kotlin/io/spring/github/GitHubPersonalAccessToken.kt

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/main/kotlin/io/spring/github/IndexController.kt

Lines changed: 0 additions & 62 deletions
This file was deleted.

src/main/kotlin/io/spring/github/LogoutController.kt

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/main/kotlin/io/spring/github/api/GitHubApi.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ interface GitHubApi {
6969
*/
7070
fun updateLabels(issueRef : IssueRef, labels: List<String>): Mono<Void>
7171

72-
fun saveHook(saveHook: SaveHook): Mono<Void>
73-
7472
/**
7573
* Finds all the labels for a Repository
7674
*/

0 commit comments

Comments
 (0)