Skip to content

Commit 240a3ec

Browse files
authored
Repository 웹 훅 제거 후 App 웹 훅으로 이전
Repository 웹 훅에서 App 웹 훅 변경으로 인한 Installation ID 환경 변수 제거 후 Payload DTO에 추가
2 parents 891cb8e + 91efb9d commit 240a3ec

10 files changed

Lines changed: 15 additions & 10 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ jobs:
1212
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
1313
API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}
1414
APP_ID: ${{ secrets.APP_ID }}
15-
APP_INSTALLATION_ID: ${{ secrets.APP_INSTALLATION_ID }}
1615
APP_PEM: ${{ secrets.APP_PEM }}
1716
steps:
1817
- name: Clean GitHub Actions cache only
@@ -86,7 +85,6 @@ jobs:
8685
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
8786
API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}
8887
APP_ID: ${{ secrets.APP_ID }}
89-
APP_INSTALLATION_ID: ${{ secrets.APP_INSTALLATION_ID }}
9088
APP_PEM: ${{ secrets.APP_PEM }}
9189

9290
steps:

src/main/kotlin/com/project/codereview/batch/FailedTaskManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class FailedTaskManager {
1515
val part: GithubDiffUtils.FileDiff
1616
) {
1717
fun toGithubReviewDto(review: String): GithubReviewDto {
18-
return GithubReviewDto(payload.pull_request, part, review)
18+
return GithubReviewDto(payload.pull_request, part, payload.installation.id, review)
1919
}
2020
}
2121

src/main/kotlin/com/project/codereview/batch/FailedTaskRetryScheduler.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class FailedTaskRetryScheduler(
2323
val batchSize = 10
2424
val batch = failedTaskManager.pollBatch(batchSize)
2525
if (batch.isEmpty()) {
26-
logger.info("[Retry Skip] queue is empty")
2726
return@launch
2827
}
2928

src/main/kotlin/com/project/codereview/client/github/GithubAppTokenProvider.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import java.util.*
1313
@Component
1414
class GithubAppTokenProvider(
1515
@param:Value("\${app.github.app.app-id}") private val appId: String,
16-
@param:Value("\${app.github.app.installation-id}") private val installationId: String,
1716
@param:Value("\${app.github.app.private-key}") private val appPem: String
1817
) {
1918
@Volatile private var cachedToken: String? = null
@@ -39,7 +38,7 @@ class GithubAppTokenProvider(
3938
.compact()
4039
}
4140

42-
fun getInstallationToken(): String {
41+
fun getInstallationToken(installationId: String): String {
4342
val now = Instant.now()
4443
if (cachedToken != null && expiresAt?.isAfter(now.plusSeconds(30)) == true) {
4544
return cachedToken!! // 만료 30초 전까지 재사용

src/main/kotlin/com/project/codereview/client/github/GithubReviewClient.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class GithubReviewClient(
1919
val client = WebClient.builder()
2020
.baseUrl("https://api.github.com")
2121
.defaultHeader("Accept", "application/vnd.github+json")
22-
.defaultHeader("Authorization", "Bearer ${tokenProvider.getInstallationToken()}")
2322
.build()
2423

2524
suspend fun addReviewComment(
@@ -31,6 +30,7 @@ class GithubReviewClient(
3130

3231
client.post()
3332
.uri(uri)
33+
.header("Authorization", "Bearer ${tokenProvider.getInstallationToken(dto.installationId)}")
3434
.bodyValue(dto.toReviewCommentRequest())
3535
.retrieve()
3636
.bodyToMono(String::class.java)

src/main/kotlin/com/project/codereview/core/controller/CodeReviewController.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ class CodeReviewController(
4343
// PR 생성 시에만 리뷰 진행
4444
when (event) {
4545
"pull_request" -> when (GithubActionType(payload.action)) {
46-
GithubActionType.OPENED -> codeReviewService.review(payload)
46+
GithubActionType.OPENED,
47+
GithubActionType.REOPENED -> {
48+
codeReviewService.review(payload)
49+
}
4750
else -> logger.info("Ignored pull_request event: ${payload.action}")
4851
}
4952
else -> logger.debug("Unhandled GitHub event: $event")

src/main/kotlin/com/project/codereview/core/dto/GithubPayloadDtos.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,15 @@ import com.fasterxml.jackson.module.kotlin.readValue
88
data class GithubPayload(
99
val action: String,
1010
val number: String,
11+
val installation: InstallationPayload,
1112
val pull_request: PullRequestPayload
1213
)
1314

15+
@JsonIgnoreProperties(ignoreUnknown = true)
16+
data class InstallationPayload(
17+
val id: String
18+
)
19+
1420
@JsonIgnoreProperties(ignoreUnknown = true)
1521
data class PullRequestPayload(
1622
val url: String,

src/main/kotlin/com/project/codereview/core/dto/GithubReviewDto.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import com.project.codereview.client.github.GithubReviewClient
77
data class GithubReviewDto(
88
val payload: PullRequestPayload,
99
val diff: GithubDiffUtils.FileDiff,
10+
val installationId: String,
1011
val review: String
1112
) {
1213
fun toReviewCommentRequest() = GithubReviewClient.ReviewCommentRequest(

src/main/kotlin/com/project/codereview/core/service/ReviewWorker.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ReviewWorker(
2020
runCatching {
2121
val review = googleGeminiClient.chat(filePath, prompt)
2222
if (review != null) {
23-
githubReviewClient.addReviewComment(GithubReviewDto(task.payload, task.part, review))
23+
githubReviewClient.addReviewComment(GithubReviewDto(task.payload, task.part, payload.installation.id, review))
2424
}
2525
}.onFailure {
2626
failedTaskManager.add(FailedTaskManager.OriginalTask(payload, task.part), prompt)

src/main/resources/application.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ app:
66
github:
77
app:
88
app-id: ${APP_ID}
9-
installation-id: ${APP_INSTALLATION_ID}
109
private-key: ${APP_PEM}
1110
webhook:
1211
secret-key: ${WEBHOOK_SECRET}

0 commit comments

Comments
 (0)