Commit a883b06e authored by Liang Ding's avatar Liang Ding

同步 GitHub solo-blog 仓库功能 #125

parent 7268a935
......@@ -20,7 +20,7 @@ import org.json.JSONObject;
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="https://hacpai.com/member/hzchendou">hzchendou</a>
* @version 1.6.0.6, Apr 6, 2020
* @version 1.7.0.0, May 20, 2020
* @since 0.6.0
*/
public final class Option {
......@@ -103,6 +103,11 @@ public final class Option {
*/
public static final String ID_C_SYNC_GITHUB = "syncGitHub";
/**
* Key of GitHub PAT (personal access token).
*/
public static final String ID_C_GITHUB_PAT = "githubPAT";
/**
* Key of enable sync (pull) GitHub. 拉取并展示仓库 https://hacpai.com/article/1557238327458
* https://github.com/b3log/solo/issues/12825
......
......@@ -27,7 +27,7 @@ import java.util.concurrent.TimeUnit;
* Cron management service.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.4, Apr 18, 2019
* @version 1.0.0.5, May 20, 2020
* @since 2.9.7
*/
@Service
......@@ -106,6 +106,7 @@ public class CronMgmtService {
articleMgmtService.refreshGitHub();
userMgmtService.refreshUSite();
exportService.exportHacPai();
exportService.exportGitHub();
} catch (final Exception e) {
LOGGER.log(Level.ERROR, "Executes cron failed", e);
} finally {
......
......@@ -47,7 +47,7 @@ import java.util.List;
* Solo initialization service.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.5.2.40, Apr 30, 2020
* @version 1.5.2.41, May 20, 2020
* @since 0.4.0
*/
@Service
......@@ -526,6 +526,12 @@ public class InitService {
syncGitHubOpt.put(Option.OPTION_VALUE, DefaultPreference.DEFAULT_SYNC_GITHUB);
optionRepository.add(syncGitHubOpt);
final JSONObject githubPATOpt = new JSONObject();
githubPATOpt.put(Keys.OBJECT_ID, Option.ID_C_GITHUB_PAT);
githubPATOpt.put(Option.OPTION_CATEGORY, Option.CATEGORY_C_PREFERENCE);
githubPATOpt.put(Option.OPTION_VALUE, "");
optionRepository.add(githubPATOpt);
final JSONObject pullGitHubOpt = new JSONObject();
pullGitHubOpt.put(Keys.OBJECT_ID, Option.ID_C_PULL_GITHUB);
pullGitHubOpt.put(Option.OPTION_CATEGORY, Option.CATEGORY_C_PREFERENCE);
......
......@@ -35,7 +35,7 @@ import java.util.Locale;
* Preference management service.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.4.0.7, Apr 15, 2020
* @version 1.4.0.8, May 20, 2020
* @since 0.4.0
*/
@Service
......@@ -207,6 +207,9 @@ public class PreferenceMgmtService {
syncGitHubOpt.put(Option.OPTION_VALUE, preference.optString(Option.ID_C_SYNC_GITHUB));
optionRepository.update(Option.ID_C_SYNC_GITHUB, syncGitHubOpt);
final String githubPATVal = preference.optString(Option.ID_C_GITHUB_PAT);
emptyPreferenceOptSave(Option.ID_C_GITHUB_PAT, githubPATVal);
final JSONObject pullGitHubOpt = optionRepository.get(Option.ID_C_PULL_GITHUB);
pullGitHubOpt.put(Option.OPTION_VALUE, preference.optString(Option.ID_C_PULL_GITHUB));
optionRepository.update(Option.ID_C_PULL_GITHUB, pullGitHubOpt);
......@@ -268,6 +271,7 @@ public class PreferenceMgmtService {
private void emptyPreferenceOptSave(final String optID, final String val) throws Exception {
// 该方法用于向后兼容,如果数据库中不存在该配置项则创建再保存
JSONObject opt = optionRepository.get(optID);
if (null == opt) {
opt = new JSONObject();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment