This is an automated email from the ASF dual-hosted git repository.
klesh pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/main by this push:
new adaa00857 fix: throwing on parsing for a 204 response (#8825)
adaa00857 is described below
commit adaa0085711687f52b991f0347479496d0a0de3d
Author: Reece Ward <[email protected]>
AuthorDate: Thu Apr 9 17:47:06 2026 +0100
fix: throwing on parsing for a 204 response (#8825)
---
.../plugins/gh-copilot/tasks/enterprise_metrics_collector.go | 2 +-
backend/plugins/gh-copilot/tasks/org_metrics_collector.go | 12 +++++++++++-
backend/plugins/gh-copilot/tasks/report_download_helper.go | 10 ++++++----
backend/plugins/gh-copilot/tasks/user_metrics_collector.go | 2 +-
4 files changed, 19 insertions(+), 7 deletions(-)
diff --git a/backend/plugins/gh-copilot/tasks/enterprise_metrics_collector.go
b/backend/plugins/gh-copilot/tasks/enterprise_metrics_collector.go
index 08ad03861..a47ef573e 100644
--- a/backend/plugins/gh-copilot/tasks/enterprise_metrics_collector.go
+++ b/backend/plugins/gh-copilot/tasks/enterprise_metrics_collector.go
@@ -93,7 +93,7 @@ func CollectEnterpriseMetrics(taskCtx plugin.SubTaskContext)
errors.Error {
},
Incremental: true,
Concurrency: 1,
- AfterResponse: ignore404,
+ AfterResponse: ignoreNoContent,
ResponseParser: func(res *http.Response) ([]json.RawMessage,
errors.Error) {
body, readErr := io.ReadAll(res.Body)
res.Body.Close()
diff --git a/backend/plugins/gh-copilot/tasks/org_metrics_collector.go
b/backend/plugins/gh-copilot/tasks/org_metrics_collector.go
index 82f3fc36c..5afeee1f8 100644
--- a/backend/plugins/gh-copilot/tasks/org_metrics_collector.go
+++ b/backend/plugins/gh-copilot/tasks/org_metrics_collector.go
@@ -87,7 +87,7 @@ func CollectOrgMetrics(taskCtx plugin.SubTaskContext)
errors.Error {
},
Incremental: true,
Concurrency: 1,
- AfterResponse: ignore404,
+ AfterResponse: ignoreNoContent,
ResponseParser: func(res *http.Response) ([]json.RawMessage,
errors.Error) {
body, readErr := io.ReadAll(res.Body)
res.Body.Close()
@@ -100,9 +100,19 @@ func CollectOrgMetrics(taskCtx plugin.SubTaskContext)
errors.Error {
var meta reportMetadataResponse
if jsonErr := json.Unmarshal(body, &meta); jsonErr !=
nil {
+ snippet := string(body)
+ if len(snippet) > 200 {
+ snippet = snippet[:200]
+ }
+ logger.Error(jsonErr, "failed to parse report
metadata, body=%s", snippet)
return nil, errors.Default.Wrap(jsonErr,
"failed to parse report metadata")
}
+ if len(meta.DownloadLinks) == 0 {
+ logger.Info("No download links for report
day=%s, skipping", meta.ReportDay)
+ return nil, nil
+ }
+
var results []json.RawMessage
for _, link := range meta.DownloadLinks {
reportBody, dlErr := downloadReport(link,
logger)
diff --git a/backend/plugins/gh-copilot/tasks/report_download_helper.go
b/backend/plugins/gh-copilot/tasks/report_download_helper.go
index 39da15f20..538fd90e0 100644
--- a/backend/plugins/gh-copilot/tasks/report_download_helper.go
+++ b/backend/plugins/gh-copilot/tasks/report_download_helper.go
@@ -50,11 +50,13 @@ func utcDate(t time.Time) time.Time {
return time.Date(y, m, d, 0, 0, 0, 0, time.UTC)
}
-// ignore404 is an AfterResponse callback that skips 404 responses.
+// ignoreNoContent is an AfterResponse callback that skips 404 and 204
responses.
// The report API returns 404 when no report is available for a given day,
-// which is normal and should not be treated as an error.
-func ignore404(res *http.Response) errors.Error {
- if res.StatusCode == http.StatusNotFound {
+// and 204 (No Content) when data is not yet available or the org had fewer
+// than 5 active Copilot users on that day. Both are normal and should not
+// be treated as errors.
+func ignoreNoContent(res *http.Response) errors.Error {
+ if res.StatusCode == http.StatusNotFound || res.StatusCode ==
http.StatusNoContent {
return helper.ErrIgnoreAndContinue
}
return nil
diff --git a/backend/plugins/gh-copilot/tasks/user_metrics_collector.go
b/backend/plugins/gh-copilot/tasks/user_metrics_collector.go
index ef3e21bb8..06905015a 100644
--- a/backend/plugins/gh-copilot/tasks/user_metrics_collector.go
+++ b/backend/plugins/gh-copilot/tasks/user_metrics_collector.go
@@ -92,7 +92,7 @@ func CollectUserMetrics(taskCtx plugin.SubTaskContext)
errors.Error {
},
Incremental: true,
Concurrency: 1,
- AfterResponse: ignore404,
+ AfterResponse: ignoreNoContent,
ResponseParser: func(res *http.Response) ([]json.RawMessage,
errors.Error) {
body, readErr := io.ReadAll(res.Body)
res.Body.Close()