Skip to content

Commit

Permalink
chore(scripts): factor git repo id (#499)
Browse files Browse the repository at this point in the history
  • Loading branch information
millotp authored May 13, 2022
1 parent 57f0edd commit f903ebd
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 117 deletions.
3 changes: 3 additions & 0 deletions config/clients.config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"java": {
"folder": "clients/algoliasearch-client-java-2",
"gitRepoId": "algoliasearch-client-java-2",
"packageVersion": "0.0.1",
"modelFolder": "algoliasearch-core/src/main/java/com/algolia/model",
"apiFolder": "algoliasearch-core/src/main/java/com/algolia/api",
Expand All @@ -12,6 +13,7 @@
},
"javascript": {
"folder": "clients/algoliasearch-client-javascript",
"gitRepoId": "algoliasearch-client-javascript",
"modelFolder": "model",
"apiFolder": "src",
"customGenerator": "algolia-javascript",
Expand All @@ -22,6 +24,7 @@
},
"php": {
"folder": "clients/algoliasearch-client-php",
"gitRepoId": "algoliasearch-client-php",
"packageVersion": "0.0.1",
"modelFolder": "lib/Model",
"customGenerator": "algolia-php",
Expand Down
80 changes: 0 additions & 80 deletions config/openapitools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
"version": "5.4.0",
"generators": {
"javascript-search": {
"apiPackage": "src",
"output": "#{cwd}/clients/algoliasearch-client-javascript/packages/client-search",
"gitRepoId": "algoliasearch-client-javascript",
"reservedWordsMappings": "queryParameters=queryParameters,requestOptions=requestOptions",
"additionalProperties": {
"npmName": "@experimental-api-clients-automation/client-search",
Expand All @@ -16,9 +14,7 @@
}
},
"javascript-algoliasearch-lite": {
"apiPackage": "src",
"output": "#{cwd}/clients/algoliasearch-client-javascript/packages/algoliasearch-lite",
"gitRepoId": "algoliasearch-client-javascript",
"reservedWordsMappings": "queryParameters=queryParameters,requestOptions=requestOptions",
"additionalProperties": {
"npmName": "@experimental-api-clients-automation/algoliasearch-lite",
Expand All @@ -29,9 +25,7 @@
}
},
"javascript-recommend": {
"apiPackage": "src",
"output": "#{cwd}/clients/algoliasearch-client-javascript/packages/recommend",
"gitRepoId": "algoliasearch-client-javascript",
"reservedWordsMappings": "queryParameters=queryParameters",
"additionalProperties": {
"npmName": "@experimental-api-clients-automation/recommend",
Expand All @@ -42,9 +36,7 @@
}
},
"javascript-personalization": {
"apiPackage": "src",
"output": "#{cwd}/clients/algoliasearch-client-javascript/packages/client-personalization",
"gitRepoId": "algoliasearch-client-javascript",
"additionalProperties": {
"npmName": "@experimental-api-clients-automation/client-personalization",
"buildFile": "client-personalization",
Expand All @@ -55,9 +47,7 @@
}
},
"javascript-analytics": {
"apiPackage": "src",
"output": "#{cwd}/clients/algoliasearch-client-javascript/packages/client-analytics",
"gitRepoId": "algoliasearch-client-javascript",
"additionalProperties": {
"npmName": "@experimental-api-clients-automation/client-analytics",
"buildFile": "client-analytics",
Expand All @@ -68,9 +58,7 @@
}
},
"javascript-insights": {
"apiPackage": "src",
"output": "#{cwd}/clients/algoliasearch-client-javascript/packages/client-insights",
"gitRepoId": "algoliasearch-client-javascript",
"additionalProperties": {
"npmName": "@experimental-api-clients-automation/client-insights",
"buildFile": "client-insights",
Expand All @@ -81,9 +69,7 @@
}
},
"javascript-abtesting": {
"apiPackage": "src",
"output": "#{cwd}/clients/algoliasearch-client-javascript/packages/client-abtesting",
"gitRepoId": "algoliasearch-client-javascript",
"additionalProperties": {
"npmName": "@experimental-api-clients-automation/client-abtesting",
"buildFile": "client-abtesting",
Expand All @@ -94,9 +80,7 @@
}
},
"javascript-query-suggestions": {
"apiPackage": "src",
"output": "#{cwd}/clients/algoliasearch-client-javascript/packages/client-query-suggestions",
"gitRepoId": "algoliasearch-client-javascript",
"additionalProperties": {
"npmName": "@experimental-api-clients-automation/client-query-suggestions",
"buildFile": "client-query-suggestions",
Expand All @@ -107,9 +91,7 @@
}
},
"javascript-sources": {
"apiPackage": "src",
"output": "#{cwd}/clients/algoliasearch-client-javascript/packages/client-sources",
"gitRepoId": "algoliasearch-client-javascript",
"additionalProperties": {
"npmName": "@experimental-api-clients-automation/client-sources",
"buildFile": "client-sources",
Expand All @@ -121,9 +103,7 @@
},
"javascript-predict": {
"templateDir": "#{cwd}/templates/javascript/",
"apiPackage": "src",
"output": "#{cwd}/clients/algoliasearch-client-javascript/packages/client-predict",
"gitRepoId": "algoliasearch-client-javascript",
"additionalProperties": {
"npmName": "@experimental-api-clients-automation/client-predict",
"buildFile": "client-predict",
Expand All @@ -135,127 +115,81 @@
},
"java-search": {
"output": "#{cwd}/clients/algoliasearch-client-java-2",
"groupId": "com.algolia",
"apiPackage": "com.algolia.api",
"invokerPackage": "com.algolia",
"modelPackage": "com.algolia.model.search",
"library": "okhttp-gson",
"gitRepoId": "algoliasearch-client-java-2",
"additionalProperties": {
"packageName": "algoliasearch-client-java"
}
},
"java-recommend": {
"output": "#{cwd}/clients/algoliasearch-client-java-2",
"groupId": "com.algolia",
"apiPackage": "com.algolia.api",
"invokerPackage": "com.algolia",
"modelPackage": "com.algolia.model.recommend",
"library": "okhttp-gson",
"gitRepoId": "algoliasearch-client-java-2",
"additionalProperties": {
"packageName": "algoliasearch-client-java"
}
},
"java-personalization": {
"output": "#{cwd}/clients/algoliasearch-client-java-2",
"groupId": "com.algolia",
"apiPackage": "com.algolia.api",
"invokerPackage": "com.algolia",
"modelPackage": "com.algolia.model.personalization",
"library": "okhttp-gson",
"gitRepoId": "algoliasearch-client-java-2",
"additionalProperties": {
"packageName": "algoliasearch-client-java",
"hasRegionalHost": true
}
},
"java-analytics": {
"output": "#{cwd}/clients/algoliasearch-client-java-2",
"groupId": "com.algolia",
"apiPackage": "com.algolia.api",
"invokerPackage": "com.algolia",
"modelPackage": "com.algolia.model.analytics",
"library": "okhttp-gson",
"gitRepoId": "algoliasearch-client-java-2",
"additionalProperties": {
"packageName": "algoliasearch-client-java",
"hasRegionalHost": true
}
},
"java-insights": {
"output": "#{cwd}/clients/algoliasearch-client-java-2",
"groupId": "com.algolia",
"apiPackage": "com.algolia.api",
"invokerPackage": "com.algolia",
"modelPackage": "com.algolia.model.insights",
"library": "okhttp-gson",
"gitRepoId": "algoliasearch-client-java-2",
"additionalProperties": {
"packageName": "algoliasearch-client-java",
"hasRegionalHost": true
}
},
"java-abtesting": {
"output": "#{cwd}/clients/algoliasearch-client-java-2",
"groupId": "com.algolia",
"apiPackage": "com.algolia.api",
"invokerPackage": "com.algolia",
"modelPackage": "com.algolia.model.abtesting",
"library": "okhttp-gson",
"gitRepoId": "algoliasearch-client-java-2",
"additionalProperties": {
"packageName": "algoliasearch-client-java",
"hasRegionalHost": true
}
},
"java-query-suggestions": {
"output": "#{cwd}/clients/algoliasearch-client-java-2",
"groupId": "com.algolia",
"apiPackage": "com.algolia.api",
"invokerPackage": "com.algolia",
"modelPackage": "com.algolia.model.querySuggestions",
"library": "okhttp-gson",
"gitRepoId": "algoliasearch-client-java-2",
"additionalProperties": {
"packageName": "algoliasearch-client-java",
"hasRegionalHost": true
}
},
"java-predict": {
"output": "#{cwd}/clients/algoliasearch-client-java-2",
"groupId": "com.algolia",
"apiPackage": "com.algolia.api",
"invokerPackage": "com.algolia",
"modelPackage": "com.algolia.model.predict",
"library": "okhttp-gson",
"gitRepoId": "algoliasearch-client-java-2",
"additionalProperties": {
"packageName": "algoliasearch-client-java"
}
},
"php-search": {
"output": "#{cwd}/clients/algoliasearch-client-php",
"gitRepoId": "algoliasearch-client-php",
"invokerPackage": "Algolia\\AlgoliaSearch",
"modelPackage": "Model\\Search",
"additionalProperties": {
"packageName": "algoliasearch-client-php"
}
},
"php-recommend": {
"output": "#{cwd}/clients/algoliasearch-client-php",
"gitRepoId": "algoliasearch-client-php",
"invokerPackage": "Algolia\\AlgoliaSearch",
"modelPackage": "Model\\Recommend",
"additionalProperties": {
"packageName": "algoliasearch-client-php"
}
},
"php-personalization": {
"output": "#{cwd}/clients/algoliasearch-client-php",
"gitRepoId": "algoliasearch-client-php",
"invokerPackage": "Algolia\\AlgoliaSearch",
"modelPackage": "Model\\Personalization",
"additionalProperties": {
"packageName": "algoliasearch-client-php",
Expand All @@ -264,8 +198,6 @@
},
"php-analytics": {
"output": "#{cwd}/clients/algoliasearch-client-php",
"gitRepoId": "algoliasearch-client-php",
"invokerPackage": "Algolia\\AlgoliaSearch",
"modelPackage": "Model\\Analytics",
"additionalProperties": {
"packageName": "algoliasearch-client-php",
Expand All @@ -274,8 +206,6 @@
},
"php-insights": {
"output": "#{cwd}/clients/algoliasearch-client-php",
"gitRepoId": "algoliasearch-client-php",
"invokerPackage": "Algolia\\AlgoliaSearch",
"modelPackage": "Model\\Insights",
"additionalProperties": {
"packageName": "algoliasearch-client-php",
Expand All @@ -284,24 +214,14 @@
},
"php-abtesting": {
"output": "#{cwd}/clients/algoliasearch-client-php",
"gitRepoId": "algoliasearch-client-php",
"invokerPackage": "Algolia\\AlgoliaSearch",
"modelPackage": "Model\\Abtesting",
"additionalProperties": {
"packageName": "algoliasearch-client-php",
"hasRegionalHost": true
}
},
"php-query-suggestions": {
"config": "#{cwd}/openapitools.json",
"gitHost": "algolia",
"gitUserId": "algolia",
"glob": "specs/bundled/query-suggestions.yml",
"templateDir": "#{cwd}/templates/php/",
"generatorName": "algolia-php",
"output": "#{cwd}/clients/algoliasearch-client-php",
"gitRepoId": "algoliasearch-client-php",
"invokerPackage": "Algolia\\AlgoliaSearch",
"modelPackage": "Model\\QuerySuggestions",
"additionalProperties": {
"packageName": "algoliasearch-client-php"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,11 @@ public String getHelp() {
public void processOpts() {
// generator specific options
setDateLibrary("java8");
setLibrary("okhttp-gson");
setSourceFolder("algoliasearch-core/src/main/java");
setInvokerPackage("com.algolia");
setGroupId("com.algolia");
additionalProperties.put("invokerPackage", "com.algolia");
setApiPackage("com.algolia.api");
setApiNameSuffix(Utils.API_SUFFIX);

super.processOpts();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void processOpts() {
// generator specific options
setSupportsES6(true);
setModelPropertyNaming("original");

setApiPackage("src");
// clear all supported files to avoid unwanted ones
supportingFiles.clear();
// model
Expand Down Expand Up @@ -60,6 +60,7 @@ private void setDefaultGeneratorOptions() {
additionalProperties.put("apiName", apiName);
additionalProperties.put("capitalizedApiName", Utils.capitalize(apiName));
additionalProperties.put("userAgent", Utils.capitalize(CLIENT));
additionalProperties.put("gitRepoId", "algoliasearch-client-javascript");
}

/** Provides an opportunity to inspect and modify operation data before the code is generated. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public void processOpts() {
// generator specific options
setApiNameSuffix(Utils.API_SUFFIX);
setParameterNamingConvention("camelCase");
additionalProperties.put("invokerPackage", "Algolia\\AlgoliaSearch");

super.processOpts();

Expand All @@ -88,4 +89,8 @@ public void processOpts() {
)
);
}

public String getComposerPackageName() {
return "algolia/algoliasearch-client-php";
}
}
30 changes: 0 additions & 30 deletions scripts/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,36 +86,6 @@ export function splitGeneratorKey(
return { language, client, key: generatorKey };
}

type GitHubUrl = (
lang: string,
options?: {
token?: string;
}
) => string;

export const getGitHubUrl: GitHubUrl = (
lang: string,
{ token } = {}
): string => {
const entry = Object.entries(openapiConfig['generator-cli'].generators).find(
(_entry) => _entry[0].startsWith(`${lang}-`)
);

if (!entry) {
throw new Error(`\`${lang}\` is not found from \`openapitools.json\`.`);
}
const { gitRepoId } = entry[1];

// GitHub Action provides a default token for authentication
// https://docs.github.com/en/actions/security-guides/automatic-token-authentication
// But it has access to only the self repository.
// If we want to do something like pushing commits to other repositories,
// we need to specify a token with more access.
return token
? `https://${token}:${token}@github.com/algolia/${gitRepoId}`
: `https://github.com/algolia/${gitRepoId}`;
};

export function createGeneratorKey({
language,
client,
Expand Down
16 changes: 16 additions & 0 deletions scripts/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,19 @@ export function getPackageVersionDefault(language: Language): string {
}
return clientsConfig[language].packageVersion;
}

export function getGitHubUrl(
language: Language,
options?: { token: string }
): string {
const { gitRepoId } = clientsConfig[language];

// GitHub Action provides a default token for authentication
// https://docs.github.com/en/actions/security-guides/automatic-token-authentication
// But it has access to only the self repository.
// If we want to do something like pushing commits to other repositories,
// we need to specify a token with more access.
return options?.token
? `https://${options.token}:${options.token}@github.com/algolia/${gitRepoId}`
: `https://github.com/algolia/${gitRepoId}`;
}
Loading

0 comments on commit f903ebd

Please sign in to comment.