Skip to content

Commit

Permalink
Use Language type
Browse files Browse the repository at this point in the history
  • Loading branch information
marcogario committed Jan 14, 2025
1 parent de0f9cf commit f33e08c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export const LANGUAGE_ALIASES: { [lang: string]: Language } = {
"c#": Language.csharp,
kotlin: Language.java,
typescript: Language.javascript,
"javascript-typescript": Language.javascript,
"java-kotlin": Language.java,
};

/**
Expand Down
21 changes: 16 additions & 5 deletions src/start-proxy-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { pki } from "node-forge";
import * as actionsUtil from "./actions-util";
import { getActionsLogger, Logger } from "./logging";
import * as util from "./util";
import { Language, parseLanguage } from "./languages";

Check failure

Code scanning / ESLint

Enforce a convention in module import order. Error

./languages import should occur before import of ./logging

const UPDATEJOB_PROXY = "update-job-proxy";
const UPDATEJOB_PROXY_VERSION = "v2.0.20241023203727";
Expand All @@ -17,10 +18,18 @@ const PROXY_USER = "proxy_user";
const KEY_SIZE = 2048;
const KEY_EXPIRY_YEARS = 2;

const LANGUAGE_TO_REGISTRY_TYPE = {
"java-kotlin": "maven_repository",
const LANGUAGE_TO_REGISTRY_TYPE: Record<Language, string> = {
java: "maven_repository",
csharp: "nuget_feed",
javascript: "npm_registry",
python: "python_index",
ruby: "rubygems_server",
rust: "cargo_registry",
// We do not have an established proxy type for these languages, thus leaving empty.
actions: "",
cpp: "",
go: "",
swift: "",
} as const;

type CertificateAuthority = {
Expand Down Expand Up @@ -198,7 +207,9 @@ function getCredentials(logger: Logger): Credential[] {
"registries_credentials",
);
const registrySecrets = actionsUtil.getOptionalInput("registry_secrets");
const language = actionsUtil.getOptionalInput("language");
const languageString = actionsUtil.getOptionalInput("language");
const language = languageString ? parseLanguage(languageString) : undefined;
const registryTypeForLanguage = language ? LANGUAGE_TO_REGISTRY_TYPE[language] : undefined;

Check failure

Code scanning / ESLint

Ensure code is properly formatted, use insertion, deletion, or replacement to obtain desired formatting. Error

Replace ·?·LANGUAGE\_TO\_REGISTRY\_TYPE[language] with ⏎····?·LANGUAGE\_TO\_REGISTRY\_TYPE[language]⏎···

let credentialsStr: string;
if (registriesCredentials !== undefined) {
Expand All @@ -222,8 +233,8 @@ function getCredentials(logger: Logger): Credential[] {

// Filter credentials based on language if specified. `type` is the registry type.
// E.g., "maven_feed" for Java/Kotlin, "nuget_repository" for C#.
if (language && LANGUAGE_TO_REGISTRY_TYPE[language] !== e.type) {
continue;
if (e.type != registryTypeForLanguage) {

Check failure

Code scanning / ESLint

Require the use of `===` and `!==` Error

Expected '!==' and instead saw '!='.
continue;

Check failure

Code scanning / ESLint

Ensure code is properly formatted, use insertion, deletion, or replacement to obtain desired formatting. Error

Delete ··
}

out.push({
Expand Down

0 comments on commit f33e08c

Please sign in to comment.