From 7806e13c29046f2f22339407934e96cc1aec2d4e Mon Sep 17 00:00:00 2001 From: "chen.ma" Date: Sun, 27 Mar 2022 12:42:12 +0800 Subject: [PATCH] Delete github notification module --- hippo4j-tools/open-change-tool/.gitignore | 33 ----- hippo4j-tools/open-change-tool/pom.xml | 62 -------- .../openchange/EnableOpenChangeNotify.java | 18 --- .../tools/openchange/GitHubRemote.java | 21 --- .../tools/openchange/OpenChangeInfo.java | 60 -------- .../OpenChangeNotifyBootstrapProperties.java | 57 ------- .../openchange/OpenChangeNotifyConfig.java | 30 ---- .../tools/openchange/OpenChangeTimedTask.java | 139 ------------------ 8 files changed, 420 deletions(-) delete mode 100644 hippo4j-tools/open-change-tool/.gitignore delete mode 100644 hippo4j-tools/open-change-tool/pom.xml delete mode 100644 hippo4j-tools/open-change-tool/src/main/java/cn/hippo4j/tools/openchange/EnableOpenChangeNotify.java delete mode 100644 hippo4j-tools/open-change-tool/src/main/java/cn/hippo4j/tools/openchange/GitHubRemote.java delete mode 100644 hippo4j-tools/open-change-tool/src/main/java/cn/hippo4j/tools/openchange/OpenChangeInfo.java delete mode 100644 hippo4j-tools/open-change-tool/src/main/java/cn/hippo4j/tools/openchange/OpenChangeNotifyBootstrapProperties.java delete mode 100644 hippo4j-tools/open-change-tool/src/main/java/cn/hippo4j/tools/openchange/OpenChangeNotifyConfig.java delete mode 100644 hippo4j-tools/open-change-tool/src/main/java/cn/hippo4j/tools/openchange/OpenChangeTimedTask.java diff --git a/hippo4j-tools/open-change-tool/.gitignore b/hippo4j-tools/open-change-tool/.gitignore deleted file mode 100644 index 549e00a2..00000000 --- a/hippo4j-tools/open-change-tool/.gitignore +++ /dev/null @@ -1,33 +0,0 @@ -HELP.md -target/ -!.mvn/wrapper/maven-wrapper.jar -!**/src/main/**/target/ -!**/src/test/**/target/ - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -build/ -!**/src/main/**/build/ -!**/src/test/**/build/ - -### VS Code ### -.vscode/ diff --git a/hippo4j-tools/open-change-tool/pom.xml b/hippo4j-tools/open-change-tool/pom.xml deleted file mode 100644 index 53726e51..00000000 --- a/hippo4j-tools/open-change-tool/pom.xml +++ /dev/null @@ -1,62 +0,0 @@ - - - 4.0.0 - - - cn.hippo4j - hippo4j-tools - ${revision} - - - open-change-tool - jar - - ${project.artifactId} - 监控 GitHub 项目 Star、Fork 变更, 有变化则发起通知. - - - true - - - - - org.springframework.boot - spring-boot-starter - - - - org.springframework.boot - spring-boot-starter-test - test - - - - org.projectlombok - lombok - - - - com.aliyun - alibaba-dingtalk-service-sdk - - - - log4j - log4j - - - - - - com.dtflys.forest - forest-spring-boot-starter - - - - cn.hutool - hutool-all - - - - diff --git a/hippo4j-tools/open-change-tool/src/main/java/cn/hippo4j/tools/openchange/EnableOpenChangeNotify.java b/hippo4j-tools/open-change-tool/src/main/java/cn/hippo4j/tools/openchange/EnableOpenChangeNotify.java deleted file mode 100644 index 6ed552d3..00000000 --- a/hippo4j-tools/open-change-tool/src/main/java/cn/hippo4j/tools/openchange/EnableOpenChangeNotify.java +++ /dev/null @@ -1,18 +0,0 @@ -package cn.hippo4j.tools.openchange; - -import org.springframework.context.annotation.Import; - -import java.lang.annotation.*; - -/** - * Change timed task. - * - * @author chen.ma - * @date 2021/10/31 13:39 - */ -@Target(ElementType.TYPE) -@Retention(RetentionPolicy.RUNTIME) -@Import(OpenChangeNotifyConfig.class) -@Documented -public @interface EnableOpenChangeNotify { -} diff --git a/hippo4j-tools/open-change-tool/src/main/java/cn/hippo4j/tools/openchange/GitHubRemote.java b/hippo4j-tools/open-change-tool/src/main/java/cn/hippo4j/tools/openchange/GitHubRemote.java deleted file mode 100644 index 31f95349..00000000 --- a/hippo4j-tools/open-change-tool/src/main/java/cn/hippo4j/tools/openchange/GitHubRemote.java +++ /dev/null @@ -1,21 +0,0 @@ -package cn.hippo4j.tools.openchange; - -import com.dtflys.forest.annotation.Get; - -/** - * GitHub remote. - * - * @author chen.ma - * @date 2021/10/31 10:45 - */ -public interface GitHubRemote { - - /** - * 获取 GitHub 仓库详细信息. - * - * @return - */ - @Get("https://api.github.com/repos/acmenlt/dynamic-threadpool") - OpenChangeInfo getGitHubItemInfo(); - -} diff --git a/hippo4j-tools/open-change-tool/src/main/java/cn/hippo4j/tools/openchange/OpenChangeInfo.java b/hippo4j-tools/open-change-tool/src/main/java/cn/hippo4j/tools/openchange/OpenChangeInfo.java deleted file mode 100644 index 9d104579..00000000 --- a/hippo4j-tools/open-change-tool/src/main/java/cn/hippo4j/tools/openchange/OpenChangeInfo.java +++ /dev/null @@ -1,60 +0,0 @@ -package cn.hippo4j.tools.openchange; - -import lombok.Data; - -/** - * Open change info. - * - * @author chen.ma - * @date 2021/10/31 10:33 - */ -@Data -public class OpenChangeInfo { - - /** - * name - */ - private String name; - - /** - * stars - */ - private Long stargazers_count; - - /** - * forks - */ - private Long forks_count; - - /** - * open issues - */ - private Long open_issues_count; - - /** - * url - */ - private String html_url; - - /** - * subscribers - */ - private Long subscribers_count; - - /** - * default branch - */ - private String default_branch; - - /** - * star_add - */ - private Long star_add; - - /** - * fork_add - */ - - private Long fork_add; - -} diff --git a/hippo4j-tools/open-change-tool/src/main/java/cn/hippo4j/tools/openchange/OpenChangeNotifyBootstrapProperties.java b/hippo4j-tools/open-change-tool/src/main/java/cn/hippo4j/tools/openchange/OpenChangeNotifyBootstrapProperties.java deleted file mode 100644 index 5b37c80c..00000000 --- a/hippo4j-tools/open-change-tool/src/main/java/cn/hippo4j/tools/openchange/OpenChangeNotifyBootstrapProperties.java +++ /dev/null @@ -1,57 +0,0 @@ -package cn.hippo4j.tools.openchange; - -import lombok.Data; -import lombok.Getter; -import lombok.Setter; -import lombok.extern.slf4j.Slf4j; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; - -import java.util.List; - -/** - * Bootstrap properties. - * - * @author chen.ma - * @date 2021/6/22 09:14 - */ -@Slf4j -@Getter -@Setter -@Configuration -@ConfigurationProperties(prefix = OpenChangeNotifyBootstrapProperties.PREFIX) -public class OpenChangeNotifyBootstrapProperties { - - public static final String PREFIX = "spring.dynamic.thread-pool"; - - /** - * notifyInterval - */ - private Long notifyInterval; - - /** - * notifys - */ - private List notifys; - - @Data - public static class NotifyConfig { - - /** - * type - */ - private String type; - - /** - * url - */ - private String url; - - /** - * token - */ - private String token; - - } - -} diff --git a/hippo4j-tools/open-change-tool/src/main/java/cn/hippo4j/tools/openchange/OpenChangeNotifyConfig.java b/hippo4j-tools/open-change-tool/src/main/java/cn/hippo4j/tools/openchange/OpenChangeNotifyConfig.java deleted file mode 100644 index c0c81c19..00000000 --- a/hippo4j-tools/open-change-tool/src/main/java/cn/hippo4j/tools/openchange/OpenChangeNotifyConfig.java +++ /dev/null @@ -1,30 +0,0 @@ -package cn.hippo4j.tools.openchange; - -import com.dtflys.forest.springboot.annotation.ForestScan; -import lombok.AllArgsConstructor; -import org.springframework.boot.autoconfigure.ImportAutoConfiguration; -import org.springframework.context.annotation.Bean; -import org.springframework.scheduling.annotation.EnableScheduling; - -/** - * 项目变更通知配置. - * - * @author chen.ma - * @date 2021/10/31 10:23 - */ -@EnableScheduling -@AllArgsConstructor -@ImportAutoConfiguration(OpenChangeNotifyBootstrapProperties.class) -@ForestScan(basePackages = "com.github.dynamic.threadpool.openchange") -public class OpenChangeNotifyConfig { - - private final GitHubRemote gitHubRemote; - - private final OpenChangeNotifyBootstrapProperties bootstrapProperties; - - @Bean - public OpenChangeTimedTask changeTimedTask() { - return new OpenChangeTimedTask(gitHubRemote, bootstrapProperties); - } - -} diff --git a/hippo4j-tools/open-change-tool/src/main/java/cn/hippo4j/tools/openchange/OpenChangeTimedTask.java b/hippo4j-tools/open-change-tool/src/main/java/cn/hippo4j/tools/openchange/OpenChangeTimedTask.java deleted file mode 100644 index bd8e3713..00000000 --- a/hippo4j-tools/open-change-tool/src/main/java/cn/hippo4j/tools/openchange/OpenChangeTimedTask.java +++ /dev/null @@ -1,139 +0,0 @@ -package cn.hippo4j.tools.openchange; - -import cn.hutool.core.date.DateUtil; -import cn.hutool.core.thread.ThreadUtil; -import cn.hutool.json.JSONUtil; -import com.dingtalk.api.DefaultDingTalkClient; -import com.dingtalk.api.DingTalkClient; -import com.dingtalk.api.request.OapiRobotSendRequest; -import com.taobao.api.ApiException; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.InitializingBean; -import org.springframework.scheduling.annotation.Scheduled; - -import java.util.concurrent.TimeUnit; - -/** - * Change timed task. - * - * @author chen.ma - * @date 2021/10/31 10:39 - */ -@Slf4j -@RequiredArgsConstructor -public class OpenChangeTimedTask implements InitializingBean { - - @NonNull - private final GitHubRemote gitHubRemote; - - @NonNull - private final OpenChangeNotifyBootstrapProperties bootstrapProperties; - - private OpenChangeInfo lastChangeInfo; - - @Scheduled(cron = "0 0/5 * * * ?") - public void execute() { - OpenChangeInfo itemInfo = null; - try { - itemInfo = gitHubRemote.getGitHubItemInfo(); - // 防止初始化调用 GitHub 403 - if (lastChangeInfo == null) { - lastChangeInfo = itemInfo; - log.info("Init... GitHub Item Info :: {}", JSONUtil.toJsonStr(lastChangeInfo)); - return; - } - } catch (Throwable ex) { - log.error("Failed to call GitHub API interface.", ex); - - // 担心 GitHub 限制访问 403, 如异常则睡眠 5 分钟 - ThreadUtil.sleep(5, TimeUnit.MINUTES); - return; - } - - long addStarNum, addForkChange; - boolean starChange = (addStarNum = (itemInfo.getStargazers_count() - lastChangeInfo.getStargazers_count())) > 0; - if (starChange) { - itemInfo.setStar_add(addStarNum); - } - - boolean forkChange = (addForkChange = (itemInfo.getForks_count() - lastChangeInfo.getForks_count())) > 0; - if (forkChange) { - itemInfo.setFork_add(addForkChange); - } - - if (starChange == false && forkChange == false) { - log.info("Star and fork are unchanged."); - return; - } - - sendDingMessage(itemInfo); - lastChangeInfo = itemInfo; - } - - public void sendDingMessage(OpenChangeInfo itemInfo) { - String gitHubItemUrl = itemInfo.getHtml_url(); - String markdownText = String.format( - "[通知] GitHub Star Fork 变更通知 \n\n" + - " --- \n\n " + - "项目名称:HIPPO-JAVA \n\n" + - "项目地址:[%s](%s) \n\n" + - " --- \n\n " + - "Hippo Stars Add:%s \n\n " + - "Hippo Forks Add:%s \n\n " + - " --- \n\n " + - "Hippo Now Star:[%d](" + gitHubItemUrl + "/stargazers) \n\n" + - "Hippo Now Fork:[%d](" + gitHubItemUrl + "/members) \n\n" + - "Hippo Open Issue:[%d](" + gitHubItemUrl + "/issues) \n\n" + - "Hippo Subscribers Count:[%d](" + gitHubItemUrl + "/watchers) \n\n" + - " --- \n\n " + - "友情提示:5 分钟内 Star Fork 有变更则通知(可配置) \n\n" + - "OWNER:Long-Tai \n\n" + - " --- \n\n " + - "**播报时间:%s**", - - itemInfo.getName().toUpperCase(), - gitHubItemUrl, - - itemInfo.getStar_add() == null ? "-" : itemInfo.getStar_add().toString() + "+", - itemInfo.getFork_add() == null ? "-" : itemInfo.getFork_add().toString() + "+", - - itemInfo.getStargazers_count(), - itemInfo.getForks_count(), - itemInfo.getOpen_issues_count(), - itemInfo.getSubscribers_count(), - - DateUtil.now() - ); - - OpenChangeNotifyBootstrapProperties.NotifyConfig notifyConfig = bootstrapProperties.getNotifys().get(0); - String serverUrl = notifyConfig.getUrl() + notifyConfig.getToken(); - DingTalkClient dingTalkClient = new DefaultDingTalkClient(serverUrl); - OapiRobotSendRequest request = new OapiRobotSendRequest(); - request.setMsgtype("markdown"); - - OapiRobotSendRequest.Markdown markdown = new OapiRobotSendRequest.Markdown(); - markdown.setTitle("GitHub Star Fork 变更通知"); - markdown.setText(markdownText); - request.setMarkdown(markdown); - - try { - dingTalkClient.execute(request); - } catch (ApiException ex) { - log.error("Ding failed to send message.", ex.getMessage()); - } - } - - @Override - public void afterPropertiesSet() throws Exception { - try { - lastChangeInfo = gitHubRemote.getGitHubItemInfo(); - } catch (Throwable ex) { - log.error("Init error..."); - } - - log.info("Init success... GitHub Item Info :: {}", JSONUtil.toJsonStr(lastChangeInfo)); - } - -}