Skip to content

Commit 5163a95

Browse files
Fall back to extension detection for unrecognized client languages
1 parent 8751485 commit 5163a95

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

app/services/heartbeat_ingest.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def normalize_direct_heartbeat(heartbeat, placeholder_state:)
104104

105105
resolve_placeholders!(attrs, placeholder_state)
106106

107-
if attrs[:language].blank? || attrs[:language] == "Unknown"
107+
if attrs[:language].blank? || attrs[:language] == "Unknown" || LanguageUtils.find_name(attrs[:language]).nil?
108108
inferred = LanguageUtils.detect_from_extension(attrs[:entity])
109109
attrs[:language] = inferred if inferred
110110
end

test/services/heartbeat_ingest_test.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,40 @@ class HeartbeatIngestTest < ActiveSupport::TestCase
790790
assert_equal 1, calls
791791
end
792792

793+
test "direct heartbeat ingest replaces unrecognized client languages with extension detection" do
794+
user = User.create!(timezone: "UTC")
795+
796+
HeartbeatIngest.call(
797+
user: user,
798+
mode: :direct,
799+
heartbeats: [ {
800+
entity: "src/main.asm",
801+
language: "RGBDS Assembly",
802+
time: Time.current.to_f,
803+
type: "file"
804+
} ]
805+
)
806+
807+
assert_equal "Assembly", user.heartbeats.sole.language
808+
end
809+
810+
test "direct heartbeat ingest preserves recognized client languages" do
811+
user = User.create!(timezone: "UTC")
812+
813+
HeartbeatIngest.call(
814+
user: user,
815+
mode: :direct,
816+
heartbeats: [ {
817+
entity: "src/main.asm",
818+
language: "Assembly",
819+
time: Time.current.to_f,
820+
type: "file"
821+
} ]
822+
)
823+
824+
assert_equal "Assembly", user.heartbeats.sole.language
825+
end
826+
793827
test "import heartbeat ingest deduplicates imported heartbeats and schedules dashboard rollup refresh" do
794828
user = User.create!(timezone: "UTC")
795829

0 commit comments

Comments
 (0)