Compare commits

...

15 Commits

Author SHA1 Message Date
3943de1696 update github-readme-stats-zeekling.vercel.app 2022-11-23 00:39:57 +08:00
a71bde4a04 add build tips
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2022-05-03 09:15:08 +08:00
46a0faca8a support drone
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2022-05-03 00:50:30 +08:00
a04540e6f2 support drone
Some checks failed
continuous-integration/drone/pr Build is failing
2022-05-03 00:39:34 +08:00
9a70b76324 support drone
Some checks reported errors
continuous-integration/drone/push Build was killed
2022-05-03 00:36:39 +08:00
d3a78d414a support drone
Some checks reported errors
continuous-integration/drone/push Build encountered an error
2022-05-03 00:35:25 +08:00
30d46c56b9 support drone
Some checks failed
continuous-integration/drone/push Build is failing
2022-05-03 00:30:57 +08:00
4b7d53d2dc 更新样式 2022-04-18 00:07:34 +08:00
174d35dc96 更新样式 2022-04-15 20:07:04 +08:00
2cf756e34d test for get all reps ion github 2022-04-09 23:23:35 +08:00
73b132c68d 判断相同则不需要跟新 2021-03-29 21:17:56 +08:00
4cbfeb50e8 判断相同则不需要跟新 2021-03-28 22:20:23 +08:00
b468e94c51 删除logs文件夹 2021-03-28 21:18:21 +08:00
2d5b12af7e change my blog 2020-08-09 21:49:41 +08:00
8cebc4b40a change my blog 2020-08-02 19:47:07 +08:00
16 changed files with 341 additions and 62 deletions

49
.classpath Normal file
View File

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="target/generated-sources/annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

34
.project Normal file
View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>github_zeekling</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
<filteredResources>
<filter>
<id>1616937475973</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>

View File

@ -0,0 +1,2 @@
eclipse.preferences.version=1
org.eclipse.jdt.apt.aptEnabled=false

View File

@ -0,0 +1,9 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.processAnnotations=disabled
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8

View File

@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

View File

