Skip to content

Commit

Permalink
chore(clients): add workflow to auto-close PR (#3834)
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcuts authored Sep 26, 2024
1 parent 4c7e4a5 commit 7884835
Show file tree
Hide file tree
Showing 24 changed files with 58 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,7 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("netcore_project.mustache", "Algolia.Search.csproj"));
supportingFiles.add(new SupportingFile("Configuration.mustache", "Clients", packageName + "Configuration.cs"));

supportingFiles.add(new SupportingFile("LICENSE", "../", "LICENSE"));
supportingFiles.add(new SupportingFile("issue.yml", "../.github/workflows", "issue.yml"));
supportingFiles.add(new SupportingFile("Bug_report.yml", "../.github/ISSUE_TEMPLATE", "Bug_report.yml"));
Helpers.addCommonSupportingFiles(supportingFiles, "../");

reservedWords.removeIf(word -> word.equals("Configuration"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,9 @@ public void processOpts() {

supportingFiles.add(new SupportingFile("version.mustache", srcFolder, "version.dart"));
supportingFiles.add(new SupportingFile("LICENSE", "", "LICENSE"));

supportingFiles.add(new SupportingFile("LICENSE", "../client_core/", "LICENSE"));
supportingFiles.add(new SupportingFile("issue.yml", "../../.github/workflows", "issue.yml"));
supportingFiles.add(new SupportingFile("Bug_report.yml", "../../.github/ISSUE_TEMPLATE", "Bug_report.yml"));

Helpers.addCommonSupportingFiles(supportingFiles, "../../");

// Search config
additionalProperties.put("isSearchClient", client.equals("search"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("configuration.mustache", "", "configuration.go"));
supportingFiles.add(new SupportingFile("client.mustache", "", "client.go"));

supportingFiles.add(new SupportingFile("LICENSE", "../../", "LICENSE"));
supportingFiles.add(new SupportingFile("issue.yml", "../../.github/workflows", "issue.yml"));
supportingFiles.add(new SupportingFile("Bug_report.yml", "../../.github/ISSUE_TEMPLATE", "Bug_report.yml"));
Helpers.addCommonSupportingFiles(supportingFiles, "../../");

try {
additionalProperties.put("packageVersion", Helpers.getClientConfigField("go", "packageVersion"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("gradle.properties.mustache", "", "gradle.properties"));
additionalProperties.put("isSearchClient", client.equals("search"));

supportingFiles.add(new SupportingFile("LICENSE", "", "LICENSE"));
supportingFiles.add(new SupportingFile("issue.yml", ".github/workflows", "issue.yml"));
supportingFiles.add(new SupportingFile("Bug_report.yml", ".github/ISSUE_TEMPLATE", "Bug_report.yml"));
Helpers.addCommonSupportingFiles(supportingFiles, "");

reservedWords.removeIf(word -> word.equals("configuration"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,9 @@ public void processOpts() {
// root export files
supportingFiles.add(new SupportingFile("index.mustache", "", "index.js"));
supportingFiles.add(new SupportingFile("index.d.mustache", "", "index.d.ts"));

supportingFiles.add(new SupportingFile("LICENSE", "", "LICENSE"));
supportingFiles.add(new SupportingFile("LICENSE", "", "../../LICENSE"));
supportingFiles.add(new SupportingFile("issue.yml", "../../.github/workflows", "issue.yml"));
supportingFiles.add(new SupportingFile("Bug_report.yml", "../../.github/ISSUE_TEMPLATE", "Bug_report.yml"));

Helpers.addCommonSupportingFiles(supportingFiles, "../../");

supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("gradle.properties.mustache", "", "gradle.properties"));
supportingFiles.add(new SupportingFile("README_BOM.mustache", "client-bom", "README.md"));

supportingFiles.add(new SupportingFile("LICENSE", "", "LICENSE"));
supportingFiles.add(new SupportingFile("issue.yml", ".github/workflows", "issue.yml"));
supportingFiles.add(new SupportingFile("Bug_report.yml", ".github/ISSUE_TEMPLATE", "Bug_report.yml"));
Helpers.addCommonSupportingFiles(supportingFiles, "");

additionalProperties.put("packageVersion", Helpers.getClientConfigField("kotlin", "packageVersion"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("client_config.mustache", "lib/Configuration", getClientName(client) + "Config.php"));
supportingFiles.add(new SupportingFile("Algolia.mustache", "lib", "Algolia.php"));

supportingFiles.add(new SupportingFile("LICENSE", "", "LICENSE"));
supportingFiles.add(new SupportingFile("issue.yml", ".github/workflows", "issue.yml"));
supportingFiles.add(new SupportingFile("Bug_report.yml", ".github/ISSUE_TEMPLATE", "Bug_report.yml"));
Helpers.addCommonSupportingFiles(supportingFiles, "");

additionalProperties.put("isSearchClient", client.equals("search"));
additionalProperties.put("configClassname", getClientName(client) + "Config");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("__init__.mustache", "http", "__init__.py"));
supportingFiles.add(new SupportingFile("config.mustache", packageName, "config.py"));

supportingFiles.add(new SupportingFile("LICENSE", "../", "LICENSE"));
supportingFiles.add(new SupportingFile("issue.yml", "../.github/workflows", "issue.yml"));
supportingFiles.add(new SupportingFile("Bug_report.yml", "../.github/ISSUE_TEMPLATE", "Bug_report.yml"));
Helpers.addCommonSupportingFiles(supportingFiles, "../");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ public void processOpts() {
apiTestTemplateFiles.clear();
modelTestTemplateFiles.clear();

supportingFiles.add(new SupportingFile("LICENSE", "", "LICENSE"));
supportingFiles.add(new SupportingFile("issue.yml", ".github/workflows", "issue.yml"));
supportingFiles.add(new SupportingFile("Bug_report.yml", ".github/ISSUE_TEMPLATE", "Bug_report.yml"));
Helpers.addCommonSupportingFiles(supportingFiles, "");

// Remove some files we don't want to output or change their paths
supportingFiles.removeIf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("version.mustache", "", "version.sbt"));
supportingFiles.add(new SupportingFile("jsonSupport.mustache", modelFolder, "JsonSupport.scala"));

supportingFiles.add(new SupportingFile("LICENSE", "", "LICENSE"));
supportingFiles.add(new SupportingFile("issue.yml", ".github/workflows", "issue.yml"));
supportingFiles.add(new SupportingFile("Bug_report.yml", ".github/ISSUE_TEMPLATE", "Bug_report.yml"));
Helpers.addCommonSupportingFiles(supportingFiles, "");

additionalProperties.put("isSearchClient", client.equals("search"));
typeMapping.put("AnyType", "Any");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,7 @@ public void processOpts() {
supportingFiles.add(
new SupportingFile("client_configuration.mustache", sourceFolder, getClientName(CLIENT) + "ClientConfiguration.swift")
);
supportingFiles.add(new SupportingFile("LICENSE", "", "LICENSE"));
supportingFiles.add(new SupportingFile("issue.yml", ".github/workflows", "issue.yml"));
supportingFiles.add(new SupportingFile("Bug_report.yml", ".github/ISSUE_TEMPLATE", "Bug_report.yml"));
Helpers.addCommonSupportingFiles(supportingFiles, "");

supportingFiles.add(new SupportingFile("Package.mustache", "Package.swift"));
supportingFiles.add(new SupportingFile("podspec.mustache", projectName + ".podspec"));
Expand Down
10 changes: 10 additions & 0 deletions generators/src/main/java/com/algolia/codegen/utils/Helpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.openapitools.codegen.CodegenOperation;
import org.openapitools.codegen.CodegenServer;
import org.openapitools.codegen.CodegenServerVariable;
import org.openapitools.codegen.SupportingFile;
import org.openapitools.codegen.model.OperationsMap;

public class Helpers {
Expand Down Expand Up @@ -258,6 +259,15 @@ public static void prettyPrint(Object o) {
Json.prettyPrint(o);
}

public static void addCommonSupportingFiles(List<SupportingFile> supportingFiles, String root) {
supportingFiles.add(new SupportingFile("LICENSE", "", root + "LICENSE"));
supportingFiles.add(new SupportingFile("issue.yml", root + ".github/workflows", "issue.yml"));
supportingFiles.add(new SupportingFile("Bug_report.yml", root + ".github/ISSUE_TEMPLATE", "Bug_report.yml"));
supportingFiles.add(
new SupportingFile("do-not-edit-this-repository.yml", root + ".github/workflows", "do-not-edit-this-repository.yml")
);
}

public static String getLanguageVersion(String language) throws IOException {
String versionFile = language.equals("javascript")
? ".nvmrc"
Expand Down
1 change: 1 addition & 0 deletions templates/csharp/do-not-edit-this-repository.yml
1 change: 1 addition & 0 deletions templates/dart/do-not-edit-this-repository.yml
24 changes: 24 additions & 0 deletions templates/do-not-edit-this-repository.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Do not edit files in this repository

on:
pull_request:
types:
- opened
- synchronize
- reopen
branches:
- 'main'

jobs:
auto_close_pr:
name: Close PR
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Close PR
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
gh pr close "${PR_NUMBER}" -d -c "Thanks for contributing to our API clients! Sorry to close your PR, but this repository is fully generated, you can port your changes to [the API Clients Automation repository](https://github.com/algolia/api-clients-automation). If you need some guidance, feel free to [open an issue](https://github.com/algolia/api-clients-automation/issues) or [read our contribution guide](https://api-clients-automation.netlify.app/docs/introduction)."
1 change: 1 addition & 0 deletions templates/go/do-not-edit-this-repository.yml
1 change: 1 addition & 0 deletions templates/java/do-not-edit-this-repository.yml
1 change: 1 addition & 0 deletions templates/kotlin/do-not-edit-this-repository.yml
1 change: 1 addition & 0 deletions templates/php/do-not-edit-this-repository.yml
1 change: 1 addition & 0 deletions templates/python/do-not-edit-this-repository.yml
1 change: 1 addition & 0 deletions templates/ruby/do-not-edit-this-repository.yml
1 change: 1 addition & 0 deletions templates/scala/do-not-edit-this-repository.yml
1 change: 1 addition & 0 deletions templates/swift/do-not-edit-this-repository.yml

0 comments on commit 7884835

Please sign in to comment.