diff --git a/.github/workflows/codecov.yaml b/.github/workflows/codecov.yaml index 4c70bc2..516668c 100644 --- a/.github/workflows/codecov.yaml +++ b/.github/workflows/codecov.yaml @@ -1,27 +1,4 @@ --- name: codecov -on: - push: - branches: [ "master" ] - pull_request: - branches: [ "master" ] -jobs: - codecov: - runs-on: ubuntu-20.04 - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-java@v3 - with: - distribution: 'temurin' - java-version: 17 - - uses: actions/cache@v3 - with: - path: ~/.m2/repository - key: maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - maven- - - run: mvn clean install - - uses: codecov/codecov-action@v3 - with: - files: ./target/site/jacoco/jacoco.xml - fail_ci_if_error: true +# @todo #1 Add codecov GHA +# Add codecov GHA after implementation of POC \ No newline at end of file diff --git a/.github/workflows/mvn.yaml b/.github/workflows/mvn.yaml index 145b232..e781459 100644 --- a/.github/workflows/mvn.yaml +++ b/.github/workflows/mvn.yaml @@ -12,8 +12,8 @@ jobs: name: Tests strategy: matrix: - os: [ubuntu-20.04, macos-12] - java: [11, 17] + os: [ ubuntu-20.04, macos-12 ] + java: [ 17, 20 ] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 diff --git a/LICENSE b/LICENSE.txt similarity index 88% rename from LICENSE rename to LICENSE.txt index 4821d65..b7bba72 100644 --- a/LICENSE +++ b/LICENSE.txt @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 Ivan Ivanchuk +Copyright (c) 2023 Blamer.io Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -14,8 +14,8 @@ copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md index e21c9a6..a3069cf 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,5 @@ -# elegant -This is a pre-configured template for your projects in Java, you can use it with any language, [more about it](https://h1alexbel.github.io/2023/01/21/maintainable-project-template.html) +blamer-bot -## Tools: - - [Rultor](https://www.rultor.com/) for CI/CD. - - [0pdd](https://www.0pdd.com/) for issue management. - - [Renovate](https://www.mend.io/free-developer-tools/renovate/) for dependency control. - - [xcop](https://www.yegor256.com/2017/08/29/xcop.html) GitHub action for XML style check. +[![codecov](https://codecov.io/gh/Blamer-io/hub/branch/master/graph/badge.svg?token=5HCTK3KRGL)](https://codecov.io/gh/Blamer-io/notifications) -## How to use? - - Configure actions in `workflows` folder. - - [Configure](https://doc.rultor.com/reference.html) the `@rultor`. - - [Configure](https://www.yegor256.com/2017/04/05/pdd-in-action.html) the `0pdd`. - - [Configure](https://github.com/marketplace/renovate) the `renovate`. - -And you're good to go! +Blamer Notifications is a service that transfers GitHub notifications into text notifications for Telegram diff --git a/blamer-notifications.svg b/blamer-notifications.svg new file mode 100644 index 0000000..3dc404e --- /dev/null +++ b/blamer-notifications.svg @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/checkstyle-suppressions.xml b/checkstyle-suppressions.xml new file mode 100644 index 0000000..e3b75e1 --- /dev/null +++ b/checkstyle-suppressions.xml @@ -0,0 +1,33 @@ + + + + + + + + + + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..e166567 --- /dev/null +++ b/pom.xml @@ -0,0 +1,144 @@ + + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.0.6 + + + + io.blamer + notifications + 0.0.1-SNAPSHOT + notifications + Demo project for Spring Boot + + 17 + 3.2.2 + 8.15 + 0.1.9 + 1.5.0 + 4.1.91.Final + + + + org.springframework.boot + spring-boot-starter-webflux + + + com.jcabi + jcabi-github + ${jcabi-github.version} + + + io.netty + netty-resolver-dns-native-macos + ${netty-resolver-dns-native-macos.version} + osx-aarch_64 + + + org.springframework.boot + spring-boot-devtools + runtime + true + + + org.springframework.boot + spring-boot-configuration-processor + true + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + io.projectreactor + reactor-test + test + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + ${maven-checkstyle-plugin.version} + + + com.puppycrawl.tools + checkstyle + ${checkstyle.version} + + + + + verify-style + process-classes + + check + + + checkstyle.suppressions.file + checkstyle-suppressions.xml + + + + + + com.github.volodya-lombrozo + jtcop-maven-plugin + ${jtcop-maven-plugin.version} + + + + check + + + + + + + diff --git a/src/main/java/io/blamer/notifications/NotificationsAppEntry.java b/src/main/java/io/blamer/notifications/NotificationsAppEntry.java new file mode 100644 index 0000000..d352ffd --- /dev/null +++ b/src/main/java/io/blamer/notifications/NotificationsAppEntry.java @@ -0,0 +1,47 @@ +/* + * MIT License + * + * Copyright (c) 2023 Blamer.io + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package io.blamer.notifications; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * Entry class. + * + * @since 0.0.0 + */ +@SpringBootApplication +public class NotificationsAppEntry { + + /** + * Entry point. + * + * @param args application arguments + */ + public static void main(final String[] args) { + SpringApplication.run(NotificationsAppEntry.class, args); + } + +} diff --git a/src/main/java/io/blamer/notifications/controller/NotificationsController.java b/src/main/java/io/blamer/notifications/controller/NotificationsController.java new file mode 100644 index 0000000..3b14511 --- /dev/null +++ b/src/main/java/io/blamer/notifications/controller/NotificationsController.java @@ -0,0 +1,68 @@ +/* + * MIT License + * + * Copyright (c) 2023 Blamer.io + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package io.blamer.notifications.controller; + +import io.blamer.notifications.message.UpdateMessage; +import io.blamer.notifications.user.TelegramUser; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +@Slf4j +@RestController +@RequestMapping("/api/v1/notifications") +@RequiredArgsConstructor +public class NotificationsController { + + private final WebClient webClient; + + @ResponseStatus(HttpStatus.ACCEPTED) + @PostMapping + public Mono receiveUser(@RequestBody final Mono user) { + return user + .doOnNext(usr -> log.info("Received {}", usr)) + .map( + usr -> + this.webClient.post() + .uri("/api/v1/bot/updates") + .contentType(MediaType.APPLICATION_JSON) + .bodyValue( + Flux.generate( + synchronousSink -> synchronousSink.next( + new UpdateMessage("Update!", usr.getChat()) + ) + ) + ) + .retrieve() + .bodyToFlux(Void.class) + .then() + ).then(); + } +} diff --git a/src/main/java/io/blamer/notifications/extension/ExtWebClient.java b/src/main/java/io/blamer/notifications/extension/ExtWebClient.java new file mode 100644 index 0000000..9aa0059 --- /dev/null +++ b/src/main/java/io/blamer/notifications/extension/ExtWebClient.java @@ -0,0 +1,42 @@ +/* + * MIT License + * + * Copyright (c) 2023 Blamer.io + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package io.blamer.notifications.extension; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.reactive.function.client.WebClient; + +@Configuration +public class ExtWebClient { + + @Value("${spring.bot.base-url}") + private String baseUrl; + + @Bean + public WebClient webClient() { + return WebClient.create(this.baseUrl); + } +} diff --git a/src/main/java/io/blamer/notifications/message/UpdateMessage.java b/src/main/java/io/blamer/notifications/message/UpdateMessage.java new file mode 100644 index 0000000..df53127 --- /dev/null +++ b/src/main/java/io/blamer/notifications/message/UpdateMessage.java @@ -0,0 +1,42 @@ +/* + * MIT License + * + * Copyright (c) 2023 Blamer.io + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package io.blamer.notifications.message; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class UpdateMessage { + + private String text; + + private String chat; + +} diff --git a/src/main/java/io/blamer/notifications/package-info.java b/src/main/java/io/blamer/notifications/package-info.java new file mode 100644 index 0000000..e02b3f2 --- /dev/null +++ b/src/main/java/io/blamer/notifications/package-info.java @@ -0,0 +1,28 @@ +/* + * MIT License + * + * Copyright (c) 2023 Blamer.io + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/** + * The root package. + */ +package io.blamer.notifications; diff --git a/src/main/java/io/blamer/notifications/service/NotificationsGenerator.java b/src/main/java/io/blamer/notifications/service/NotificationsGenerator.java new file mode 100644 index 0000000..53f862e --- /dev/null +++ b/src/main/java/io/blamer/notifications/service/NotificationsGenerator.java @@ -0,0 +1,47 @@ +/* + * MIT License + * + * Copyright (c) 2023 Blamer.io + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package io.blamer.notifications.service; + +import io.blamer.notifications.message.UpdateMessage; +import org.springframework.stereotype.Service; +import reactor.core.publisher.Flux; + +@Service +public class NotificationsGenerator { + + public Flux generate(final String chat) { + return Flux.generate( + () -> new UpdateMessage("First message!", chat), + (state, sink) -> { + try { + Thread.sleep(1500L); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + return new UpdateMessage(state.getText(), state.getChat()); + } + ); + } +} diff --git a/src/main/java/io/blamer/notifications/user/TelegramUser.java b/src/main/java/io/blamer/notifications/user/TelegramUser.java new file mode 100644 index 0000000..f39d618 --- /dev/null +++ b/src/main/java/io/blamer/notifications/user/TelegramUser.java @@ -0,0 +1,42 @@ +/* + * MIT License + * + * Copyright (c) 2023 Blamer.io + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package io.blamer.notifications.user; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class TelegramUser { + + private String token; + + private String chat; + +} diff --git a/src/main/resources/application-dev.yaml b/src/main/resources/application-dev.yaml new file mode 100644 index 0000000..4d56222 --- /dev/null +++ b/src/main/resources/application-dev.yaml @@ -0,0 +1,8 @@ +spring: + bot: + base-url: http://localhost:8065 +server: + port: 8067 +logging: + level: + web: debug diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml new file mode 100644 index 0000000..bda45c3 --- /dev/null +++ b/src/main/resources/application.yaml @@ -0,0 +1,9 @@ +server: + port: ${NOTIFICATIONS_PORT} +spring: + rsocket: + server: + port: ${NOTIFICATIONS_RSOCKET_PORT} +bot: + host: ${BOT_HOST} + rsocket_port: ${BOT_RSOCKET_PORT} \ No newline at end of file diff --git a/src/test/java/io/blamer/notifications/NotificationsAppEntryTests.java b/src/test/java/io/blamer/notifications/NotificationsAppEntryTests.java new file mode 100644 index 0000000..a1f2135 --- /dev/null +++ b/src/test/java/io/blamer/notifications/NotificationsAppEntryTests.java @@ -0,0 +1,37 @@ +/* + * MIT License + * + * Copyright (c) 2023 Blamer.io + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package io.blamer.notifications; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class NotificationsAppEntryTests { + + @Test + void loadsContext() { + } + +}