Skip to content

Commit e706d30

Browse files
authored
feat(fetch): include mason.nvim version in User-Agent (#1362)
1 parent f7f81ab commit e706d30

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

lua/mason-core/fetch.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ local log = require "mason-core.log"
66
local platform = require "mason-core.platform"
77
local powershell = require "mason-core.managers.powershell"
88
local spawn = require "mason-core.spawn"
9+
local version = require "mason.version"
910

10-
local USER_AGENT = "mason.nvim (+https://github.com/williamboman/mason.nvim)"
11+
local USER_AGENT = ("mason.nvim %s (+https://github.com/williamboman/mason.nvim)"):format(version.VERSION)
1112

1213
---@alias FetchMethod
1314
---| '"GET"'

tests/mason-core/fetch_spec.lua

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ local fetch = require "mason-core.fetch"
33
local match = require "luassert.match"
44
local spawn = require "mason-core.spawn"
55
local stub = require "luassert.stub"
6+
local version = require "mason.version"
67

78
describe("fetch", function()
89
it(
@@ -21,7 +22,9 @@ describe("fetch", function()
2122
assert.spy(spawn.curl).was_called(1)
2223
assert.spy(spawn.wget).was_called_with {
2324
{
24-
"--header=User-Agent: mason.nvim (+https://github.com/williamboman/mason.nvim)",
25+
("--header=User-Agent: mason.nvim %s (+https://github.com/williamboman/mason.nvim)"):format(
26+
version.VERSION
27+
),
2528
"--header=X-Custom-Header: here",
2629
},
2730
"-nv",
@@ -38,7 +41,9 @@ describe("fetch", function()
3841
match.same {
3942
{
4043
"-H",
41-
"User-Agent: mason.nvim (+https://github.com/williamboman/mason.nvim)",
44+
("User-Agent: mason.nvim %s (+https://github.com/williamboman/mason.nvim)"):format(
45+
version.VERSION
46+
),
4247
},
4348
{
4449
"-H",
@@ -79,7 +84,9 @@ describe("fetch", function()
7984

8085
assert.spy(spawn.wget).was_called_with {
8186
{
82-
"--header=User-Agent: mason.nvim (+https://github.com/williamboman/mason.nvim)",
87+
("--header=User-Agent: mason.nvim %s (+https://github.com/williamboman/mason.nvim)"):format(
88+
version.VERSION
89+
),
8390
},
8491
"-nv",
8592
"-o",
@@ -95,7 +102,9 @@ describe("fetch", function()
95102
match.same {
96103
{
97104
"-H",
98-
"User-Agent: mason.nvim (+https://github.com/williamboman/mason.nvim)",
105+
("User-Agent: mason.nvim %s (+https://github.com/williamboman/mason.nvim)"):format(
106+
version.VERSION
107+
),
99108
},
100109
},
101110
"-fsSL",

0 commit comments

Comments
 (0)