Skip to content

Commit 2d2f57e

Browse files
authored
Merge pull request #3079 from github/mbg/proxy/accept-git-source
Accept `git_source` registry configurations for Go
2 parents b364f99 + 8fe8b24 commit 2d2f57e

File tree

3 files changed

+42
-30
lines changed

3 files changed

+42
-30
lines changed

lib/start-proxy-action.js

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/start-proxy.test.ts

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ setupTests(test);
1111
const toEncodedJSON = (data: any) =>
1212
Buffer.from(JSON.stringify(data)).toString("base64");
1313

14+
const mixedCredentials = [
15+
{ type: "npm_registry", host: "npm.pkg.github.com", token: "abc" },
16+
{ type: "maven_repository", host: "maven.pkg.github.com", token: "def" },
17+
{ type: "nuget_feed", host: "nuget.pkg.github.com", token: "ghi" },
18+
{ type: "goproxy_server", host: "goproxy.example.com", token: "jkl" },
19+
{ type: "git_source", host: "github.com/github", token: "mno" },
20+
];
21+
1422
test("getCredentials prefers registriesCredentials over registrySecrets", async (t) => {
1523
const registryCredentials = Buffer.from(
1624
JSON.stringify([
@@ -94,13 +102,6 @@ test("getCredentials throws error when credential missing host and url", async (
94102
});
95103

96104
test("getCredentials filters by language when specified", async (t) => {
97-
const mixedCredentials = [
98-
{ type: "npm_registry", host: "npm.pkg.github.com", token: "abc" },
99-
{ type: "maven_repository", host: "maven.pkg.github.com", token: "def" },
100-
{ type: "nuget_feed", host: "nuget.pkg.github.com", token: "ghi" },
101-
{ type: "goproxy_server", host: "goproxy.example.com", token: "jkl" },
102-
];
103-
104105
const credentials = startProxyExports.getCredentials(
105106
getRunnerLogger(true),
106107
undefined,
@@ -111,13 +112,21 @@ test("getCredentials filters by language when specified", async (t) => {
111112
t.is(credentials[0].type, "maven_repository");
112113
});
113114

115+
test("getCredentials returns all for a language when specified", async (t) => {
116+
const credentials = startProxyExports.getCredentials(
117+
getRunnerLogger(true),
118+
undefined,
119+
toEncodedJSON(mixedCredentials),
120+
"go",
121+
);
122+
t.is(credentials.length, 2);
123+
124+
const credentialsTypes = credentials.map((c) => c.type);
125+
t.assert(credentialsTypes.includes("goproxy_server"));
126+
t.assert(credentialsTypes.includes("git_source"));
127+
});
128+
114129
test("getCredentials returns all credentials when no language specified", async (t) => {
115-
const mixedCredentials = [
116-
{ type: "npm_registry", host: "npm.pkg.github.com", token: "abc" },
117-
{ type: "maven_repository", host: "maven.pkg.github.com", token: "def" },
118-
{ type: "nuget_feed", host: "nuget.pkg.github.com", token: "ghi" },
119-
{ type: "goproxy_server", host: "goproxy.example.com", token: "jkl" },
120-
];
121130
const credentialsInput = toEncodedJSON(mixedCredentials);
122131

123132
const credentials = startProxyExports.getCredentials(

src/start-proxy.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ export function parseLanguage(language: string): KnownLanguage | undefined {
5555
return undefined;
5656
}
5757

58-
const LANGUAGE_TO_REGISTRY_TYPE: Partial<Record<KnownLanguage, string>> = {
59-
java: "maven_repository",
60-
csharp: "nuget_feed",
61-
javascript: "npm_registry",
62-
python: "python_index",
63-
ruby: "rubygems_server",
64-
rust: "cargo_registry",
65-
go: "goproxy_server",
58+
const LANGUAGE_TO_REGISTRY_TYPE: Partial<Record<KnownLanguage, string[]>> = {
59+
java: ["maven_repository"],
60+
csharp: ["nuget_feed"],
61+
javascript: ["npm_registry"],
62+
python: ["python_index"],
63+
ruby: ["rubygems_server"],
64+
rust: ["cargo_registry"],
65+
go: ["goproxy_server", "git_source"],
6666
} as const;
6767

6868
/**
@@ -140,7 +140,10 @@ export function getCredentials(
140140

141141
// Filter credentials based on language if specified. `type` is the registry type.
142142
// E.g., "maven_feed" for Java/Kotlin, "nuget_repository" for C#.
143-
if (registryTypeForLanguage && e.type !== registryTypeForLanguage) {
143+
if (
144+
registryTypeForLanguage &&
145+
!registryTypeForLanguage.some((t) => t === e.type)
146+
) {
144147
continue;
145148
}
146149

0 commit comments

Comments
 (0)