11const router = require ( "koa-router" ) ( ) ;
22const fetch = require ( "node-fetch" ) ;
3+ const fs = require ( "fs" ) ;
4+ const path = require ( "path" ) ;
5+ const process = require ( "child_process" ) ;
36
47const { getDay } = require ( "../utils/day" ) ;
58const { success, fail } = require ( "../utils/request" ) ;
9+ const mySolutions = require ( "../static/my/solutions.json" ) ;
610const solutions = require ( "../static/solution/solutions.json" ) ;
7- // const mySolutions = require("../database");
811
912router . all ( "/api/v1/github/content" , async ( ctx ) => {
1013 const { url, ...params } = ctx . query ;
@@ -30,13 +33,30 @@ router.all("/api/v1/github/content", async (ctx) => {
3033
3134router . all ( "/api/v1/github/webhook" , async ( ctx ) => {
3235 const { action, comment, issue } = ctx . request . body ;
33- if ( issue . number === solutions [ getDay ( ) - 1 ] . issue_number ) {
36+
37+ if ( issue . number !== solutions [ getDay ( ) ] . issue_number ) {
3438 ctx . body = success ( "只处理当天的打卡信息" ) ;
3539 return ;
3640 }
3741 if ( action === "created" && comment . body . length > 20 ) {
38- ctx . body = success ( "收到!" ) ;
42+ mySolutions [ comment . user . login ] [ getDay ( ) - 1 ] = {
43+ // title: problem.title,
44+ url : comment . html_url ,
45+ body : comment . body ,
46+ } ;
47+
48+ fs . writeFileSync (
49+ path . resolve ( __dirname , "../static/my/solutions.json" ) ,
50+ JSON . stringify ( mySolutions )
51+ ) ;
52+
53+ process . exec (
54+ "sh " + path . resolve ( __dirname , "../scripts/commit.sh" ) ,
55+ console . log
56+ ) ;
3957 }
58+
59+ ctx . body = success ( mySolutions [ comment . user . login ] ) ;
4060} ) ;
4161
4262module . exports = router ;
0 commit comments