@ -1,5 +1,6 @@
## 跟新个人主页
```sh
git clone ssh://git@git.zeekling.cn:222/zeekling/github_zeekling.git
cd github_zeekling

View File

@ -1,5 +1,7 @@
package com.zeekling.blog;
import org.json.JSONArray;
/**
* @author zeekling [lingzhaohui@zeekling.cn]
* @version 1.0
@ -11,4 +13,6 @@ public interface BlogUpdateService {
int update();
JSONArray getGitHubRepos();
}

View File

@ -5,20 +5,24 @@ import com.rometools.rome.io.FeedException;
import com.zeekling.conf.BlogConfigure;
import com.zeekling.util.ConfigureUtil;
import com.zeekling.util.FeedXmlUtil;
import com.zeekling.util.FileUtils;
import com.zeekling.util.GitHubs;
import jodd.http.HttpRequest;
import jodd.http.HttpResponse;
import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.net.MalformedURLException;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.TimeZone;
/**
* @author zeekling [lingzhaohui@zeekling.cn]
@ -32,8 +36,6 @@ public class BlogUpdateServiceImpl implements BlogUpdateService {
private BlogConfigure blogConfigure = null;
private static String HTML_REGEX="<[^>]+>";
public BlogUpdateServiceImpl(String confPath) {
// init blogConfigure
try {
@ -62,54 +64,76 @@ public class BlogUpdateServiceImpl implements BlogUpdateService {
return -1;
}
final String readme = genSoloBlogReadme(loginName + "/" + blogConfigure.getRepoName());
LOGGER.log(Level.INFO, "begin get README.md");
final String oldReadme = FileUtils.readFile(blogConfigure.getGithubTmp() + "/README.md");
if (oldReadme != null && oldReadme.equals(readme)) {
LOGGER.info("not need update readme.");
return 0;
}
ok = GitHubs.updateFile(blogConfigure.getPat(), loginName, blogConfigure.getRepoName(), "README.md", readme.getBytes(StandardCharsets.UTF_8));
if (ok) {
LOGGER.log(Level.INFO, "Exported public articles to your repo [" + blogConfigure.getRepoName() + "]");
}
FileUtils.saveDataToFile(blogConfigure.getGithubTmp() + "/README.md", readme);
return 0;
}
private String genSoloBlogReadme(final String repoFullName) {
final StringBuilder bodyBuilder = new StringBuilder("### 最新\n");
final StringBuilder bodyBuilder = new StringBuilder("### 最新文章\n");
try {
List<SyndEntry> entries = FeedXmlUtil.parseXml(blogConfigure.getRss());
for (SyndEntry syndEntry: entries){
String des = syndEntry.getDescription().getValue();
des = des.replaceAll("\n", "\n > ");
bodyBuilder.append("\n* \uD83D\uDCDD [").append(syndEntry.getTitle()).append("](").append(syndEntry.getLink())
.append(") \n > ").append(des);
bodyBuilder.append("\n* \uD83D\uDCDD [")
.append(syndEntry.getTitle())
.append("](")
.append(syndEntry.getLink())
.append(") \n ");
}
} catch (FeedException | MalformedURLException e) {
e.printStackTrace();
}
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String currentDate = format.format(new Date());
bodyBuilder.append("\n\n");
String ret = "### Hey \uD83D\uDC4B, I'm [Zeek Ling](https://www/zeekling.cn)! \n" +
"![Github Stats](https://github-readme-stats.vercel.app/api?username=zeekling&show_icons=true) \n" +
"### 我在[小令童鞋](https://www/zeekling.cn)的近期动态\n" +
"\n" +
"⭐️ Star [个人主页](https://github.com/zeekling/zeekling) 后会自动更新,最近更新时间:`" + currentDate + "`\n" +
"\n<p align=\"center\"><img alt=\"${title}\" src=\"${favicon}\"></p><h2 align=\"center\">" +
"${title}\n" +
"</h2>\n" +
"\n" +
"<h4 align=\"center\">${subtitle}</h4>\n" +
"<p align=\"center\">" +
"<a title=\"${title}\" target=\"_blank\" href=\"https://github.com/${repoFullName}\"><img src=\"https://img.shields.io/github/last-commit/${repoFullName}.svg?style=flat-square&color=FF9900\"></a>\n" +
"<a title=\"GitHub repo size in bytes\" target=\"_blank\" href=\"https://github.com/${repoFullName}\"><img src=\"https://img.shields.io/github/repo-size/${repoFullName}.svg?style=flat-square\"></a>\n" +
"<a title=\"Hits\" target=\"_blank\" href=\"https://github.com/zeekling/hits\"><img src=\"https://hits.b3log.org/${repoFullName}.svg\"></a>" +
"</p>\n" +
"\n" +
"${body}\n\n" +
"\n" ;
String ret = "### Hey \uD83D\uDC4B, I'm [${title}](${home})! \n" +
"\n![Github Stats](https://github-readme-stats-zeekling.vercel.app/api?username=${username}&show_icons=true) \n\n" +
"### 我在博客[${title}](${home})的近期动态\n" +
"⭐️ Star [个人主页](https://github.com/${username}) 后会自动更新" +
"\n\n<p align=\"center\"><img alt=\"${title}\" src=\"${favicon}\"></p>" +
"<h2 align=\"center\"> ${title} </h2>\n" +
"\n" +
"<h4 align=\"center\">${subtitle}</h4>\n" +
"<p align=\"center\">" +
"<a title=\"${title}\" target=\"_blank\" href=\"https://github.com/${repoFullName}\"><img src=\"https://img.shields.io/github/last-commit/${repoFullName}.svg?style=flat-square&color=FF9900\"></a>\n" +
"<a title=\"GitHub repo size in bytes\" target=\"_blank\" href=\"https://github.com/${repoFullName}\"><img src=\"https://img.shields.io/github/repo-size/${repoFullName}.svg?style=flat-square\"></a>\n" +
"<a title=\"Hits\" target=\"_blank\" href=\"https://github.com/${username}/hits\">" +
"<img src=\"https://hits.b3log.org/${repoFullName}.svg\"></a>" +
"</p>\n" +
"\n" +
"${body}\n\n" +
"\n";
ret = ret.replace("${title}", blogConfigure.getClientTitle()).
replace("${subtitle}", blogConfigure.getClientSubtitle()).
replace("${favicon}", blogConfigure.getFavicon()).
replace("${repoFullName}", repoFullName).
replace("${body}", bodyBuilder.toString());
replace("${subtitle}", blogConfigure.getClientSubtitle()).
replace("${favicon}", blogConfigure.getFavicon()).
replace("${repoFullName}", repoFullName).
replace("${body}", bodyBuilder.toString()).
replace("${username}", blogConfigure.getRepoName()).
replace("${home}", blogConfigure.getHome());
return ret;
}
@Override
public JSONArray getGitHubRepos() {
if (blogConfigure == null) {
return null;
}
final JSONObject gitHubUser = GitHubs.getGitHubUser(blogConfigure.getPat());
if (null == gitHubUser) {
LOGGER.error("login failed");
return null;
}
LOGGER.info("login success");
final String myGitHubID = gitHubUser.optString("login");
return GitHubs.getGitHubRepos(myGitHubID);
}
}

View File

@ -28,8 +28,19 @@ public final class BlogConfigure {
@Value(name = "blog.rss")
private String rss;
@Value(name = "github.tmp")
private String githubTmp;
public String getClientTitle() {
public String getGithubTmp() {
return githubTmp;
}
public void setGithubTmp(String githubTmp) {
this.githubTmp = githubTmp;
}
public String getClientTitle() {
return clientTitle;
}
@ -84,4 +95,6 @@ public final class BlogConfigure {
public void setRss(String rss) {
this.rss = rss;
}
}

View File

@ -6,7 +6,6 @@ import org.apache.commons.lang.StringUtils;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.util.Properties;
@ -28,8 +27,8 @@ public final class ConfigureUtil {
return properties;
}
@SuppressWarnings("ReflectionForUnavailableAnnotation")
public static <T> T getNewInstants(String filePath, Class<T> tClass)
@SuppressWarnings("deprecation")
public static <T> T getNewInstants(String filePath, Class<T> tClass)
throws IllegalAccessException, InstantiationException, IOException {
T t = tClass.newInstance();
Properties properties = readProperties(filePath);

View File

@ -0,0 +1,66 @@
package com.zeekling.util;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public final class FileUtils {
public static void saveDataToFile(String filePath, String context) {
File file = new File(filePath);
if (!file.getParentFile().exists()) {
file.getParentFile().mkdir();
}
BufferedWriter writer = null;
try {
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file,false), "UTF-8"));
writer.write(context);
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
if(writer != null){
writer.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static String readFile(String filePath) {
File file = new File(filePath);
if (file == null || !file.exists()) {
return null;
}
BufferedReader reader = null;
StringBuilder res = new StringBuilder();
try {
FileInputStream fileInputStream = new FileInputStream(file);
InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8");
reader = new BufferedReader(inputStreamReader);
String tempString = null;
while ((tempString = reader.readLine()) != null){
res.append(tempString).append("\n");
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return res.toString();
}
}

View File

@ -47,19 +47,14 @@ public final class GitHubs {
*/
public static JSONArray getGitHubRepos(final String githubUserId) {
try {
final HttpResponse res = HttpRequest.get("https://hacpai.com/github/repos?id=" + githubUserId).trustAllCerts(true).
connectionTimeout(3000).timeout(7000).header("User-Agent", GitHubConstants.USER_AGENT).send();
final HttpResponse res = HttpRequest.get("https://api.github.com/users/" + githubUserId + "/repos").
connectionTimeout(20000).timeout(60000).header("User-Agent", GitHubConstants.USER_AGENT).send();
if (200 != res.statusCode()) {
LOGGER.error("error code:" + res.statusCode());
return null;
}
res.charset("UTF-8");
final JSONObject result = new JSONObject(res.bodyText());
if (0 != result.optInt(GitHubConstants.CODE)) {
return null;
}
final JSONObject data = result.optJSONObject(GitHubConstants.DATA);
return data.optJSONArray("githubrepos");
return new JSONArray(res.bodyText());
} catch (final Exception e) {
LOGGER.log(Level.ERROR, "Gets GitHub repos failed", e);
return null;
@ -89,9 +84,7 @@ public final class GitHubs {
return false;
}
final JSONObject body = new JSONObject().
put("message", ":memo: 更新博客").
put("content", Base64.getEncoder().encodeToString(content));
final JSONObject body = new JSONObject().put("message", ":memo: 自动更新博客").put("content", Base64.getEncoder().encodeToString(content));
if (200 == statusCode) {
final JSONObject responseData = new JSONObject(responseBody);
final JSONArray tree = responseData.optJSONArray("tree");

View File

@ -1,7 +1,8 @@
blog.title=小令童鞋
blog.subTitle=梅干菜你个小酥饼哦。
blog.title=ZEEKLING
blog.subTitle=Stay simple, stay naive.
blog.home=https://www/zeekling.cn
blog.rss=https://www.zeekling.cn/rss.xml
blog.favicon=https://img.zeekling.cn/images/2020/02/23/logo.th.png
github.pat=068783457fa6e084aad1342ed2730f33a0255b97
github.repoName=zeekling
github.tmp=/tmp

View File

@ -14,19 +14,14 @@ public class BlogUpdateTest {
@Test
public void updateGitHub(){
String pat = "068783457fa6e084aad1342ed2730f33a0255b97";
final JSONObject gitHubUser = GitHubs.getGitHubUser(pat);
if (null == gitHubUser) {
String configPath = "/home/zeekling/project/ling/github_zeekling/src/main/resources/blog.properties";
BlogUpdateService updateService = new BlogUpdateServiceImpl(configPath);
int res = updateService.update();
if (res == 0){
System.out.println("update github success!");
return;
}
final String loginName = gitHubUser.optString("login");
final String repoName = "zeekling";
boolean ok = GitHubs.createOrUpdateGitHubRepo(pat, loginName, repoName, "跟新主页", "https://www.zeekling.cn/");
if (!ok) {
return;
}
// final String readme = genSoloBlogReadme(clientTitle, clientSubtitle, preference.optString(Option.ID_C_FAVICON_URL), loginName + "/" + repoName);
System.out.println("update github failed!");
}
}

View File

@ -0,0 +1,21 @@
package com.zeekling.util;
import org.testng.Assert;
import org.testng.annotations.Test;
public class FileUtilsTest {
private String context = "test";
@Test
public void writeFile() {
FileUtils.saveDataToFile("/tmp/README.md", context);
}
@Test
public void readFile() {
String fileContext = FileUtils.readFile("/tmp/README.md");
System.out.println(fileContext);
}
}

View File

@ -1,5 +1,12 @@
package com.zeekling.util;
import com.zeekling.blog.BlogUpdateService;
import com.zeekling.blog.BlogUpdateServiceImpl;
import org.apache.commons.lang.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.testng.annotations.Test;
/**
* @author zeekling [lingzhaohui@zeekling.cn]
* @version 1.0
@ -8,6 +15,63 @@ package com.zeekling.util;
*/
public class GitHubsTest {
@Test
public void genGitHubInfo() {
String configPath = "/home/zeekling/project/ling/github_zeekling/src/main/resources/blog.properties";
BlogUpdateService updateService = new BlogUpdateServiceImpl(configPath);
JSONArray result = updateService.getGitHubRepos();
JSONArray compatibleResult = new JSONArray();
for (int i = 0; i < result.length(); i++){
JSONObject resultObject = result.optJSONObject(i);
JSONObject compatibleObject = new JSONObject();
if (resultObject.getBoolean("fork")) {
continue;
}
compatibleObject.put("githubrepoId", resultObject.optString("id"));
compatibleObject.put("githubrepoStatus", 0);
compatibleObject.put("oId", "" + System.currentTimeMillis());
compatibleObject.put("githubrepoDescription", resultObject.optString("description"));
compatibleObject.put("githubrepoHomepage", resultObject.optString("homepage"));
compatibleObject.put("githubrepoForksCount", resultObject.optLong("forks_count"));
compatibleObject.put("githubrepoOwnerId", resultObject.optJSONObject("owner").optString("id"));
compatibleObject.put("githubrepoStargazersCount", resultObject.optLong("stargazers_count"));
compatibleObject.put("githubrepoWatchersCount", resultObject.optLong("watchers_count"));
compatibleObject.put("githubrepoOwnerLogin", resultObject.optJSONObject("owner").optString("login"));
compatibleObject.put("githubrepoHTMLURL", resultObject.optString("html_url"));
compatibleObject.put("githubrepoLanguage", resultObject.optString("language"));
compatibleObject.put("githubrepoName", resultObject.optString("name"));
compatibleObject.put("githubrepoFullName", resultObject.optString("full_name"));
compatibleResult.put(compatibleObject);
}
System.out.println(compatibleResult);
final StringBuilder contentBuilder = new StringBuilder();
String stats = "\n![Github Stats](https://github-readme-stats.vercel.app/api?username={username}&show_icons=true) \n\n";
stats = stats.replace("{username}", "zeekling");
contentBuilder.append("![GitHub Repo](/images/github_repo.jpg)\n\n");
contentBuilder.append("## Github Stats\n").append(stats);
contentBuilder.append("## 所有开源项目\n");
contentBuilder.append("| 仓库 | 项目简介 | 收藏数 | fork数 | 项目主页 | 主要编程语言 |\n | ---- | ---- | ---- | ---- | ---- | ---- |\n");
for (int i = 0; i < compatibleResult.length(); i++) {
final JSONObject repo = compatibleResult.optJSONObject(i);
final String url = repo.optString("githubrepoHTMLURL");
final String desc = repo.optString("githubrepoDescription");
final String name = repo.optString("githubrepoName");
final String stars = repo.optString("githubrepoStargazersCount");
final String forks = repo.optString("githubrepoForksCount");
final String lang = repo.optString("githubrepoLanguage");
final String hp = repo.optString("githubrepoHomepage");
contentBuilder.append("| [").append(name).append("](").append(url).append(") | ")
.append(desc).append(" | ")
.append(stars).append(" | ")
.append(forks).append(" | ")
.append(hp).append(" | ")
.append(lang).append("|\n");
}
FileUtils.saveDataToFile("/tmp/GITHUB.md", contentBuilder.toString());
}
}