Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(clients): add workflow to auto-close PR #3834

Merged
merged 6 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: |
Copy link
Collaborator

@millotp millotp Sep 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to check that the PR is targeting main, because it's possible to do bug fixes on older version

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh sorry I missed that

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
Loading