Skip to content

Commit c041f8e

Browse files
committed
fix(observer): improve error handling for GitHub API permissions
Add user-friendly fallback messages when admin rights are missing for downloading GitHub Action logs. Include permission requirement notice in settings UI and provide graceful degradation with direct workflow URLs when detailed logs are unavailable.
1 parent 4bd3afe commit c041f8e

File tree

2 files changed

+44
-9
lines changed

2 files changed

+44
-9
lines changed

core/src/233/main/kotlin/cc/unitmesh/devti/observer/PipelineStatusProcessor.kt

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -192,28 +192,40 @@ class PipelineStatusProcessor : AgentObserver, GitPushListener {
192192
private fun handleWorkflowFailure(workflowRun: GHWorkflowRun, commitSha: String) {
193193
try {
194194
log.info("Analyzing workflow failure for commit: $commitSha")
195-
195+
196196
// 获取失败的构建详情
197197
val failureDetails = getWorkflowFailureDetails(workflowRun)
198-
198+
199199
// 构建详细的错误通知
200200
val detailedMessage = buildDetailedFailureMessage(workflowRun, commitSha, failureDetails)
201-
201+
202202
AutoDevNotifications.notify(
203203
project!!,
204204
detailedMessage,
205205
NotificationType.ERROR
206206
)
207-
207+
208208
// 记录详细日志
209209
log.info("Workflow failure details for commit $commitSha: $failureDetails")
210-
210+
211211
} catch (e: Exception) {
212212
log.error("Error analyzing workflow failure for commit: $commitSha", e)
213-
// 回退到简单通知
213+
214+
// 提供更好的错误回退消息
215+
val fallbackMessage = if (e.message?.contains("admin rights", ignoreCase = true) == true ||
216+
e.message?.contains("403", ignoreCase = true) == true) {
217+
"❌ GitHub Action failed for commit: ${commitSha.take(7)} - ${workflowRun.conclusion}\n" +
218+
"⚠️ Detailed logs unavailable - admin rights required\n" +
219+
"View details at: ${workflowRun.htmlUrl}"
220+
} else {
221+
"❌ GitHub Action failed for commit: ${commitSha.take(7)} - ${workflowRun.conclusion}\n" +
222+
"URL: ${workflowRun.htmlUrl}\n" +
223+
"Error getting details: ${e.message}"
224+
}
225+
214226
AutoDevNotifications.notify(
215227
project!!,
216-
"❌ GitHub Action failed for commit: ${commitSha.take(7)} - ${workflowRun.conclusion}\nURL: ${workflowRun.htmlUrl}",
228+
fallbackMessage,
217229
NotificationType.ERROR
218230
)
219231
}
@@ -278,7 +290,18 @@ class PipelineStatusProcessor : AgentObserver, GitPushListener {
278290
}
279291
}
280292
} catch (e: Exception) {
281-
log.error("Error downloading job logs for job: ${job.name}", e)
293+
log.warn("Cannot download job logs for job: ${job.name} - ${e.message}")
294+
295+
// Check if it's a permission error
296+
if (e.message?.contains("admin rights", ignoreCase = true) == true ||
297+
e.message?.contains("403", ignoreCase = true) == true) {
298+
log.info("Admin rights required to download job logs. Falling back to alternative approach.")
299+
return "⚠️ Job logs unavailable - admin rights required to download logs from GitHub Actions.\n" +
300+
"Job URL: ${job.htmlUrl}\n" +
301+
"You can view the logs directly at: ${job.htmlUrl}"
302+
}
303+
304+
// Try alternative API approach for other errors
282305
getLogsViaDirectAPI(workflowRun, job.id)
283306
}
284307
}
@@ -305,7 +328,17 @@ class PipelineStatusProcessor : AgentObserver, GitPushListener {
305328
}
306329
}
307330
} catch (e: Exception) {
308-
log.error("Error downloading workflow logs", e)
331+
log.warn("Cannot download workflow logs - ${e.message}")
332+
333+
// Check if it's a permission error
334+
if (e.message?.contains("admin rights", ignoreCase = true) == true ||
335+
e.message?.contains("403", ignoreCase = true) == true) {
336+
log.info("Admin rights required to download workflow logs.")
337+
return "⚠️ Workflow logs unavailable - admin rights required to download logs from GitHub Actions.\n" +
338+
"Workflow URL: ${workflowRun.htmlUrl}\n" +
339+
"You can view the logs directly at: ${workflowRun.htmlUrl}"
340+
}
341+
309342
null
310343
}
311344
}

core/src/main/kotlin/cc/unitmesh/devti/settings/devops/AutoDevDevOpsConfigurableProvider.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class DevOpsConfigurable(project: Project) : BoundConfigurable(AutoDevBundle.mes
4141
link("Create Token") {
4242
BrowserUtil.browse("https://github.com/settings/tokens/new?scopes=repo,workflow&description=AutoDev%20IDE%20Plugin")
4343
}
44+
45+
comment("Note: Admin rights to repository are required to download detailed job logs. Basic monitoring works with read access.")
4446
}
4547
row("GitLab URL:") {
4648
gitlabUrlField = textField().component

0 commit comments

Comments
 (0)